From 38b48f4217a4d3aae9b6611f6c9c59421e91e9b1 Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Mon, 29 Jul 2019 10:57:21 +0200 Subject: [PATCH 1/3] transition from accepte to instruction as superadmin --- .../gestionnaires/dossiers_controller.rb | 8 ++++-- .../manager/dossiers_controller.rb | 10 +++++++ app/models/dossier.rb | 5 ++++ app/views/manager/dossiers/show.html.erb | 3 ++ config/routes.rb | 1 + .../gestionnaires/dossiers_controller_spec.rb | 28 ++++++++++++++++++- .../manager/dossiers_controller_spec.rb | 13 +++++++++ 7 files changed, 65 insertions(+), 3 deletions(-) diff --git a/app/controllers/gestionnaires/dossiers_controller.rb b/app/controllers/gestionnaires/dossiers_controller.rb index adbc9e237..096b954e6 100644 --- a/app/controllers/gestionnaires/dossiers_controller.rb +++ b/app/controllers/gestionnaires/dossiers_controller.rb @@ -109,8 +109,12 @@ module Gestionnaires if dossier.en_instruction? flash.notice = 'Le dossier est déjà en instruction.' else - flash.notice = "Le dossier #{dossier.id} a été repassé en instruction." - dossier.repasser_en_instruction!(current_gestionnaire) + if dossier.accepte? && !administration_signed_in? + flash.notice = 'Il n\'est pas possible de repasser un dossier accepte en instruction.' + else + flash.notice = "Le dossier #{dossier.id} a été repassé en instruction." + dossier.repasser_en_instruction!(current_gestionnaire) + end end render partial: 'state_button_refresh', locals: { dossier: dossier } diff --git a/app/controllers/manager/dossiers_controller.rb b/app/controllers/manager/dossiers_controller.rb index 35b7c785c..8fd264a62 100644 --- a/app/controllers/manager/dossiers_controller.rb +++ b/app/controllers/manager/dossiers_controller.rb @@ -30,6 +30,16 @@ module Manager redirect_to manager_dossier_path(dossier) end + def repasser_en_instruction + dossier = Dossier.find(params[:id]) + dossier.repasser_en_instruction(current_administration) + + logger.info("Le dossier #{dossier.id} est repassé en instruction par #{current_administration.email}") + flash[:notice] = "Le dossier #{dossier.id} est repassé en instruction." + + redirect_to manager_dossier_path(dossier) + end + private def unfiltered_list? diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 30bbe5312..10f6d0b1c 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -1,5 +1,6 @@ class Dossier < ApplicationRecord include DossierFilteringConcern + include Devise::Controllers::Helpers enum state: { brouillon: 'brouillon', @@ -86,6 +87,7 @@ class Dossier < ApplicationRecord event :repasser_en_instruction, after: :after_repasser_en_instruction do transitions from: :refuse, to: :en_instruction transitions from: :sans_suite, to: :en_instruction + transitions from: :accepte, to: :en_instruction end end @@ -228,6 +230,9 @@ class Dossier < ApplicationRecord !procedure.archivee? && brouillon? end + def can_retransition_to_en_instruction? + end + def can_be_updated_by_user? brouillon? || en_construction? end diff --git a/app/views/manager/dossiers/show.html.erb b/app/views/manager/dossiers/show.html.erb index 1dcae61cc..b8a1ec640 100644 --- a/app/views/manager/dossiers/show.html.erb +++ b/app/views/manager/dossiers/show.html.erb @@ -28,6 +28,9 @@ as well as a link to its edit page.
+ <% if dossier.accepte? %> + <%= link_to 'Repasser en instruction', repasser_en_instruction_manager_dossier_path(dossier), method: :post, class: 'button', data: { confirm: "Confirmez vous le passage en instruction du dossier ?" } %> + <% end %> <% if dossier.hidden_at.nil? %> <%= link_to 'Supprimer le dossier', hide_manager_dossier_path(dossier), method: :post, class: 'button', data: { confirm: "Confirmez vous la suppression du dossier ?" } %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index d13ff6051..1a4bd3c6c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,6 +16,7 @@ Rails.application.routes.draw do resources :dossiers, only: [:index, :show] do post 'hide', on: :member + post 'repasser_en_instruction', on: :member end resources :administrateurs, only: [:index, :show, :new, :create] do diff --git a/spec/controllers/gestionnaires/dossiers_controller_spec.rb b/spec/controllers/gestionnaires/dossiers_controller_spec.rb index 0f327221a..9efeb267b 100644 --- a/spec/controllers/gestionnaires/dossiers_controller_spec.rb +++ b/spec/controllers/gestionnaires/dossiers_controller_spec.rb @@ -4,6 +4,8 @@ describe Gestionnaires::DossiersController, type: :controller do render_views let(:gestionnaire) { create(:gestionnaire) } + let(:administrateur) { create(:administrateur) } + let(:administration) { create(:administration) } let(:gestionnaires) { [gestionnaire] } let(:procedure) { create(:procedure, :published, gestionnaires: gestionnaires) } let(:dossier) { create(:dossier, :en_construction, procedure: procedure) } @@ -153,9 +155,10 @@ describe Gestionnaires::DossiersController, type: :controller do describe '#repasser_en_instruction' do let(:dossier) { create(:dossier, :refuse, procedure: procedure) } + let(:current_user) { gestionnaire } before do - sign_in gestionnaire + sign_in current_user post :repasser_en_instruction, params: { procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js' @@ -173,6 +176,29 @@ describe Gestionnaires::DossiersController, type: :controller do expect(response).to have_http_status(:ok) end end + + context 'when the dossier is accepte' do + let(:dossier) { create(:dossier, :accepte, procedure: procedure) } + + it 'it is not possible to go back to en_instruction as gestionnaire' do + expect(dossier.reload.state).to eq(Dossier.states.fetch(:accepte)) + expect(response).to have_http_status(:ok) + end + context 'as administrateur' do + let (:current_user) { administrateur } + it 'it is not possible to go back to en_instruction' do + expect(dossier.reload.state).to eq(Dossier.states.fetch(:accepte)) + expect(response).to have_http_status(:ok) + end + end + context 'as superadmin' do + let (:current_user) { administration } + it 'it is not possible to go back to en_instruction' do + expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) + expect(response).to have_http_status(:ok) + end + end + end end describe '#terminer' do diff --git a/spec/controllers/manager/dossiers_controller_spec.rb b/spec/controllers/manager/dossiers_controller_spec.rb index e3c5f3cad..cc835e6d6 100644 --- a/spec/controllers/manager/dossiers_controller_spec.rb +++ b/spec/controllers/manager/dossiers_controller_spec.rb @@ -11,4 +11,17 @@ describe Manager::DossiersController, type: :controller do it { expect(dossier.hidden_at).not_to be_nil } end + + describe '#repasser_en_instruction' do + let(:administration) { create :administration } + let!(:dossier) { create(:dossier, :accepte) } + + before do + sign_in administration + post :repasser_en_instruction, params: { id: dossier.id } + dossier.reload + end + + it { expect(dossier.en_instruction?).to be true } + end end From 2f82dd9a3ddb6d174378428dd2e1891444fb552d Mon Sep 17 00:00:00 2001 From: Keirua Date: Tue, 30 Jul 2019 08:42:22 +0200 Subject: [PATCH 2/3] improve typography and texts Co-Authored-By: Nicolas Bouilleaud --- app/controllers/gestionnaires/dossiers_controller.rb | 2 +- spec/controllers/gestionnaires/dossiers_controller_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/gestionnaires/dossiers_controller.rb b/app/controllers/gestionnaires/dossiers_controller.rb index 096b954e6..8cea6f1f6 100644 --- a/app/controllers/gestionnaires/dossiers_controller.rb +++ b/app/controllers/gestionnaires/dossiers_controller.rb @@ -110,7 +110,7 @@ module Gestionnaires flash.notice = 'Le dossier est déjà en instruction.' else if dossier.accepte? && !administration_signed_in? - flash.notice = 'Il n\'est pas possible de repasser un dossier accepte en instruction.' + flash.notice = 'Il n’est pas possible de repasser un dossier accepté en instruction.' else flash.notice = "Le dossier #{dossier.id} a été repassé en instruction." dossier.repasser_en_instruction!(current_gestionnaire) diff --git a/spec/controllers/gestionnaires/dossiers_controller_spec.rb b/spec/controllers/gestionnaires/dossiers_controller_spec.rb index 9efeb267b..2f02eb67a 100644 --- a/spec/controllers/gestionnaires/dossiers_controller_spec.rb +++ b/spec/controllers/gestionnaires/dossiers_controller_spec.rb @@ -193,7 +193,7 @@ describe Gestionnaires::DossiersController, type: :controller do end context 'as superadmin' do let (:current_user) { administration } - it 'it is not possible to go back to en_instruction' do + it 'it is possible to go back to en_instruction' do expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) expect(response).to have_http_status(:ok) end From f5d3818e3cdd27ed120f84c77c597376a8feb3af Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Tue, 30 Jul 2019 10:12:57 +0200 Subject: [PATCH 3/3] remove unnecessary retransition methods --- app/controllers/gestionnaires/dossiers_controller.rb | 2 +- app/models/dossier.rb | 4 ---- spec/controllers/gestionnaires/dossiers_controller_spec.rb | 4 ++-- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/app/controllers/gestionnaires/dossiers_controller.rb b/app/controllers/gestionnaires/dossiers_controller.rb index 8cea6f1f6..a830229a4 100644 --- a/app/controllers/gestionnaires/dossiers_controller.rb +++ b/app/controllers/gestionnaires/dossiers_controller.rb @@ -109,7 +109,7 @@ module Gestionnaires if dossier.en_instruction? flash.notice = 'Le dossier est déjà en instruction.' else - if dossier.accepte? && !administration_signed_in? + if dossier.accepte? flash.notice = 'Il n’est pas possible de repasser un dossier accepté en instruction.' else flash.notice = "Le dossier #{dossier.id} a été repassé en instruction." diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 10f6d0b1c..913976add 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -1,6 +1,5 @@ class Dossier < ApplicationRecord include DossierFilteringConcern - include Devise::Controllers::Helpers enum state: { brouillon: 'brouillon', @@ -230,9 +229,6 @@ class Dossier < ApplicationRecord !procedure.archivee? && brouillon? end - def can_retransition_to_en_instruction? - end - def can_be_updated_by_user? brouillon? || en_construction? end diff --git a/spec/controllers/gestionnaires/dossiers_controller_spec.rb b/spec/controllers/gestionnaires/dossiers_controller_spec.rb index 2f02eb67a..986ae1e46 100644 --- a/spec/controllers/gestionnaires/dossiers_controller_spec.rb +++ b/spec/controllers/gestionnaires/dossiers_controller_spec.rb @@ -193,8 +193,8 @@ describe Gestionnaires::DossiersController, type: :controller do end context 'as superadmin' do let (:current_user) { administration } - it 'it is possible to go back to en_instruction' do - expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) + it 'it is not possible to go back to en_instruction' do + expect(dossier.reload.state).to eq(Dossier.states.fetch(:accepte)) expect(response).to have_http_status(:ok) end end