From 7b4ec486ec8949166ad73c5eb60009c05356ea71 Mon Sep 17 00:00:00 2001 From: kara Diaby Date: Thu, 11 Feb 2021 19:32:48 +0100 Subject: [PATCH 1/4] change active record request to get expert list --- .../new_administrateur/procedures_controller.rb | 2 +- app/models/experts_procedure.rb | 11 ----------- spec/models/experts_procedure_spec.rb | 14 ++++++++++---- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/app/controllers/new_administrateur/procedures_controller.rb b/app/controllers/new_administrateur/procedures_controller.rb index bebb3a255..7a2169656 100644 --- a/app/controllers/new_administrateur/procedures_controller.rb +++ b/app/controllers/new_administrateur/procedures_controller.rb @@ -186,7 +186,7 @@ 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 private diff --git a/app/models/experts_procedure.rb b/app/models/experts_procedure.rb index d874fdb36..203f927fc 100644 --- a/app/models/experts_procedure.rb +++ b/app/models/experts_procedure.rb @@ -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 diff --git a/spec/models/experts_procedure_spec.rb b/spec/models/experts_procedure_spec.rb index efd227593..b6dd1a7b8 100644 --- a/spec/models/experts_procedure_spec.rb +++ b/spec/models/experts_procedure_spec.rb @@ -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 From 9492b09f856fedd5f2358884c477a36c94990fa2 Mon Sep 17 00:00:00 2001 From: kara Diaby Date: Thu, 11 Feb 2021 20:19:15 +0100 Subject: [PATCH 2/4] make and expert notifiable (controller and routes) --- .../new_administrateur/procedures_controller.rb | 13 ++++++++++++- config/routes.rb | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/controllers/new_administrateur/procedures_controller.rb b/app/controllers/new_administrateur/procedures_controller.rb index 7a2169656..8b2c0431d 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] + 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 @@ -189,6 +189,13 @@ module NewAdministrateur @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 def apercu_tab @@ -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 diff --git a/config/routes.rb b/config/routes.rb index f9a9f8131..f3117b72b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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] From 38172106498c150ccbc4135e40d8b168f618051f Mon Sep 17 00:00:00 2001 From: kara Diaby Date: Thu, 11 Feb 2021 20:23:11 +0100 Subject: [PATCH 3/4] layout --- app/assets/stylesheets/procedure_form.scss | 4 +++ .../procedures/invited_expert_list.html.haml | 28 ++++++++++++++++--- .../procedures/show.html.haml | 2 +- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/procedure_form.scss b/app/assets/stylesheets/procedure_form.scss index e5b9b750a..fff8e74e4 100644 --- a/app/assets/stylesheets/procedure_form.scss +++ b/app/assets/stylesheets/procedure_form.scss @@ -23,6 +23,10 @@ flex: 10; padding: 0 $default-padding; background-color: $light-grey; + + &.no-background { + background-color: transparent; + } } .procedure-form__column--preview { diff --git a/app/views/new_administrateur/procedures/invited_expert_list.html.haml b/app/views/new_administrateur/procedures/invited_expert_list.html.haml index 6c1b82e64..d783e8caf 100644 --- a/app/views/new_administrateur/procedures/invited_expert_list.html.haml +++ b/app/views/new_administrateur/procedures/invited_expert_list.html.haml @@ -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. diff --git a/app/views/new_administrateur/procedures/show.html.haml b/app/views/new_administrateur/procedures/show.html.haml index 834fe6adf..83a5ca28f 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", invited_expert_list_admin_procedure_path(@procedure), class: 'button' + = link_to "Voir", admin_procedure_invited_expert_list_path(@procedure), class: 'button' .card-admin From 8310dc48bff553a86beedfd56f938c5883eeb84b Mon Sep 17 00:00:00 2001 From: kara Diaby Date: Thu, 11 Feb 2021 20:30:40 +0100 Subject: [PATCH 4/4] tests --- .../procedures_controller_spec.rb | 30 +++++++++++++++++++ .../invited_expert_list.html.haml_spec.rb | 12 ++++---- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/spec/controllers/new_administrateur/procedures_controller_spec.rb b/spec/controllers/new_administrateur/procedures_controller_spec.rb index e508faba7..5aa38b7ac 100644 --- a/spec/controllers/new_administrateur/procedures_controller_spec.rb +++ b/spec/controllers/new_administrateur/procedures_controller_spec.rb @@ -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 diff --git a/spec/views/new_administrateur/procedures/invited_expert_list.html.haml_spec.rb b/spec/views/new_administrateur/procedures/invited_expert_list.html.haml_spec.rb index 98aa12ef4..6f962b01e 100644 --- a/spec/views/new_administrateur/procedures/invited_expert_list.html.haml_spec.rb +++ b/spec/views/new_administrateur/procedures/invited_expert_list.html.haml_spec.rb @@ -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