2019-11-13 20:01:58 +01:00
|
|
|
|
module Mutations
|
|
|
|
|
class DossierRefuser < Mutations::BaseMutation
|
|
|
|
|
include DossierHelper
|
|
|
|
|
|
|
|
|
|
description "Refuser le dossier."
|
|
|
|
|
|
|
|
|
|
argument :dossier_id, ID, "Dossier ID", required: true, loads: Types::DossierType
|
|
|
|
|
argument :instructeur_id, ID, "Instructeur qui prend la décision sur le dossier.", required: true, loads: Types::ProfileType
|
|
|
|
|
argument :motivation, String, required: true
|
|
|
|
|
argument :justificatif, ID, required: false
|
2021-09-01 15:11:11 +02:00
|
|
|
|
argument :disable_notification, Boolean, "Désactiver l’envoi de l’email de notification après l’opération", required: false, default_value: false
|
2019-11-13 20:01:58 +01:00
|
|
|
|
|
|
|
|
|
field :dossier, Types::DossierType, null: true
|
|
|
|
|
field :errors, [Types::ValidationErrorType], null: true
|
|
|
|
|
|
2021-09-01 15:11:11 +02:00
|
|
|
|
def resolve(dossier:, instructeur:, motivation:, justificatif: nil, disable_notification:)
|
2022-12-07 13:21:55 +01:00
|
|
|
|
dossier.refuser!(instructeur:, motivation:, justificatif:, disable_notification:)
|
2019-11-13 20:01:58 +01:00
|
|
|
|
|
2022-12-07 13:21:55 +01:00
|
|
|
|
{ dossier: }
|
2020-12-10 16:23:24 +01:00
|
|
|
|
end
|
|
|
|
|
|
2023-02-13 14:25:17 +01:00
|
|
|
|
def authorized_before_load?(justificatif: nil, **args)
|
2020-12-10 16:23:24 +01:00
|
|
|
|
if justificatif.present?
|
|
|
|
|
validate_blob(justificatif)
|
2019-11-13 20:01:58 +01:00
|
|
|
|
else
|
2020-12-10 16:23:24 +01:00
|
|
|
|
true
|
2019-11-13 20:01:58 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2020-12-10 16:23:24 +01:00
|
|
|
|
def authorized?(dossier:, instructeur:, **args)
|
|
|
|
|
if !dossier.en_instruction?
|
|
|
|
|
return false, { errors: ["Le dossier est déjà #{dossier_display_state(dossier, lower: true)}"] }
|
|
|
|
|
end
|
|
|
|
|
dossier_authorized_for?(dossier, instructeur)
|
2019-11-13 20:01:58 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|