Skip to content

Commit

Permalink
Add admin_update event to AuthorizationRequestEvent
Browse files Browse the repository at this point in the history
Because of the change of diff management (on v1 it was on each update,
v2 is on submit), changes from admin (without submit) is no longer
displayed nor imported.

We have to introduce a new event to store these diffs within changelog
model.
  • Loading branch information
skelz0r committed May 14, 2024
1 parent aaae8e5 commit aa58e0f
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/decorators/authorization_request_event_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def text
case name
when 'refuse', 'request_changes', 'revoke'
h.simple_format(entity.reason)
when 'submit'
when 'submit', 'admin_update'
humanized_changelog
when 'initial_submit_with_changed_prefilled'
humanized_changelog_without_blank_values
Expand Down
4 changes: 3 additions & 1 deletion app/models/authorization_request_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class AuthorizationRequestEvent < ApplicationRecord
applicant_message
instructor_message

admin_update

system_reminder
system_archive
].freeze
Expand All @@ -34,7 +36,7 @@ def entity_type_is_authorized
return if name == 'refuse' && entity_type == 'DenialOfAuthorization'
return if name == 'revoke' && entity_type == 'RevocationOfAuthorization'
return if name == 'request_changes' && entity_type == 'InstructorModificationRequest'
return if name == 'submit' && entity_type == 'AuthorizationRequestChangelog'
return if %w[submit admin_update].include?(name) && entity_type == 'AuthorizationRequestChangelog'
return if %w[approve reopen].include?(name) && entity_type == 'Authorization'
return if %w[applicant_message instructor_message].include?(name) && entity_type == 'Message'
return if %w[approve refuse request_changes revoke].exclude?(name) && entity_type == 'AuthorizationRequest'
Expand Down
9 changes: 9 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,15 @@ fr:
%{text}
</blockquote>
admin_update:
text: |
L'administrateur <strong>%{user_full_name}</strong> a mis à jour la demande.
<br />
La liste des changements est :
%{text}
system_reminder:
text: Une relance a été envoyé au demandeur

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class MoreAndMoreConstraintsToAuthorizationRequestEvents < ActiveRecord::Migration[7.1]
def up
execute <<-SQL
ALTER TABLE authorization_request_events
DROP CONSTRAINT entity_type_validation
SQL

execute <<-SQL
ALTER TABLE authorization_request_events
ADD CONSTRAINT entity_type_validation
CHECK (
(name = 'refuse' AND entity_type = 'DenialOfAuthorization') OR
(name = 'request_changes' AND entity_type = 'InstructorModificationRequest') OR
(name = 'approve' AND entity_type = 'Authorization') OR
(name = 'reopen' AND entity_type = 'Authorization') OR
(name = 'submit' AND entity_type = 'AuthorizationRequestChangelog') OR
(name = 'admin_update' AND entity_type = 'AuthorizationRequestChangelog') OR
(name = 'applicant_message' AND entity_type = 'Message') OR
(name = 'instructor_message' AND entity_type = 'Message') OR
(name = 'revoke' AND entity_type = 'RevocationOfAuthorization') OR
(entity_type = 'AuthorizationRequest')
)
SQL
end

def down
execute <<-SQL
ALTER TABLE authorization_request_events
DROP CONSTRAINT entity_type_validation
SQL

execute <<-SQL
ALTER TABLE authorization_request_events
ADD CONSTRAINT entity_type_validation
CHECK (
(name = 'refuse' AND entity_type = 'DenialOfAuthorization') OR
(name = 'request_changes' AND entity_type = 'InstructorModificationRequest') OR
(name = 'approve' AND entity_type = 'Authorization') OR
(name = 'reopen' AND entity_type = 'Authorization') OR
(name = 'submit' AND entity_type = 'AuthorizationRequestChangelog') OR
(name = 'applicant_message' AND entity_type = 'Message') OR
(name = 'instructor_message' AND entity_type = 'Message') OR
(name = 'revoke' AND entity_type = 'RevocationOfAuthorization') OR
(entity_type = 'AuthorizationRequest')
)
SQL
end
end
4 changes: 2 additions & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions spec/factories/authorization_request_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@
end
end

trait :admin_update do
name { 'admin_update' }

entity factory: %i[authorization_request_changelog]

after(:build) do |authorization_request_event, evaluator|
authorization_request_event.entity = build(:authorization_request_changelog, authorization_request: evaluator.authorization_request) if evaluator.authorization_request.present?

authorization_request_event.entity.diff.delete 'scopes'
end
end

trait :system_reminder do
name { 'system_reminder' }

Expand Down
6 changes: 6 additions & 0 deletions spec/features/instruction/events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
AuthorizationRequestEvent::NAMES.each_with_index do |event_name, index|
create(:authorization_request_event, event_name, authorization_request:, created_at: index.days.ago)
end

Bullet.enable = false
end

after do
Bullet.enable = true
end

it 'works for all events' do
Expand Down

0 comments on commit aa58e0f

Please sign in to comment.