Merge pull request #10670 from tchak/feat-graphql-desarchiver
feat(graphql): add desarchiver mutation
This commit is contained in:
commit
45d5e79e55
5 changed files with 109 additions and 0 deletions
|
@ -728,6 +728,18 @@ class API::V2::StoredQuery
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mutation dossierDesarchiver($input: DossierDesarchiverInput!) {
|
||||||
|
dossierDesarchiver(input: $input) {
|
||||||
|
dossier {
|
||||||
|
id
|
||||||
|
archived
|
||||||
|
}
|
||||||
|
errors {
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mutation dossierPasserEnInstruction($input: DossierPasserEnInstructionInput!) {
|
mutation dossierPasserEnInstruction($input: DossierPasserEnInstructionInput!) {
|
||||||
dossierPasserEnInstruction(input: $input) {
|
dossierPasserEnInstruction(input: $input) {
|
||||||
dossier {
|
dossier {
|
||||||
|
|
25
app/graphql/mutations/dossier_desarchiver.rb
Normal file
25
app/graphql/mutations/dossier_desarchiver.rb
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
module Mutations
|
||||||
|
class DossierDesarchiver < Mutations::BaseMutation
|
||||||
|
description "Désarchiver 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
|
||||||
|
|
||||||
|
field :dossier, Types::DossierType, null: true
|
||||||
|
field :errors, [Types::ValidationErrorType], null: true
|
||||||
|
|
||||||
|
def resolve(dossier:, instructeur:)
|
||||||
|
dossier.desarchiver!
|
||||||
|
|
||||||
|
{ dossier: }
|
||||||
|
end
|
||||||
|
|
||||||
|
def authorized?(dossier:, instructeur:)
|
||||||
|
if !dossier.archived?
|
||||||
|
return false, { errors: ["Un dossier non archivé ne peut pas être désarchivé"] }
|
||||||
|
end
|
||||||
|
|
||||||
|
dossier_authorized_for?(dossier, instructeur)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1682,6 +1682,38 @@ enum DossierDeclarativeState {
|
||||||
en_instruction
|
en_instruction
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"""
|
||||||
|
Autogenerated input type of DossierDesarchiver
|
||||||
|
"""
|
||||||
|
input DossierDesarchiverInput {
|
||||||
|
"""
|
||||||
|
A unique identifier for the client performing the mutation.
|
||||||
|
"""
|
||||||
|
clientMutationId: String
|
||||||
|
|
||||||
|
"""
|
||||||
|
Dossier ID
|
||||||
|
"""
|
||||||
|
dossierId: ID!
|
||||||
|
|
||||||
|
"""
|
||||||
|
Instructeur qui prend la décision sur le dossier.
|
||||||
|
"""
|
||||||
|
instructeurId: ID!
|
||||||
|
}
|
||||||
|
|
||||||
|
"""
|
||||||
|
Autogenerated return type of DossierDesarchiver.
|
||||||
|
"""
|
||||||
|
type DossierDesarchiverPayload {
|
||||||
|
"""
|
||||||
|
A unique identifier for the client performing the mutation.
|
||||||
|
"""
|
||||||
|
clientMutationId: String
|
||||||
|
dossier: Dossier
|
||||||
|
errors: [ValidationError!]
|
||||||
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
An edge in a connection.
|
An edge in a connection.
|
||||||
"""
|
"""
|
||||||
|
@ -3271,6 +3303,16 @@ type Mutation {
|
||||||
input: DossierClasserSansSuiteInput!
|
input: DossierClasserSansSuiteInput!
|
||||||
): DossierClasserSansSuitePayload
|
): DossierClasserSansSuitePayload
|
||||||
|
|
||||||
|
"""
|
||||||
|
Désarchiver le dossier.
|
||||||
|
"""
|
||||||
|
dossierDesarchiver(
|
||||||
|
"""
|
||||||
|
Parameters for DossierDesarchiver
|
||||||
|
"""
|
||||||
|
input: DossierDesarchiverInput!
|
||||||
|
): DossierDesarchiverPayload
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Envoyer un message à l'usager du dossier.
|
Envoyer un message à l'usager du dossier.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -11,6 +11,7 @@ module Types
|
||||||
field :dossier_repasser_en_instruction, mutation: Mutations::DossierRepasserEnInstruction
|
field :dossier_repasser_en_instruction, mutation: Mutations::DossierRepasserEnInstruction
|
||||||
field :dossier_repasser_en_construction, mutation: Mutations::DossierRepasserEnConstruction
|
field :dossier_repasser_en_construction, mutation: Mutations::DossierRepasserEnConstruction
|
||||||
field :dossier_archiver, mutation: Mutations::DossierArchiver
|
field :dossier_archiver, mutation: Mutations::DossierArchiver
|
||||||
|
field :dossier_desarchiver, mutation: Mutations::DossierDesarchiver
|
||||||
field :dossier_changer_groupe_instructeur, mutation: Mutations::DossierChangerGroupeInstructeur
|
field :dossier_changer_groupe_instructeur, mutation: Mutations::DossierChangerGroupeInstructeur
|
||||||
|
|
||||||
field :dossier_modifier_annotation_text, mutation: Mutations::DossierModifierAnnotationText
|
field :dossier_modifier_annotation_text, mutation: Mutations::DossierModifierAnnotationText
|
||||||
|
|
|
@ -889,6 +889,35 @@ describe API::V2::GraphqlController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'dossierDesarchiver' do
|
||||||
|
let(:dossier) { create(:dossier, :refuse, :with_individual, :archived, procedure:) }
|
||||||
|
let(:variables) { { input: { dossierId: dossier.to_typed_id, instructeurId: instructeur.to_typed_id } } }
|
||||||
|
let(:operation_name) { 'dossierDesarchiver' }
|
||||||
|
|
||||||
|
it {
|
||||||
|
expect(gql_errors).to be_nil
|
||||||
|
expect(gql_data[:dossierDesarchiver][:errors]).to be_nil
|
||||||
|
expect(gql_data[:dossierDesarchiver][:dossier][:id]).to eq(dossier.to_typed_id)
|
||||||
|
expect(gql_data[:dossierDesarchiver][:dossier][:archived]).to be_falsey
|
||||||
|
}
|
||||||
|
|
||||||
|
context 'read only token' do
|
||||||
|
before { api_token.update(write_access: false) }
|
||||||
|
|
||||||
|
it {
|
||||||
|
expect(gql_data[:dossierDesarchiver][:errors].first[:message]).to eq('Le jeton utilisé est configuré seulement en lecture')
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when not processed' do
|
||||||
|
let(:dossier) { create(:dossier, :refuse, :with_individual, procedure:) }
|
||||||
|
|
||||||
|
it {
|
||||||
|
expect(gql_data[:dossierDesarchiver][:errors].first[:message]).to eq('Un dossier non archivé ne peut pas être désarchivé')
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'dossierPasserEnInstruction' do
|
context 'dossierPasserEnInstruction' do
|
||||||
let(:dossier) { create(:dossier, :en_construction, :with_individual, procedure: procedure) }
|
let(:dossier) { create(:dossier, :en_construction, :with_individual, procedure: procedure) }
|
||||||
let(:variables) { { input: { dossierId: dossier.to_typed_id, instructeurId: instructeur.to_typed_id, disableNotification: } } }
|
let(:variables) { { input: { dossierId: dossier.to_typed_id, instructeurId: instructeur.to_typed_id, disableNotification: } } }
|
||||||
|
|
Loading…
Reference in a new issue