mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #12457 from abdellani/12452-log-who-deleted-products
This commit is contained in:
@@ -42,6 +42,7 @@ module Api
|
||||
authorize! :delete, Spree::Product
|
||||
@product = product_finder.find_product
|
||||
authorize! :delete, @product
|
||||
@product.destroyed_by = current_api_user
|
||||
@product.destroy
|
||||
render json: @product, serializer: Api::Admin::ProductSerializer, status: :no_content
|
||||
end
|
||||
|
||||
18
app/models/concerns/log_destroy_performer.rb
Normal file
18
app/models/concerns/log_destroy_performer.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'active_support/concern'
|
||||
|
||||
module LogDestroyPerformer
|
||||
extend ActiveSupport::Concern
|
||||
included do
|
||||
attr_accessor :destroyed_by
|
||||
|
||||
after_destroy :log_who_destroyed
|
||||
|
||||
def log_who_destroyed
|
||||
return if destroyed_by.nil?
|
||||
|
||||
Rails.logger.info "#{self.class} #{id} deleted by #{destroyed_by.id}"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -23,6 +23,7 @@ require 'open_food_network/property_merge'
|
||||
module Spree
|
||||
class Product < ApplicationRecord
|
||||
include ProductStock
|
||||
include LogDestroyPerformer
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
|
||||
Reference in New Issue
Block a user