From c82c72402d517011865d31cb4ddfbca3c0ba2d51 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 6 Apr 2021 11:55:43 +0000 Subject: [PATCH] app: move the experts list to ExpertsProceduresController --- .../experts_procedures_controller.rb | 18 ++++++++++++++++-- .../procedures_controller.rb | 11 +---------- .../index.html.haml} | 0 .../procedures/show.html.haml | 2 +- config/routes.rb | 3 +-- .../experts_procedures_controller_spec.rb | 19 +++++++++++++++---- .../index.html.haml_spec.rb} | 2 +- 7 files changed, 35 insertions(+), 20 deletions(-) rename app/views/new_administrateur/{procedures/invited_expert_list.html.haml => experts_procedures/index.html.haml} (100%) rename spec/views/new_administrateur/{procedures/invited_expert_list.html.haml_spec.rb => experts_procedures/index.html.haml_spec.rb} (93%) diff --git a/app/controllers/new_administrateur/experts_procedures_controller.rb b/app/controllers/new_administrateur/experts_procedures_controller.rb index 89645ec5f..dada4d873 100644 --- a/app/controllers/new_administrateur/experts_procedures_controller.rb +++ b/app/controllers/new_administrateur/experts_procedures_controller.rb @@ -2,6 +2,14 @@ module NewAdministrateur class ExpertsProceduresController < AdministrateurController before_action :retrieve_procedure + def index + @experts_procedure = @procedure + .experts_procedures + .where(revoked_at: nil) + .sort_by { |expert_procedure| expert_procedure.expert.email } + @experts_emails = experts_procedure_emails + end + def create emails = params['emails'].presence || [].to_json emails = JSON.parse(emails).map(&:strip).map(&:downcase) @@ -29,7 +37,7 @@ module NewAdministrateur value: valid_users.map(&:email).join(', '), procedure: @procedure.id) end - redirect_to admin_procedure_invited_expert_list_path(@procedure) + redirect_to admin_procedure_experts_path(@procedure) end def destroy @@ -37,7 +45,13 @@ module NewAdministrateur expert_email = expert_procedure.expert.email expert_procedure.update!(revoked_at: Time.zone.now) flash[:notice] = "#{expert_email} a été révoqué de la démarche et ne pourra plus déposer d'avis." - redirect_to admin_procedure_invited_expert_list_path(@procedure) + redirect_to admin_procedure_experts_path(@procedure) + end + + private + + def experts_procedure_emails + @procedure.experts.map(&:email).sort end end end diff --git a/app/controllers/new_administrateur/procedures_controller.rb b/app/controllers/new_administrateur/procedures_controller.rb index 212878085..637b6d3ad 100644 --- a/app/controllers/new_administrateur/procedures_controller.rb +++ b/app/controllers/new_administrateur/procedures_controller.rb @@ -1,6 +1,6 @@ module NewAdministrateur class ProceduresController < AdministrateurController - before_action :retrieve_procedure, only: [:champs, :annotations, :edit, :monavis, :update_monavis, :jeton, :update_jeton, :publication, :publish, :transfert, :allow_expert_review, :invited_expert_list, :update_allow_decision_access] + before_action :retrieve_procedure, only: [:champs, :annotations, :edit, :monavis, :update_monavis, :jeton, :update_jeton, :publication, :publish, :transfert, :allow_expert_review, :update_allow_decision_access] before_action :procedure_locked?, only: [:champs, :annotations] ITEMS_PER_PAGE = 25 @@ -185,11 +185,6 @@ module NewAdministrateur end end - def invited_expert_list - @experts_procedure = @procedure.experts_procedures.where(revoked_at: nil).sort_by { |expert_procedure| expert_procedure.expert.email } - @experts_emails = experts_procedure_emails - end - def update_allow_decision_access @procedure .experts_procedures @@ -199,10 +194,6 @@ module NewAdministrateur private - def experts_procedure_emails - @procedure.experts.map(&:email).sort - end - def apercu_tab params[:tab] || 'dossier' end diff --git a/app/views/new_administrateur/procedures/invited_expert_list.html.haml b/app/views/new_administrateur/experts_procedures/index.html.haml similarity index 100% rename from app/views/new_administrateur/procedures/invited_expert_list.html.haml rename to app/views/new_administrateur/experts_procedures/index.html.haml diff --git a/app/views/new_administrateur/procedures/show.html.haml b/app/views/new_administrateur/procedures/show.html.haml index 83a5ca28f..6f362e623 100644 --- a/app/views/new_administrateur/procedures/show.html.haml +++ b/app/views/new_administrateur/procedures/show.html.haml @@ -167,7 +167,7 @@ %p.card-admin-subtitle Liste des experts invités par les instructeurs .card-admin-action - = link_to "Voir", admin_procedure_invited_expert_list_path(@procedure), class: 'button' + = link_to "Voir", admin_procedure_experts_path(@procedure), class: 'button' .card-admin diff --git a/config/routes.rb b/config/routes.rb index 41180668f..ee2b37e7b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -406,7 +406,6 @@ Rails.application.routes.draw do put 'publish' => 'procedures#publish', as: :publish get 'transfert' => 'procedures#transfert', as: :transfert post 'transfer' => 'procedures#transfer', as: :transfer - get 'invited_expert_list' put 'update_allow_decision_access' => 'procedures#update_allow_decision_access', as: :update_allow_decision_access resources :mail_templates, only: [:edit, :update] @@ -425,7 +424,7 @@ Rails.application.routes.draw do resources :administrateurs, controller: 'procedure_administrateurs', only: [:index, :create, :destroy] - resources :experts, controller: 'experts_procedures', only: [:create, :destroy] + resources :experts, controller: 'experts_procedures', only: [:index, :create, :destroy] resources :types_de_champ, only: [:create, :update, :destroy] do member do diff --git a/spec/controllers/new_administrateur/experts_procedures_controller_spec.rb b/spec/controllers/new_administrateur/experts_procedures_controller_spec.rb index 88a8d38fc..48c85f043 100644 --- a/spec/controllers/new_administrateur/experts_procedures_controller_spec.rb +++ b/spec/controllers/new_administrateur/experts_procedures_controller_spec.rb @@ -1,12 +1,24 @@ describe NewAdministrateur::ExpertsProceduresController, type: :controller do let(:admin) { create(:administrateur) } + let(:procedure) { create :procedure, administrateur: admin } before do sign_in(admin.user) end + describe '#index' do + subject do + get :index, params: { procedure_id: procedure.id } + end + + before do + subject + end + + it { expect(response.status).to eq 200 } + end + describe '#create' do - let(:procedure) { create :procedure, administrateur: admin } let(:expert) { create(:expert) } let(:expert2) { create(:expert) } @@ -25,12 +37,11 @@ describe NewAdministrateur::ExpertsProceduresController, type: :controller do it { expect(procedure.experts.include?(expert)).to be_truthy } it { expect(procedure.experts.include?(expert2)).to be_truthy } it { expect(flash.notice).to be_present } - it { expect(response).to redirect_to(admin_procedure_invited_expert_list_path(procedure)) } + it { expect(response).to redirect_to(admin_procedure_experts_path(procedure)) } end end describe '#delete' do - let(:procedure) { create :procedure, administrateur: admin } let(:expert) { create(:expert) } let(:expert_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) } @@ -46,7 +57,7 @@ describe NewAdministrateur::ExpertsProceduresController, type: :controller do context 'of multiple experts' do it { expect(expert_procedure.revoked_at).to be_present } it { expect(flash.notice).to be_present } - it { expect(response).to redirect_to(admin_procedure_invited_expert_list_path(procedure)) } + it { expect(response).to redirect_to(admin_procedure_experts_path(procedure)) } end end end diff --git a/spec/views/new_administrateur/procedures/invited_expert_list.html.haml_spec.rb b/spec/views/new_administrateur/experts_procedures/index.html.haml_spec.rb similarity index 93% rename from spec/views/new_administrateur/procedures/invited_expert_list.html.haml_spec.rb rename to spec/views/new_administrateur/experts_procedures/index.html.haml_spec.rb index c21d87f40..b4a34df12 100644 --- a/spec/views/new_administrateur/procedures/invited_expert_list.html.haml_spec.rb +++ b/spec/views/new_administrateur/experts_procedures/index.html.haml_spec.rb @@ -1,4 +1,4 @@ -describe 'new_administrateur/procedures/invited_expert_list.html.haml', type: :view do +describe 'new_administrateur/experts_procedures/index.html.haml', type: :view do let!(:procedure) { create(:procedure, :published) } before do