app: move the experts list to ExpertsProceduresController

This commit is contained in:
Pierre de La Morinerie 2021-04-06 11:55:43 +00:00
parent 7acb4cee83
commit c82c72402d
7 changed files with 35 additions and 20 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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