diff --git a/app/assets/images/icons/sign-out.svg b/app/assets/images/icons/sign-out.svg index 184162794..76706b80d 100644 --- a/app/assets/images/icons/sign-out.svg +++ b/app/assets/images/icons/sign-out.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/app/controllers/manager/procedures_controller.rb b/app/controllers/manager/procedures_controller.rb index d5bef5228..b3241429f 100644 --- a/app/controllers/manager/procedures_controller.rb +++ b/app/controllers/manager/procedures_controller.rb @@ -1,14 +1,12 @@ module Manager class ProceduresController < Manager::ApplicationController def whitelist - procedure = Procedure.find(params[:id]) procedure.whitelist! flash[:notice] = "Démarche whitelistée." redirect_to manager_procedure_path(procedure) end def draft - procedure = Procedure.find(params[:id]) if procedure.dossiers.empty? procedure.draft! flash[:notice] = "La démarche a bien été passée en brouillon." @@ -19,14 +17,12 @@ module Manager end def hide - procedure = Procedure.find(params[:id]) procedure.hide! flash[:notice] = "La démarche a bien été supprimée, en cas d'erreur contactez un développeur." redirect_to manager_procedures_path end def add_administrateur - procedure = Procedure.find(params[:id]) administrateur = Administrateur.find_by(email: params[:email]) if administrateur procedure.administrateurs << administrateur @@ -36,5 +32,28 @@ module Manager end redirect_to manager_procedure_path(procedure) end + + def change_piece_justificative_template + if type_de_champ.update(type_de_champ_params) + flash[:notice] = "Le modèle est mis à jour." + else + flash[:alert] = type_de_champ.errors.full_messages.join(', ') + end + redirect_to manager_procedure_path(procedure) + end + + private + + def procedure + Procedure.find(params[:id]) + end + + def type_de_champ + TypeDeChamp.find(params[:type_de_champ][:id]) + end + + def type_de_champ_params + params.require(:type_de_champ).permit(:piece_justificative_template) + end end end diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index 9bfa8e211..5a2d9b0ea 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -31,7 +31,18 @@ class Gestionnaire < ApplicationRecord return end - followed_dossiers << dossier + begin + followed_dossiers << dossier + rescue ActiveRecord::RecordNotUnique + # Altough we checked before the insertion that the gestionnaire wasn't + # already following this dossier, this was done at the Rails level: + # at the database level, the dossier was already followed, and a + # "invalid constraint" exception is raised. + # + # We can ignore this safely, as it means the goal is already reached: + # the gestionnaire follows the dossier. + return + end end def unfollow(dossier) @@ -116,6 +127,8 @@ class Gestionnaire < ApplicationRecord procedure.dossiers.termine when :not_archived procedure.dossiers.not_archived + when :all + procedure.dossiers else procedure.dossiers.en_cours end @@ -215,7 +228,7 @@ class Gestionnaire < ApplicationRecord h = { nb_en_construction: procedure.dossiers.en_construction.count, - nb_notification: notifications_per_procedure(procedure).count + nb_notification: notifications_for_procedure(procedure, :all).count } if h[:nb_en_construction] > 0 || h[:nb_notification] > 0 diff --git a/app/views/fields/types_de_champ_collection_field/_show.html.haml b/app/views/fields/types_de_champ_collection_field/_show.html.haml index 86b298e54..f70d88c66 100644 --- a/app/views/fields/types_de_champ_collection_field/_show.html.haml +++ b/app/views/fields/types_de_champ_collection_field/_show.html.haml @@ -5,6 +5,7 @@ %td.cell-label Libelle %td.cell-label Type de champ %td.cell-label Rempli + %td.cell-label Modifier le modèle %tbody - field.data.order(:order_place).each do |f| %tr @@ -20,5 +21,14 @@ vide - else rempli + + %td.cell-data + - if f.type_champ == 'piece_justificative' + = form_for f, + url: change_piece_justificative_template_manager_procedure_path, + method: :post do |form| + = form.hidden_field :id + = form.file_field :piece_justificative_template + = form.submit 'modifier' - else Aucun diff --git a/app/views/shared/dossiers/_edit.html.haml b/app/views/shared/dossiers/_edit.html.haml index 5dc2bba2c..54c4f41be 100644 --- a/app/views/shared/dossiers/_edit.html.haml +++ b/app/views/shared/dossiers/_edit.html.haml @@ -14,7 +14,7 @@ .mandatory-explanation Les champs avec un astérisque ( %span.mandatory> * - ) sont obligatoires. + ) sont obligatoires. Pour enregistrer les informations saisies, cliquez sur le bouton « enregistrer le brouillon » en bas à gauche du formulaire. - if notice_url(dossier.procedure).present? = link_to notice_url(dossier.procedure), target: '_blank', rel: 'noopener', class: 'button notice', title: "Pour vous aider à remplir votre dossier, vous pouvez consulter le guide de cette démarche." do diff --git a/config/routes.rb b/config/routes.rb index 20cd28d8a..33493af6c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,6 +11,7 @@ Rails.application.routes.draw do post 'draft', on: :member post 'hide', on: :member post 'add_administrateur', on: :member + post 'change_piece_justificative_template', on: :member end resources :dossiers, only: [:index, :show] do diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index ee3cfbafa..04a56e02f 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -279,7 +279,7 @@ describe Gestionnaire, type: :model do end end - describe '#notification_for_procedure' do + describe '#notifications_for_procedure' do let!(:dossier) { create(:dossier, :followed, state: Dossier.states.fetch(:en_construction)) } let(:gestionnaire) { dossier.follows.first.gestionnaire } let(:procedure) { dossier.procedure } @@ -438,8 +438,8 @@ describe Gestionnaire, type: :model do context 'when a notification exists' do before do - allow(gestionnaire).to receive(:notifications_per_procedure) - .with(procedure_to_assign) + allow(gestionnaire).to receive(:notifications_for_procedure) + .with(procedure_to_assign, :all) .and_return([1, 2, 3]) end diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index 7c9a9e116..c690c2ba6 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -49,7 +49,7 @@ describe NotificationService do context 'when there is a notification on this procedure' do before do - allow_any_instance_of(Gestionnaire).to receive(:notifications_per_procedure) + allow_any_instance_of(Gestionnaire).to receive(:notifications_for_procedure) .and_return([12]) end