diff --git a/app/decorators/authorization_request_event_decorator.rb b/app/decorators/authorization_request_event_decorator.rb
index eff5f197a..025e5be0d 100644
--- a/app/decorators/authorization_request_event_decorator.rb
+++ b/app/decorators/authorization_request_event_decorator.rb
@@ -36,6 +36,12 @@ def text
end
alias comment text # see WebhookEventSerializer
+ def copied_from_authorization_request_id
+ return unless name == 'copy'
+
+ entity.copied_from_request.id
+ end
+
private
def humanized_changelog
diff --git a/app/models/authorization_request_event.rb b/app/models/authorization_request_event.rb
index 1dd0eab57..a0b149808 100644
--- a/app/models/authorization_request_event.rb
+++ b/app/models/authorization_request_event.rb
@@ -10,6 +10,8 @@ class AuthorizationRequestEvent < ApplicationRecord
submit
update
+ copy
+
applicant_message
instructor_message
diff --git a/app/views/instruction/authorization_request_events/_authorization_request_event.html.erb b/app/views/instruction/authorization_request_events/_authorization_request_event.html.erb
index dd5446a11..d553d5727 100644
--- a/app/views/instruction/authorization_request_events/_authorization_request_event.html.erb
+++ b/app/views/instruction/authorization_request_events/_authorization_request_event.html.erb
@@ -16,6 +16,7 @@
**{
user_full_name: authorization_request_event.user_full_name,
text: simple_format(authorization_request_event.text),
+ copied_from_authorization_request_id: authorization_request_event.copied_from_authorization_request_id,
}.compact
).html_safe
%>
diff --git a/config/locales/fr.yml b/config/locales/fr.yml
index cca87b625..095d0a2a0 100644
--- a/config/locales/fr.yml
+++ b/config/locales/fr.yml
@@ -467,6 +467,10 @@ fr:
icon: close-circle-line
color: error
+ copy:
+ text: |
+ %{user_full_name} a copié la demande %{copied_from_authorization_request_id}
+
reopen:
text: "%{user_full_name} a réouvert l'habilitation"
diff --git a/spec/factories/authorization_request_events.rb b/spec/factories/authorization_request_events.rb
index a018fde1b..fd40d09e2 100644
--- a/spec/factories/authorization_request_events.rb
+++ b/spec/factories/authorization_request_events.rb
@@ -2,7 +2,7 @@
factory :authorization_request_event do
name { 'create' }
user
- entity factory: %i[authorization_request]
+ entity factory: %i[authorization_request api_entreprise]
transient do
authorization_request { nil }
@@ -104,6 +104,22 @@
end
end
+ trait :copy do
+ entity factory: %i[authorization_request api_entreprise]
+ entity_is_authorization_request
+
+ name { 'copy' }
+
+ after(:build) do |authorization_request_event|
+ authorization_request = authorization_request_event.entity
+ authorization_request_trait = authorization_request.type.split('::').last.underscore.to_sym
+
+ copied_from_authorization_request = create(:authorization_request, :validated, authorization_request_trait, applicant: authorization_request.applicant)
+
+ authorization_request_event.entity.copied_from_request = copied_from_authorization_request
+ end
+ end
+
trait :applicant_message do
name { 'applicant_message' }
diff --git a/spec/features/instruction/events_spec.rb b/spec/features/instruction/events_spec.rb
index b9c893616..4f366d00b 100644
--- a/spec/features/instruction/events_spec.rb
+++ b/spec/features/instruction/events_spec.rb
@@ -1,6 +1,6 @@
RSpec.describe 'Instruction: habilitation events' do
let(:user) { create(:user, :instructor) }
- let(:authorization_request) { create(:authorization_request, applicant: user) }
+ let(:authorization_request) { create(:authorization_request, :api_entreprise, applicant: user) }
before do
sign_in(user)
diff --git a/spec/queries/authorization_request_events_query_spec.rb b/spec/queries/authorization_request_events_query_spec.rb
index d26ddeb1f..d26d1297a 100644
--- a/spec/queries/authorization_request_events_query_spec.rb
+++ b/spec/queries/authorization_request_events_query_spec.rb
@@ -2,7 +2,7 @@
describe '#perform' do
subject(:events) { described_class.new(authorization_request).perform }
- let(:authorization_request) { create(:authorization_request).reload }
+ let(:authorization_request) { create(:authorization_request, :api_entreprise).reload }
before do
AuthorizationRequestEvent::NAMES.each_with_index do |event_name, index|