Merge pull request #9230 from colinux/log-destroyed-dossiers
Tech: log technique de la destruction de dossiers
This commit is contained in:
commit
d69636c411
3 changed files with 32 additions and 0 deletions
|
@ -25,6 +25,7 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
before_action do
|
||||
Current.request_id = request.uuid
|
||||
Current.user = current_user
|
||||
end
|
||||
|
||||
def staging_authenticate
|
||||
|
|
|
@ -125,6 +125,8 @@ class Dossier < ApplicationRecord
|
|||
belongs_to :transfer, class_name: 'DossierTransfer', foreign_key: 'dossier_transfer_id', optional: true, inverse_of: :dossiers
|
||||
has_many :transfer_logs, class_name: 'DossierTransferLog', dependent: :destroy
|
||||
|
||||
after_destroy_commit :log_destroy
|
||||
|
||||
accepts_nested_attributes_for :champs
|
||||
accepts_nested_attributes_for :champs_public
|
||||
accepts_nested_attributes_for :champs_private
|
||||
|
@ -1395,4 +1397,22 @@ class Dossier < ApplicationRecord
|
|||
|
||||
avis.each { |a| ExpertMailer.send_dossier_decision_v2(a).deliver_later }
|
||||
end
|
||||
|
||||
def log_destroy
|
||||
app_traces = caller.reject { _1.match?(%r{/ruby/.+/gems/}) }.map { _1.sub(Rails.root.to_s, "") }
|
||||
|
||||
payload = {
|
||||
message: "Dossier destroyed",
|
||||
dossier_id: id,
|
||||
procedure_id: procedure.id,
|
||||
request_id: Current.request_id,
|
||||
user_id: Current.user&.id,
|
||||
controller: app_traces.find { _1.match?(%r{/controllers/|/jobs/}) },
|
||||
caller: app_traces.second # first is the callback definition
|
||||
}
|
||||
|
||||
logger = Lograge.logger || Rails.logger
|
||||
|
||||
logger.info payload.to_json
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1934,6 +1934,17 @@ describe Dossier, type: :model do
|
|||
expect { dossier.procedure.reset! }.not_to raise_error
|
||||
expect { dossier.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
it "call logger with context" do
|
||||
json_message = nil
|
||||
|
||||
allow(Rails.logger).to receive(:info) { json_message ||= _1 }
|
||||
dossier.destroy
|
||||
|
||||
expect(JSON.parse(json_message)).to a_hash_including(
|
||||
{ message: "Dossier destroyed", dossier_id: dossier.id, procedure_id: procedure.id }.stringify_keys
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#spreadsheet_columns" do
|
||||
|
|
Loading…
Reference in a new issue