Merge pull request #12457 from abdellani/12452-log-who-deleted-products

This commit is contained in:
David Cook
2024-05-20 10:37:32 +10:00
committed by GitHub
3 changed files with 20 additions and 0 deletions

View File

@@ -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

View 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

View File

@@ -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