Merge pull request #8209 from tchak/fix-dossier-notifications
fix(dossier): send notifications on declarative dossiers
This commit is contained in:
commit
a4a308ec08
20 changed files with 36 additions and 57 deletions
|
@ -134,7 +134,7 @@ module Instructeurs
|
||||||
|
|
||||||
def repasser_en_construction
|
def repasser_en_construction
|
||||||
begin
|
begin
|
||||||
dossier.repasser_en_construction!(current_instructeur)
|
dossier.repasser_en_construction!(instructeur: current_instructeur)
|
||||||
flash.notice = 'Dossier repassé en construction.'
|
flash.notice = 'Dossier repassé en construction.'
|
||||||
rescue AASM::InvalidTransition => e
|
rescue AASM::InvalidTransition => e
|
||||||
flash.alert = aasm_error_message(e, target_state: :en_construction)
|
flash.alert = aasm_error_message(e, target_state: :en_construction)
|
||||||
|
|
|
@ -14,9 +14,9 @@ module Mutations
|
||||||
field :errors, [Types::ValidationErrorType], null: true
|
field :errors, [Types::ValidationErrorType], null: true
|
||||||
|
|
||||||
def resolve(dossier:, instructeur:, motivation: nil, justificatif: nil, disable_notification:)
|
def resolve(dossier:, instructeur:, motivation: nil, justificatif: nil, disable_notification:)
|
||||||
dossier.accepter!(instructeur: instructeur, motivation: motivation, justificatif: justificatif, disable_notification: disable_notification)
|
dossier.accepter!(instructeur:, motivation:, justificatif:, disable_notification:)
|
||||||
|
|
||||||
{ dossier: dossier }
|
{ dossier: }
|
||||||
end
|
end
|
||||||
|
|
||||||
def ready?(justificatif: nil, **args)
|
def ready?(justificatif: nil, **args)
|
||||||
|
|
|
@ -11,7 +11,7 @@ module Mutations
|
||||||
def resolve(dossier:, instructeur:)
|
def resolve(dossier:, instructeur:)
|
||||||
dossier.archiver!(instructeur)
|
dossier.archiver!(instructeur)
|
||||||
|
|
||||||
{ dossier: dossier }
|
{ dossier: }
|
||||||
end
|
end
|
||||||
|
|
||||||
def authorized?(dossier:, instructeur:)
|
def authorized?(dossier:, instructeur:)
|
||||||
|
|
|
@ -11,9 +11,9 @@ module Mutations
|
||||||
field :errors, [Types::ValidationErrorType], null: true
|
field :errors, [Types::ValidationErrorType], null: true
|
||||||
|
|
||||||
def resolve(dossier:, groupe_instructeur:)
|
def resolve(dossier:, groupe_instructeur:)
|
||||||
dossier.update!(groupe_instructeur: groupe_instructeur)
|
dossier.update!(groupe_instructeur:)
|
||||||
|
|
||||||
{ dossier: dossier }
|
{ dossier: }
|
||||||
end
|
end
|
||||||
|
|
||||||
def authorized?(dossier:, groupe_instructeur:)
|
def authorized?(dossier:, groupe_instructeur:)
|
||||||
|
|
|
@ -14,9 +14,9 @@ module Mutations
|
||||||
field :errors, [Types::ValidationErrorType], null: true
|
field :errors, [Types::ValidationErrorType], null: true
|
||||||
|
|
||||||
def resolve(dossier:, instructeur:, motivation:, justificatif: nil, disable_notification:)
|
def resolve(dossier:, instructeur:, motivation:, justificatif: nil, disable_notification:)
|
||||||
dossier.classer_sans_suite!(instructeur: instructeur, motivation: motivation, justificatif: justificatif, disable_notification: disable_notification)
|
dossier.classer_sans_suite!(instructeur:, motivation:, justificatif:, disable_notification:)
|
||||||
|
|
||||||
{ dossier: dossier }
|
{ dossier: }
|
||||||
end
|
end
|
||||||
|
|
||||||
def ready?(justificatif: nil, **args)
|
def ready?(justificatif: nil, **args)
|
||||||
|
|
|
@ -14,7 +14,7 @@ module Mutations
|
||||||
message = CommentaireService.create(instructeur, dossier, body: body, piece_jointe: attachment)
|
message = CommentaireService.create(instructeur, dossier, body: body, piece_jointe: attachment)
|
||||||
|
|
||||||
if message.errors.empty?
|
if message.errors.empty?
|
||||||
{ message: message }
|
{ message: }
|
||||||
else
|
else
|
||||||
{ errors: message.errors.full_messages }
|
{ errors: message.errors.full_messages }
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,7 +23,7 @@ module Mutations
|
||||||
if annotation.save
|
if annotation.save
|
||||||
dossier.log_modifier_annotation!(annotation, instructeur)
|
dossier.log_modifier_annotation!(annotation, instructeur)
|
||||||
|
|
||||||
{ annotation: annotation }
|
{ annotation: }
|
||||||
else
|
else
|
||||||
{ errors: annotation.errors.full_messages }
|
{ errors: annotation.errors.full_messages }
|
||||||
end
|
end
|
||||||
|
@ -44,9 +44,9 @@ module Mutations
|
||||||
|
|
||||||
Champ.joins(:type_de_champ).find_by(type_de_champ: {
|
Champ.joins(:type_de_champ).find_by(type_de_champ: {
|
||||||
type_champ: annotation_type_champ,
|
type_champ: annotation_type_champ,
|
||||||
stable_id: stable_id,
|
stable_id:,
|
||||||
private: true
|
private: true
|
||||||
}, private: true, row: row, dossier: dossier)
|
}, private: true, row:, dossier:)
|
||||||
end
|
end
|
||||||
|
|
||||||
def annotation_type_champ
|
def annotation_type_champ
|
||||||
|
|
|
@ -16,7 +16,7 @@ module Mutations
|
||||||
|
|
||||||
annotation.add_row(dossier.revision)
|
annotation.add_row(dossier.revision)
|
||||||
|
|
||||||
{ annotation: annotation, errors: nil }
|
{ annotation:, errors: nil }
|
||||||
end
|
end
|
||||||
|
|
||||||
def authorized?(dossier:, instructeur:, **args)
|
def authorized?(dossier:, instructeur:, **args)
|
||||||
|
|
|
@ -5,12 +5,7 @@ module Mutations
|
||||||
argument :value, Boolean, required: true
|
argument :value, Boolean, required: true
|
||||||
|
|
||||||
def resolve(dossier:, annotation_id:, instructeur:, value:)
|
def resolve(dossier:, annotation_id:, instructeur:, value:)
|
||||||
resolve_with_type(
|
resolve_with_type(dossier:, annotation_id:, instructeur:, value:) do |type_champ, value|
|
||||||
dossier: dossier,
|
|
||||||
annotation_id: annotation_id,
|
|
||||||
instructeur: instructeur,
|
|
||||||
value: value
|
|
||||||
) do |type_champ, value|
|
|
||||||
if type_champ == TypeDeChamp.type_champs.fetch(:yes_no)
|
if type_champ == TypeDeChamp.type_champs.fetch(:yes_no)
|
||||||
value ? 'true' : 'false'
|
value ? 'true' : 'false'
|
||||||
else
|
else
|
||||||
|
|
|
@ -5,12 +5,7 @@ module Mutations
|
||||||
argument :value, GraphQL::Types::ISO8601Date, required: true
|
argument :value, GraphQL::Types::ISO8601Date, required: true
|
||||||
|
|
||||||
def resolve(dossier:, annotation_id:, instructeur:, value:)
|
def resolve(dossier:, annotation_id:, instructeur:, value:)
|
||||||
resolve_with_type(
|
resolve_with_type(dossier:, annotation_id:, instructeur:, value:)
|
||||||
dossier: dossier,
|
|
||||||
annotation_id: annotation_id,
|
|
||||||
instructeur: instructeur,
|
|
||||||
value: value
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -5,12 +5,7 @@ module Mutations
|
||||||
argument :value, GraphQL::Types::ISO8601DateTime, required: true
|
argument :value, GraphQL::Types::ISO8601DateTime, required: true
|
||||||
|
|
||||||
def resolve(dossier:, annotation_id:, instructeur:, value:)
|
def resolve(dossier:, annotation_id:, instructeur:, value:)
|
||||||
resolve_with_type(
|
resolve_with_type(dossier:, annotation_id:, instructeur:, value:)
|
||||||
dossier: dossier,
|
|
||||||
annotation_id: annotation_id,
|
|
||||||
instructeur: instructeur,
|
|
||||||
value: value
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -5,12 +5,7 @@ module Mutations
|
||||||
argument :value, Int, required: true
|
argument :value, Int, required: true
|
||||||
|
|
||||||
def resolve(dossier:, annotation_id:, instructeur:, value:)
|
def resolve(dossier:, annotation_id:, instructeur:, value:)
|
||||||
resolve_with_type(
|
resolve_with_type(dossier:, annotation_id:, instructeur:, value:)
|
||||||
dossier: dossier,
|
|
||||||
annotation_id: annotation_id,
|
|
||||||
instructeur: instructeur,
|
|
||||||
value: value
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -5,12 +5,7 @@ module Mutations
|
||||||
argument :value, String, required: true
|
argument :value, String, required: true
|
||||||
|
|
||||||
def resolve(dossier:, annotation_id:, instructeur:, value:)
|
def resolve(dossier:, annotation_id:, instructeur:, value:)
|
||||||
resolve_with_type(
|
resolve_with_type(dossier:, annotation_id:, instructeur:, value:)
|
||||||
dossier: dossier,
|
|
||||||
annotation_id: annotation_id,
|
|
||||||
instructeur: instructeur,
|
|
||||||
value: value
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -12,9 +12,9 @@ module Mutations
|
||||||
field :errors, [Types::ValidationErrorType], null: true
|
field :errors, [Types::ValidationErrorType], null: true
|
||||||
|
|
||||||
def resolve(dossier:, instructeur:, disable_notification:)
|
def resolve(dossier:, instructeur:, disable_notification:)
|
||||||
dossier.passer_en_instruction!(instructeur: instructeur, disable_notification: disable_notification)
|
dossier.passer_en_instruction!(instructeur:, disable_notification:)
|
||||||
|
|
||||||
{ dossier: dossier }
|
{ dossier: }
|
||||||
end
|
end
|
||||||
|
|
||||||
def authorized?(dossier:, instructeur:, **args)
|
def authorized?(dossier:, instructeur:, **args)
|
||||||
|
|
|
@ -14,9 +14,9 @@ module Mutations
|
||||||
field :errors, [Types::ValidationErrorType], null: true
|
field :errors, [Types::ValidationErrorType], null: true
|
||||||
|
|
||||||
def resolve(dossier:, instructeur:, motivation:, justificatif: nil, disable_notification:)
|
def resolve(dossier:, instructeur:, motivation:, justificatif: nil, disable_notification:)
|
||||||
dossier.refuser!(instructeur: instructeur, motivation: motivation, justificatif: justificatif, disable_notification: disable_notification)
|
dossier.refuser!(instructeur:, motivation:, justificatif:, disable_notification:)
|
||||||
|
|
||||||
{ dossier: dossier }
|
{ dossier: }
|
||||||
end
|
end
|
||||||
|
|
||||||
def ready?(justificatif: nil, **args)
|
def ready?(justificatif: nil, **args)
|
||||||
|
|
|
@ -12,9 +12,9 @@ module Mutations
|
||||||
field :errors, [Types::ValidationErrorType], null: true
|
field :errors, [Types::ValidationErrorType], null: true
|
||||||
|
|
||||||
def resolve(dossier:, instructeur:, disable_notification:)
|
def resolve(dossier:, instructeur:, disable_notification:)
|
||||||
dossier.repasser_en_construction!(instructeur)
|
dossier.repasser_en_construction!(instructeur:, disable_notification:)
|
||||||
|
|
||||||
{ dossier: dossier }
|
{ dossier: }
|
||||||
end
|
end
|
||||||
|
|
||||||
def authorized?(dossier:, instructeur:, **args)
|
def authorized?(dossier:, instructeur:, **args)
|
||||||
|
|
|
@ -12,9 +12,9 @@ module Mutations
|
||||||
field :errors, [Types::ValidationErrorType], null: true
|
field :errors, [Types::ValidationErrorType], null: true
|
||||||
|
|
||||||
def resolve(dossier:, instructeur:, disable_notification:)
|
def resolve(dossier:, instructeur:, disable_notification:)
|
||||||
dossier.repasser_en_instruction!(instructeur: instructeur, disable_notification: disable_notification)
|
dossier.repasser_en_instruction!(instructeur:, disable_notification:)
|
||||||
|
|
||||||
{ dossier: dossier }
|
{ dossier: }
|
||||||
end
|
end
|
||||||
|
|
||||||
def authorized?(dossier:, instructeur:, **args)
|
def authorized?(dossier:, instructeur:, **args)
|
||||||
|
|
|
@ -10,8 +10,8 @@ module Mutations
|
||||||
field :errors, [Types::ValidationErrorType], null: true
|
field :errors, [Types::ValidationErrorType], null: true
|
||||||
|
|
||||||
def resolve(groupe_instructeur:, label: nil, closed: nil)
|
def resolve(groupe_instructeur:, label: nil, closed: nil)
|
||||||
if groupe_instructeur.update({ label: label, closed: closed }.compact)
|
if groupe_instructeur.update({ label:, closed: }.compact)
|
||||||
{ groupe_instructeur: groupe_instructeur }
|
{ groupe_instructeur: }
|
||||||
else
|
else
|
||||||
{ errors: groupe_instructeur.errors.full_messages }
|
{ errors: groupe_instructeur.errors.full_messages }
|
||||||
end
|
end
|
||||||
|
|
|
@ -844,7 +844,7 @@ class Dossier < ApplicationRecord
|
||||||
.processed_at
|
.processed_at
|
||||||
save!
|
save!
|
||||||
|
|
||||||
if !procedure.declarative_accepte? && !disable_notification
|
if !disable_notification
|
||||||
NotificationMailer.send_en_instruction_notification(self).deliver_later
|
NotificationMailer.send_en_instruction_notification(self).deliver_later
|
||||||
end
|
end
|
||||||
log_dossier_operation(instructeur, :passer_en_instruction)
|
log_dossier_operation(instructeur, :passer_en_instruction)
|
||||||
|
@ -857,10 +857,14 @@ class Dossier < ApplicationRecord
|
||||||
.passer_en_instruction
|
.passer_en_instruction
|
||||||
.processed_at
|
.processed_at
|
||||||
save!
|
save!
|
||||||
|
|
||||||
|
NotificationMailer.send_en_instruction_notification(self).deliver_later
|
||||||
log_automatic_dossier_operation(:passer_en_instruction)
|
log_automatic_dossier_operation(:passer_en_instruction)
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_repasser_en_construction(instructeur)
|
def after_repasser_en_construction(h)
|
||||||
|
instructeur = h[:instructeur]
|
||||||
|
|
||||||
create_missing_traitemets
|
create_missing_traitemets
|
||||||
|
|
||||||
self.en_construction_close_to_expiration_notice_sent_at = nil
|
self.en_construction_close_to_expiration_notice_sent_at = nil
|
||||||
|
|
|
@ -493,7 +493,7 @@ describe Dossier do
|
||||||
it 'should keep first en_construction_at date' do
|
it 'should keep first en_construction_at date' do
|
||||||
Timecop.return
|
Timecop.return
|
||||||
dossier.passer_en_instruction!(instructeur: instructeur)
|
dossier.passer_en_instruction!(instructeur: instructeur)
|
||||||
dossier.repasser_en_construction!(instructeur)
|
dossier.repasser_en_construction!(instructeur: instructeur)
|
||||||
|
|
||||||
expect(dossier.traitements.size).to eq(3)
|
expect(dossier.traitements.size).to eq(3)
|
||||||
expect(dossier.traitements.first.processed_at).to eq(beginning_of_day)
|
expect(dossier.traitements.first.processed_at).to eq(beginning_of_day)
|
||||||
|
@ -519,7 +519,7 @@ describe Dossier do
|
||||||
|
|
||||||
it 'should keep first en_instruction_at date if dossier is set to en_construction again' do
|
it 'should keep first en_instruction_at date if dossier is set to en_construction again' do
|
||||||
Timecop.return
|
Timecop.return
|
||||||
dossier.repasser_en_construction!(instructeur)
|
dossier.repasser_en_construction!(instructeur: instructeur)
|
||||||
dossier.passer_en_instruction!(instructeur: instructeur)
|
dossier.passer_en_instruction!(instructeur: instructeur)
|
||||||
|
|
||||||
expect(dossier.traitements.size).to eq(4)
|
expect(dossier.traitements.size).to eq(4)
|
||||||
|
|
Loading…
Add table
Reference in a new issue