app: move update_allow_decision_access to ExpertsController

This commit is contained in:
Pierre de La Morinerie 2021-04-06 14:25:41 +02:00
parent c82c72402d
commit 62051c926a
6 changed files with 39 additions and 41 deletions

View file

@ -40,6 +40,13 @@ module NewAdministrateur
redirect_to admin_procedure_experts_path(@procedure) redirect_to admin_procedure_experts_path(@procedure)
end end
def update
@procedure
.experts_procedures
.find(params[:id])
.update!(expert_procedure_params)
end
def destroy def destroy
expert_procedure = ExpertsProcedure.find_by!(procedure: @procedure, id: params[:id]) expert_procedure = ExpertsProcedure.find_by!(procedure: @procedure, id: params[:id])
expert_email = expert_procedure.expert.email expert_email = expert_procedure.expert.email
@ -53,5 +60,9 @@ module NewAdministrateur
def experts_procedure_emails def experts_procedure_emails
@procedure.experts.map(&:email).sort @procedure.experts.map(&:email).sort
end end
def expert_procedure_params
params.require(:experts_procedure).permit(:allow_decision_access)
end
end end
end end

View file

@ -1,6 +1,6 @@
module NewAdministrateur module NewAdministrateur
class ProceduresController < AdministrateurController class ProceduresController < AdministrateurController
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 :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] before_action :procedure_locked?, only: [:champs, :annotations]
ITEMS_PER_PAGE = 25 ITEMS_PER_PAGE = 25
@ -185,13 +185,6 @@ module NewAdministrateur
end end
end end
def update_allow_decision_access
@procedure
.experts_procedures
.find(params[:expert_procedure])
.update!(allow_decision_access_params)
end
private private
def apercu_tab def apercu_tab

View file

@ -46,7 +46,7 @@
- if @procedure.feature_enabled?(:admin_affect_experts_to_avis) - if @procedure.feature_enabled?(:admin_affect_experts_to_avis)
%td.text-center %td.text-center
= form_for expert_procedure, = 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, remote: true,
method: :put, method: :put,
authenticity_token: true, authenticity_token: true,

View file

@ -406,7 +406,6 @@ Rails.application.routes.draw do
put 'publish' => 'procedures#publish', as: :publish put 'publish' => 'procedures#publish', as: :publish
get 'transfert' => 'procedures#transfert', as: :transfert get 'transfert' => 'procedures#transfert', as: :transfert
post 'transfer' => 'procedures#transfer', as: :transfer post 'transfer' => 'procedures#transfer', as: :transfer
put 'update_allow_decision_access' => 'procedures#update_allow_decision_access', as: :update_allow_decision_access
resources :mail_templates, only: [:edit, :update] resources :mail_templates, only: [:edit, :update]
resources :groupe_instructeurs, only: [:index, :show, :create, :update, :destroy] do resources :groupe_instructeurs, only: [:index, :show, :create, :update, :destroy] do
@ -424,7 +423,7 @@ Rails.application.routes.draw do
resources :administrateurs, controller: 'procedure_administrateurs', only: [:index, :create, :destroy] resources :administrateurs, controller: 'procedure_administrateurs', only: [:index, :create, :destroy]
resources :experts, controller: 'experts_procedures', only: [:index, :create, :destroy] resources :experts, controller: 'experts_procedures', only: [:index, :create, :update, :destroy]
resources :types_de_champ, only: [:create, :update, :destroy] do resources :types_de_champ, only: [:create, :update, :destroy] do
member do member do

View file

@ -41,6 +41,31 @@ describe NewAdministrateur::ExpertsProceduresController, type: :controller do
end end
end end
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 describe '#delete' do
let(:expert) { create(:expert) } let(:expert) { create(:expert) }
let(:expert_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) } let(:expert_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) }

View file

@ -532,34 +532,4 @@ describe NewAdministrateur::ProceduresController, type: :controller do
it { expect(procedure.allow_expert_review).to be_truthy } it { expect(procedure.allow_expert_review).to be_truthy }
end end
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 end