Merge pull request #5548 from tchak/graphql-dossier-archive
[GraphQL] Add archiver mutation
This commit is contained in:
commit
f30a8b154e
7 changed files with 120 additions and 3 deletions
|
@ -97,12 +97,12 @@ module Instructeurs
|
|||
end
|
||||
|
||||
def archive
|
||||
dossier.update(archived: true)
|
||||
dossier.archiver!(current_instructeur)
|
||||
redirect_back(fallback_location: instructeur_procedures_url)
|
||||
end
|
||||
|
||||
def unarchive
|
||||
dossier.update(archived: false)
|
||||
dossier.desarchiver!(current_instructeur)
|
||||
redirect_back(fallback_location: instructeur_procedures_url)
|
||||
end
|
||||
|
||||
|
|
25
app/graphql/mutations/dossier_archiver.rb
Normal file
25
app/graphql/mutations/dossier_archiver.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Mutations
|
||||
class DossierArchiver < Mutations::BaseMutation
|
||||
description "Archiver 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:)
|
||||
if dossier.termine?
|
||||
dossier.archiver!(instructeur)
|
||||
|
||||
{ dossier: dossier }
|
||||
else
|
||||
{ errors: ["Un dossier ne peut être archivé qu’une fois le traitement terminé"] }
|
||||
end
|
||||
end
|
||||
|
||||
def authorized?(dossier:, instructeur:)
|
||||
instructeur.is_a?(Instructeur) && instructeur.dossiers.exists?(id: dossier.id)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -457,6 +457,38 @@ type DossierAccepterPayload {
|
|||
errors: [ValidationError!]
|
||||
}
|
||||
|
||||
"""
|
||||
Autogenerated input type of DossierArchiver
|
||||
"""
|
||||
input DossierArchiverInput {
|
||||
"""
|
||||
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 DossierArchiver
|
||||
"""
|
||||
type DossierArchiverPayload {
|
||||
"""
|
||||
A unique identifier for the client performing the mutation.
|
||||
"""
|
||||
clientMutationId: String
|
||||
dossier: Dossier
|
||||
errors: [ValidationError!]
|
||||
}
|
||||
|
||||
"""
|
||||
Autogenerated input type of DossierChangerGroupeInstructeur
|
||||
"""
|
||||
|
@ -925,6 +957,11 @@ type Mutation {
|
|||
"""
|
||||
dossierAccepter(input: DossierAccepterInput!): DossierAccepterPayload
|
||||
|
||||
"""
|
||||
Archiver le dossier.
|
||||
"""
|
||||
dossierArchiver(input: DossierArchiverInput!): DossierArchiverPayload
|
||||
|
||||
"""
|
||||
Changer le grope instructeur du dossier.
|
||||
"""
|
||||
|
|
|
@ -7,6 +7,7 @@ module Types
|
|||
field :dossier_classer_sans_suite, mutation: Mutations::DossierClasserSansSuite
|
||||
field :dossier_refuser, mutation: Mutations::DossierRefuser
|
||||
field :dossier_accepter, mutation: Mutations::DossierAccepter
|
||||
field :dossier_archiver, mutation: Mutations::DossierArchiver
|
||||
field :dossier_changer_groupe_instructeur, mutation: Mutations::DossierChangerGroupeInstructeur
|
||||
end
|
||||
end
|
||||
|
|
|
@ -416,6 +416,16 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def archiver!(author)
|
||||
update!(archived: true)
|
||||
log_dossier_operation(author, :archiver)
|
||||
end
|
||||
|
||||
def desarchiver!(author)
|
||||
update!(archived: false)
|
||||
log_dossier_operation(author, :desarchiver)
|
||||
end
|
||||
|
||||
def text_summary
|
||||
if brouillon?
|
||||
parts = [
|
||||
|
|
|
@ -26,7 +26,9 @@ class DossierOperationLog < ApplicationRecord
|
|||
supprimer: 'supprimer',
|
||||
restaurer: 'restaurer',
|
||||
modifier_annotation: 'modifier_annotation',
|
||||
demander_un_avis: 'demander_un_avis'
|
||||
demander_un_avis: 'demander_un_avis',
|
||||
archiver: 'archiver',
|
||||
desarchiver: 'desarchiver'
|
||||
}
|
||||
|
||||
has_one_attached :serialized
|
||||
|
|
|
@ -885,6 +885,48 @@ describe API::V2::GraphqlController do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'dossierArchiver' do
|
||||
let(:query) do
|
||||
"mutation {
|
||||
dossierArchiver(input: {
|
||||
dossierId: \"#{dossier.to_typed_id}\",
|
||||
instructeurId: \"#{instructeur.to_typed_id}\"
|
||||
}) {
|
||||
dossier {
|
||||
archived
|
||||
}
|
||||
errors {
|
||||
message
|
||||
}
|
||||
}
|
||||
}"
|
||||
end
|
||||
|
||||
it "validation error" do
|
||||
expect(gql_errors).to eq(nil)
|
||||
|
||||
expect(gql_data).to eq(dossierArchiver: {
|
||||
dossier: nil,
|
||||
errors: [{ message: "Un dossier ne peut être archivé qu’une fois le traitement terminé" }]
|
||||
})
|
||||
end
|
||||
|
||||
context "should archive dossier" do
|
||||
let(:dossier) { create(:dossier, :sans_suite, :with_individual, procedure: procedure) }
|
||||
|
||||
it "change made" do
|
||||
expect(gql_errors).to eq(nil)
|
||||
|
||||
expect(gql_data).to eq(dossierArchiver: {
|
||||
dossier: {
|
||||
archived: true
|
||||
},
|
||||
errors: nil
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue