Merge pull request #6056 from betagouv/rename-expert-controller-actions
`ExpertsProceduresController` utilise maintenant les actions par défaut de Rails (#6056)
This commit is contained in:
commit
dd40b17e60
8 changed files with 90 additions and 76 deletions
|
@ -1,8 +1,16 @@
|
|||
module NewAdministrateur
|
||||
class ExpertsProceduresController < AdministrateurController
|
||||
before_action :retrieve_procedure, only: [:add_expert_to_procedure, :revoke_expert_from_procedure]
|
||||
before_action :retrieve_procedure
|
||||
|
||||
def add_expert_to_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,15 +37,32 @@ 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 revoke_expert_from_procedure
|
||||
expert_procedure = ExpertsProcedure.find_by!(procedure: @procedure, id: params[:expert_procedure][:id])
|
||||
def update
|
||||
@procedure
|
||||
.experts_procedures
|
||||
.find(params[:id])
|
||||
.update!(expert_procedure_params)
|
||||
end
|
||||
|
||||
def destroy
|
||||
expert_procedure = ExpertsProcedure.find_by!(procedure: @procedure, id: params[:id])
|
||||
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
|
||||
|
||||
def expert_procedure_params
|
||||
params.require(:experts_procedure).permit(:allow_decision_access)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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]
|
||||
before_action :procedure_locked?, only: [:champs, :annotations]
|
||||
|
||||
ITEMS_PER_PAGE = 25
|
||||
|
@ -185,24 +185,8 @@ 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
|
||||
.find(params[:expert_procedure])
|
||||
.update!(allow_decision_access_params)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def experts_procedure_emails
|
||||
@procedure.experts.map(&:email).sort
|
||||
end
|
||||
|
||||
def apercu_tab
|
||||
params[:tab] || 'dossier'
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
.card
|
||||
.card-title Affecter des experts à la démarche
|
||||
= form_for :experts_procedure,
|
||||
url: admin_procedure_add_expert_to_procedure_path(@procedure),
|
||||
url: admin_procedure_experts_path(@procedure),
|
||||
html: { class: 'form' } do |f|
|
||||
|
||||
.instructeur-wrapper
|
||||
|
@ -46,7 +46,7 @@
|
|||
- if @procedure.feature_enabled?(:admin_affect_experts_to_avis)
|
||||
%td.text-center
|
||||
= form_for expert_procedure,
|
||||
url: admin_procedure_update_allow_decision_access_path(expert_procedure: expert_procedure),
|
||||
url: admin_procedure_expert_path(id: expert_procedure),
|
||||
remote: true,
|
||||
method: :put,
|
||||
authenticity_token: true,
|
||||
|
@ -57,13 +57,11 @@
|
|||
%span.toggle-switch-label.on
|
||||
%span.toggle-switch-label.off
|
||||
%td.actions= button_to 'retirer',
|
||||
{ action: "revoke_expert_from_procedure", :controller=>"new_administrateur/experts_procedures" },
|
||||
{ method: :put,
|
||||
data: { confirm: "Êtes-vous sûr de vouloir révoquer l'expert « #{expert_procedure.expert.email} » de la démarche #{expert_procedure.procedure.libelle} ? Les instructeurs ne pourront plus lui demander d'avis" },
|
||||
params: { expert_procedure: { id: expert_procedure.id }},
|
||||
class: 'button' }
|
||||
admin_procedure_expert_path(id: expert_procedure, procedure: @procedure),
|
||||
method: :delete,
|
||||
data: { confirm: "Êtes-vous sûr de vouloir révoquer l'expert « #{expert_procedure.expert.email} » de la démarche #{expert_procedure.procedure.libelle} ? Les instructeurs ne pourront plus lui demander d'avis" },
|
||||
class: 'button'
|
||||
- else
|
||||
.blank-tab
|
||||
%h2.empty-text Aucun expert invité pour le moment.
|
||||
%p.empty-text-details Les instructeurs de cette démarche n'ont pas encore fait appel aux experts.
|
||||
|
|
@ -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
|
||||
|
|
|
@ -406,10 +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
|
||||
post 'add_expert_to_procedure' => 'experts_procedures#add_expert_to_procedure', as: :add_expert_to_procedure
|
||||
put 'revoke_expert_from_procedure' => 'experts_procedures#revoke_expert_from_procedure', as: :revoke_expert_from_procedure
|
||||
resources :mail_templates, only: [:edit, :update]
|
||||
|
||||
resources :groupe_instructeurs, only: [:index, :show, :create, :update, :destroy] do
|
||||
|
@ -427,6 +423,8 @@ Rails.application.routes.draw do
|
|||
|
||||
resources :administrateurs, controller: 'procedure_administrateurs', only: [:index, :create, :destroy]
|
||||
|
||||
resources :experts, controller: 'experts_procedures', only: [:index, :create, :update, :destroy]
|
||||
|
||||
resources :types_de_champ, only: [:create, :update, :destroy] do
|
||||
member do
|
||||
patch :move
|
||||
|
|
|
@ -1,17 +1,32 @@
|
|||
describe NewAdministrateur::ExpertsProceduresController, type: :controller do
|
||||
let(:admin) { create(:administrateur) }
|
||||
let(:procedure) { create :procedure, administrateur: admin }
|
||||
|
||||
before do
|
||||
sign_in(admin.user)
|
||||
end
|
||||
describe '#add_expert_to_procedure' do
|
||||
let(:procedure) { create :procedure, administrateur: admin }
|
||||
|
||||
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(:expert) { create(:expert) }
|
||||
let(:expert2) { create(:expert) }
|
||||
|
||||
subject do
|
||||
post :add_expert_to_procedure,
|
||||
params: { procedure_id: procedure.id, emails: "[\"#{expert.email}\",\"#{expert2.email}\"]" }
|
||||
post :create, params: {
|
||||
procedure_id: procedure.id,
|
||||
emails: "[\"#{expert.email}\",\"#{expert2.email}\"]"
|
||||
}
|
||||
end
|
||||
|
||||
before do
|
||||
|
@ -22,17 +37,41 @@ 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 '#revoke_expert_from_procedure' do
|
||||
let(:procedure) { create :procedure, administrateur: admin }
|
||||
describe '#update' do
|
||||
let(:expert) { create(:expert) }
|
||||
let(:expert_procedure) { create(:experts_procedure, procedure: procedure, expert: expert) }
|
||||
|
||||
subject do
|
||||
put :update, params: {
|
||||
id: expert_procedure.id,
|
||||
procedure_id: procedure.id,
|
||||
experts_procedure: {
|
||||
allow_decision_access: true
|
||||
}
|
||||
}, format: :js
|
||||
end
|
||||
|
||||
before do
|
||||
subject
|
||||
end
|
||||
|
||||
it 'updates the record' do
|
||||
expect(expert_procedure.allow_decision_access).to be false
|
||||
subject
|
||||
expect(expert_procedure.reload.allow_decision_access).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#delete' do
|
||||
let(:expert) { create(:expert) }
|
||||
let(:expert_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) }
|
||||
|
||||
subject do
|
||||
put :revoke_expert_from_procedure, params: { procedure_id: procedure.id, expert_procedure: { id: expert_procedure.id } }
|
||||
delete :destroy, params: { procedure_id: procedure.id, id: expert_procedure.id }
|
||||
end
|
||||
|
||||
before do
|
||||
|
@ -43,7 +82,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
|
||||
|
|
|
@ -532,34 +532,4 @@ describe NewAdministrateur::ProceduresController, type: :controller do
|
|||
it { expect(procedure.allow_expert_review).to be_truthy }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT #update_allow_decision_access' do
|
||||
let!(:procedure) { create :procedure, :with_service, administrateur: admin }
|
||||
let(:expert) { create(:expert) }
|
||||
let(:expert_procedure) { create(:experts_procedure, procedure: procedure, expert: expert) }
|
||||
|
||||
subject do
|
||||
put :update_allow_decision_access, params: { procedure_id: procedure.id, experts_procedure: { allow_decision_access: !expert_procedure.allow_decision_access }, expert_procedure: expert_procedure }, format: :js
|
||||
end
|
||||
|
||||
context 'when the experts_procedure is true' do
|
||||
let(:expert_procedure) { create(:experts_procedure, procedure: procedure, expert: expert, allow_decision_access: true) }
|
||||
|
||||
before do
|
||||
subject
|
||||
expert_procedure.reload
|
||||
end
|
||||
|
||||
it { expect(expert_procedure.allow_decision_access).to be_falsy }
|
||||
end
|
||||
|
||||
context 'when the experts_procedure is false' do
|
||||
before do
|
||||
subject
|
||||
expert_procedure.reload
|
||||
end
|
||||
|
||||
it { expect(expert_procedure.allow_decision_access).to be_truthy }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
Loading…
Reference in a new issue