Merge pull request #5904 from betagouv/5812-expert-notifiable

Technique : préparation du mécanisme pour rendre les instructeurs notifiables (ou non) de la décision finale sur un dossier (#5904)
This commit is contained in:
Pierre de La Morinerie 2021-02-16 11:04:48 +01:00 committed by GitHub
commit 6ba58baf30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 90 additions and 29 deletions

View file

@ -23,6 +23,10 @@
flex: 10;
padding: 0 $default-padding;
background-color: $light-grey;
&.no-background {
background-color: transparent;
}
}
.procedure-form__column--preview {

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]
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 :procedure_locked?, only: [:champs, :annotations]
ITEMS_PER_PAGE = 25
@ -186,7 +186,14 @@ module NewAdministrateur
end
def invited_expert_list
@invited_expert_emails = ExpertsProcedure.invited_expert_emails(@procedure)
@experts_procedure = @procedure.experts_procedures.sort_by { |expert_procedure| expert_procedure.expert.email }
end
def update_allow_decision_access
@procedure
.experts_procedures
.find(params[:expert_procedure])
.update!(allow_decision_access_params)
end
private
@ -215,5 +222,9 @@ module NewAdministrateur
def publish_params
params.permit(:path, :lien_site_web)
end
def allow_decision_access_params
params.require(:experts_procedure).permit(:allow_decision_access)
end
end
end

View file

@ -14,15 +14,4 @@ class ExpertsProcedure < ApplicationRecord
belongs_to :procedure
has_many :avis, dependent: :destroy
def email_to_display
expert&.email
end
def self.invited_expert_emails(procedure)
joins(:expert)
.where(procedure: procedure)
.map(&:email_to_display)
.sort
end
end

View file

@ -1,16 +1,36 @@
= render partial: 'new_administrateur/breadcrumbs',
locals: { steps: [link_to('Démarches', admin_procedures_path),
link_to(@procedure.libelle, admin_procedure_path(@procedure)),
'Liste des experts'] }
.container
%h1.mt-2 Experts invités sur #{@procedure.libelle}
- if @invited_expert_emails.present?
%h1.page-title.mt-2 Experts invités sur #{@procedure.libelle}
- if @experts_procedure.present?
%table.table.mt-2
%thead
%tr
%th Liste des experts
- if feature_enabled_for?(:make_experts_notifiable, @procedure)
%th Notifier des décisions sur les dossiers
%tbody
- @invited_expert_emails.each do |expert|
- @experts_procedure.each do |expert_procedure|
%tr
%td
%span.icon.person
= expert
= expert_procedure.expert.email
- if feature_enabled_for?(:make_experts_notifiable, @procedure)
%td
= form_for expert_procedure,
url: admin_procedure_update_allow_decision_access_path(expert_procedure: expert_procedure),
remote: true,
method: :put,
authenticity_token: true,
html: { class: 'form procedure-form__column--form no-background' } do |f|
%label.toggle-switch
= f.check_box :allow_decision_access, class: 'toggle-switch-checkbox', onchange: 'this.form.submit()'
%span.toggle-switch-control.round
%span.toggle-switch-label.on
%span.toggle-switch-label.off
- else
.blank-tab
%h2.empty-text Aucun expert invité pour le moment.

View file

@ -167,7 +167,7 @@
%p.card-admin-subtitle Liste des experts invités par les instructeurs
.card-admin-action
= link_to "Voir", invited_expert_list_admin_procedure_path(@procedure), class: 'button'
= link_to "Voir", admin_procedure_invited_expert_list_path(@procedure), class: 'button'
.card-admin

View file

@ -379,13 +379,14 @@ Rails.application.routes.draw do
get 'jeton'
patch 'update_jeton'
put :allow_expert_review
get 'invited_expert_list'
end
get 'publication' => 'procedures#publication', as: :publication
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]

View file

@ -532,4 +532,34 @@ 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) { ExpertsProcedure.create(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) { ExpertsProcedure.create(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

View file

@ -7,7 +7,7 @@ RSpec.describe ExpertsProcedure, type: :model do
let(:experts_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) }
let(:experts_procedure2) { ExpertsProcedure.create(expert: expert2, procedure: procedure) }
let(:experts_procedure3) { ExpertsProcedure.create(expert: expert3, procedure: procedure) }
subject { ExpertsProcedure.invited_expert_emails(procedure) }
subject { procedure.experts_procedures }
context 'when there is one dossier' do
let!(:dossier) { create(:dossier, procedure: procedure) }
@ -15,14 +15,18 @@ RSpec.describe ExpertsProcedure, type: :model do
context 'when a procedure has one avis and known instructeur' do
let!(:avis) { create(:avis, dossier: dossier, instructeur: create(:instructeur, email: expert.email), experts_procedure: experts_procedure) }
it { is_expected.to eq([expert.email]) }
it { is_expected.to eq([experts_procedure]) }
it { expect(procedure.experts.count).to eq(1) }
it { expect(procedure.experts.first.email).to eq(expert.email) }
end
context 'when a dossier has 2 avis from the same expert' do
let!(:avis) { create(:avis, dossier: dossier, experts_procedure: experts_procedure) }
let!(:avis2) { create(:avis, dossier: dossier, experts_procedure: experts_procedure) }
it { is_expected.to eq([expert.email]) }
it { is_expected.to eq([experts_procedure]) }
it { expect(procedure.experts.count).to eq(1) }
it { expect(procedure.experts.first).to eq(expert) }
end
end
@ -35,7 +39,9 @@ RSpec.describe ExpertsProcedure, type: :model do
let!(:avis2) { create(:avis, dossier: dossier2, experts_procedure: experts_procedure2) }
let!(:avis3) { create(:avis, dossier: dossier2, experts_procedure: experts_procedure3) }
it { is_expected.to eq([expert.email, expert2.email, expert3.email].sort) }
it { is_expected.to match_array([experts_procedure, experts_procedure2, experts_procedure3]) }
it { expect(procedure.experts.count).to eq(3) }
it { expect(procedure.experts).to match_array([expert, expert2, expert3]) }
end
end
end

View file

@ -12,13 +12,13 @@ describe 'new_administrateur/procedures/invited_expert_list.html.haml', type: :v
context 'when the procedure has 0 avis' do
let!(:dossier) { create(:dossier, procedure: procedure) }
before do
@invited_expert_emails = ExpertsProcedure.invited_expert_emails(procedure)
@invited_experts = procedure.experts_procedures
subject
end
it 'has 0 experts into the page' do
expect(@invited_expert_emails.count).to eq(0)
expect(@invited_expert_emails).to eq([])
expect(@invited_experts.count).to eq(0)
expect(@invited_experts).to eq([])
end
end
@ -32,13 +32,13 @@ describe 'new_administrateur/procedures/invited_expert_list.html.haml', type: :v
let!(:avis2) { create(:avis, dossier: dossier, experts_procedure: experts_procedure2) }
before do
@invited_expert_emails = ExpertsProcedure.invited_expert_emails(procedure)
@invited_experts = procedure.experts_procedures
subject
end
it 'has 2 experts and match array' do
expect(@invited_expert_emails.count).to eq(2)
expect(@invited_expert_emails).to eq([expert.email, expert2.email].sort)
expect(@invited_experts.count).to eq(2)
expect(@invited_experts).to match_array([experts_procedure, experts_procedure2])
end
end
end