From 1072bacb1295012cb5208ea7ddfff5e056fb9556 Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Mon, 29 Jun 2020 15:31:14 +0200 Subject: [PATCH 01/18] fix missing aria-labels in footer --- app/views/root/_footer.html.haml | 4 ++-- spec/features/accessibilite/wcag_usager_spec.rb | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/views/root/_footer.html.haml b/app/views/root/_footer.html.haml index 8c9248971..49f29d593 100644 --- a/app/views/root/_footer.html.haml +++ b/app/views/root/_footer.html.haml @@ -12,9 +12,9 @@ = link_to "beta.gouv.fr", "https://beta.gouv.fr", title: "le site de Beta.gouv.fr" %li = link_to "https://numerique.gouv.fr/", title: "DINUM", 'aria-label': 'DINUM' do - %span.footer-logo.footer-logo-dinum{ role: 'img' } + %span.footer-logo.footer-logo-dinum{ role: 'img', 'aria-label': 'Logo DINUM' } = link_to "https://beta.gouv.fr", title: "le site de Beta.gouv.fr", 'aria-label': 'beta.gouv.fr' do - %span.footer-logo.footer-logo-beta-gouv-fr{ role: 'img' } + %span.footer-logo.footer-logo-beta-gouv-fr{ role: 'img', 'aria-label': 'Logo beta.gouv.fr' } %span.footer-logo.footer-logo-france{ role: 'img', 'aria-label': 'République Française' } %li.footer-column diff --git a/spec/features/accessibilite/wcag_usager_spec.rb b/spec/features/accessibilite/wcag_usager_spec.rb index 30064e805..d54afe7ee 100644 --- a/spec/features/accessibilite/wcag_usager_spec.rb +++ b/spec/features/accessibilite/wcag_usager_spec.rb @@ -6,12 +6,12 @@ feature 'wcag rules for usager', js: true do context 'pages without the need to be logged in' do scenario 'homepage' do visit root_path - expect(page).to be_accessible.excluding ".footer-logo" + expect(page).to be_accessible end scenario 'sign_up page' do visit new_user_registration_path - expect(page).to be_accessible.excluding ".footer-logo" + expect(page).to be_accessible end scenario 'account confirmation page' do @@ -28,12 +28,12 @@ feature 'wcag rules for usager', js: true do scenario 'sign_in page' do visit new_user_session_path - expect(page).to be_accessible.excluding ".footer-logo", '#user_email' + expect(page).to be_accessible.excluding '#user_email' end scenario 'contact page' do visit contact_path - expect(page).to be_accessible.excluding ".footer-logo" + expect(page).to be_accessible end scenario 'commencer page' do From 3e1afa8bf997425454e1af1b8cc0cc8d30d75c69 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Thu, 16 Apr 2020 14:49:13 +0200 Subject: [PATCH 02/18] fix avis spec --- spec/controllers/instructeurs/avis_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/controllers/instructeurs/avis_controller_spec.rb b/spec/controllers/instructeurs/avis_controller_spec.rb index c4d4462cb..a7e1f327b 100644 --- a/spec/controllers/instructeurs/avis_controller_spec.rb +++ b/spec/controllers/instructeurs/avis_controller_spec.rb @@ -4,7 +4,7 @@ describe Instructeurs::AvisController, type: :controller do let(:claimant) { create(:instructeur) } let(:instructeur) { create(:instructeur) } - let(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) } + let(:procedure) { create(:procedure, :published, instructeurs: [claimant]) } let(:dossier) { create(:dossier, :en_construction, procedure: procedure) } let!(:avis_without_answer) { Avis.create(dossier: dossier, claimant: claimant, instructeur: instructeur) } let!(:avis_with_answer) { Avis.create(dossier: dossier, claimant: claimant, instructeur: instructeur, answer: 'yop') } From dcb9afaf259450a7cee77ac9ff53ea4522c8755d Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Thu, 16 Apr 2020 17:07:11 +0200 Subject: [PATCH 03/18] refactor expert avis url : fix avis_controller_spec --- config/routes.rb | 25 +++++------ .../instructeurs/avis_controller_spec.rb | 41 ++++++++++--------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index cecce951f..f33c91bd2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -309,6 +309,19 @@ Rails.application.routes.draw do end end + resources :avis, only: [:index, :show, :update] do + member do + get 'instruction' + get 'messagerie' + post 'commentaire' => 'avis#create_commentaire' + post 'avis' => 'avis#create_avis' + get 'bilans_bdf' + + get 'sign_up/email/:email' => 'avis#sign_up', constraints: { email: /.*/ }, as: 'sign_up' + post 'sign_up/email/:email' => 'avis#create_instructeur', constraints: { email: /.*/ } + end + end + patch 'update_displayed_fields' get 'update_sort/:table/:column' => 'procedures#update_sort', as: 'update_sort' post 'add_filter' @@ -347,18 +360,6 @@ Rails.application.routes.draw do end end end - resources :avis, only: [:index, :show, :update] do - member do - get 'instruction' - get 'messagerie' - post 'commentaire' => 'avis#create_commentaire' - post 'avis' => 'avis#create_avis' - get 'bilans_bdf' - - get 'sign_up/email/:email' => 'avis#sign_up', constraints: { email: /.*/ }, as: 'sign_up' - post 'sign_up/email/:email' => 'avis#create_instructeur', constraints: { email: /.*/ } - end - end get "recherche" => "recherche#index" end diff --git a/spec/controllers/instructeurs/avis_controller_spec.rb b/spec/controllers/instructeurs/avis_controller_spec.rb index a7e1f327b..aeef6fff9 100644 --- a/spec/controllers/instructeurs/avis_controller_spec.rb +++ b/spec/controllers/instructeurs/avis_controller_spec.rb @@ -12,22 +12,22 @@ describe Instructeurs::AvisController, type: :controller do before { sign_in(instructeur.user) } describe '#index' do - before { get :index } + before { get :index, params: { procedure_id: procedure.id } } - it { expect(response).to have_http_status(:success) } - it { expect(assigns(:avis_a_donner)).to match([avis_without_answer]) } - it { expect(assigns(:avis_donnes)).to match([avis_with_answer]) } - it { expect(assigns(:statut)).to eq('a-donner') } + xit { expect(response).to have_http_status(:success) } + xit { expect(assigns(:avis_a_donner)).to match([avis_without_answer]) } + xit { expect(assigns(:avis_donnes)).to match([avis_with_answer]) } + xit { expect(assigns(:statut)).to eq('a-donner') } context 'with a statut equal to donnes' do - before { get :index, params: { statut: 'donnes' } } + before { get :index, params: { statut: 'donnes', procedure_id: procedure.id } } - it { expect(assigns(:statut)).to eq('donnes') } + xit { expect(assigns(:statut)).to eq('donnes') } end end describe '#show' do - before { get :show, params: { id: avis_without_answer.id } } + before { get :show, params: { id: avis_without_answer.id, procedure_id: procedure.id } } it { expect(response).to have_http_status(:success) } it { expect(assigns(:avis)).to eq(avis_without_answer) } @@ -35,7 +35,7 @@ describe Instructeurs::AvisController, type: :controller do end describe '#instruction' do - before { get :instruction, params: { id: avis_without_answer.id } } + before { get :instruction, params: { id: avis_without_answer.id, procedure_id: procedure.id } } it { expect(response).to have_http_status(:success) } it { expect(assigns(:avis)).to eq(avis_without_answer) } @@ -43,7 +43,7 @@ describe Instructeurs::AvisController, type: :controller do end describe '#messagerie' do - before { get :messagerie, params: { id: avis_without_answer.id } } + before { get :messagerie, params: { id: avis_without_answer.id, procedure_id: procedure.id } } it { expect(response).to have_http_status(:success) } it { expect(assigns(:avis)).to eq(avis_without_answer) } @@ -51,7 +51,7 @@ describe Instructeurs::AvisController, type: :controller do end describe '#bilans_bdf' do - before { get :bilans_bdf, params: { id: avis_without_answer.id } } + before { get :bilans_bdf, params: { id: avis_without_answer.id, procedure_id: procedure.id } } it { expect(response).to redirect_to(instructeur_avis_path(avis_without_answer)) } end @@ -59,7 +59,7 @@ describe Instructeurs::AvisController, type: :controller do describe '#update' do describe 'without attachment' do before do - patch :update, params: { id: avis_without_answer.id, avis: { answer: 'answer' } } + patch :update, params: { id: avis_without_answer.id, procedure_id: procedure.id, avis: { answer: 'answer' } } avis_without_answer.reload end @@ -78,7 +78,7 @@ describe Instructeurs::AvisController, type: :controller do before do expect(ClamavService).to receive(:safe_file?).and_return(true) perform_enqueued_jobs do - post :update, params: { id: avis_without_answer.id, avis: { answer: 'answer', piece_justificative_file: file } } + post :update, params: { id: avis_without_answer.id, procedure_id: procedure.id, avis: { answer: 'answer', piece_justificative_file: file } } end avis_without_answer.reload end @@ -96,7 +96,7 @@ describe Instructeurs::AvisController, type: :controller do let(:file) { nil } let(:scan_result) { true } - subject { post :create_commentaire, params: { id: avis_without_answer.id, commentaire: { body: 'commentaire body', piece_jointe: file } } } + subject { post :create_commentaire, params: { id: avis_without_answer.id, procedure_id: procedure.id, commentaire: { body: 'commentaire body', piece_jointe: file } } } before do allow(ClamavService).to receive(:safe_file?).and_return(scan_result) @@ -131,7 +131,7 @@ describe Instructeurs::AvisController, type: :controller do before do @introduction_file = Rack::Test::UploadedFile.new("./spec/fixtures/files/piece_justificative_0.pdf", 'application/pdf') - post :create_avis, params: { id: previous_avis.id, avis: { emails: emails, introduction: intro, confidentiel: asked_confidentiel, invite_linked_dossiers: invite_linked_dossiers, introduction_file: @introduction_file } } + post :create_avis, params: { id: previous_avis.id, procedure_id: procedure.id, avis: { emails: emails, introduction: intro, confidentiel: asked_confidentiel, invite_linked_dossiers: invite_linked_dossiers, introduction_file: @introduction_file } } created_avis.reload end @@ -255,6 +255,7 @@ describe Instructeurs::AvisController, type: :controller do describe '#sign_up' do let(:invited_email) { 'invited@avis.com' } let(:dossier) { create(:dossier) } + let(:procedure) { dossier.procedure } let!(:avis) { create(:avis, email: invited_email, dossier: dossier) } let(:invitations_email) { true } @@ -263,7 +264,7 @@ describe Instructeurs::AvisController, type: :controller do expect(Avis).to receive(:avis_exists_and_email_belongs_to_avis?) .with(avis.id.to_s, invited_email) .and_return(invitations_email) - get :sign_up, params: { id: avis.id, email: invited_email } + get :sign_up, params: { id: avis.id, procedure_id: procedure.id, email: invited_email } end context 'when the email belongs to the invitation' do @@ -286,7 +287,7 @@ describe Instructeurs::AvisController, type: :controller do context 'when the instructeur is authenticated' do before do sign_in(instructeur.user) - get :sign_up, params: { id: avis.id, email: invited_email } + get :sign_up, params: { id: avis.id, procedure_id: procedure.id, email: invited_email } end it { is_expected.to redirect_to instructeur_avis_url(avis) } @@ -294,7 +295,7 @@ describe Instructeurs::AvisController, type: :controller do context 'when the instructeur is not authenticated' do before do - get :sign_up, params: { id: avis.id, email: invited_email } + get :sign_up, params: { id: avis.id, procedure_id: procedure.id, email: invited_email } end it { is_expected.to redirect_to new_user_session_url } @@ -307,7 +308,7 @@ describe Instructeurs::AvisController, type: :controller do before do sign_in(instructeur.user) - get :sign_up, params: { id: avis.id, email: invited_email } + get :sign_up, params: { id: avis.id, procedure_id: procedure.id, email: invited_email } end # redirected to dossier but then the instructeur gonna be banished ! @@ -320,6 +321,7 @@ describe Instructeurs::AvisController, type: :controller do let!(:existing_user) { create(:user, email: existing_user_mail) } let(:invited_email) { 'invited@avis.com' } let(:dossier) { create(:dossier) } + let(:procedure) { dossier.procedure } let!(:avis) { create(:avis, email: invited_email, dossier: dossier) } let(:avis_id) { avis.id } let(:password) { 'démarches-simplifiées-pwd' } @@ -334,6 +336,7 @@ describe Instructeurs::AvisController, type: :controller do post :create_instructeur, params: { id: avis_id, + procedure_id: procedure.id, email: invited_email, user: { password: password From 72d27ffdb2e99908c265244a176c94f7dc985ec9 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Thu, 16 Apr 2020 17:52:58 +0200 Subject: [PATCH 04/18] replace instructeur_avis_index url by instructeur_all_avis url --- app/controllers/instructeurs/avis_controller.rb | 2 +- app/controllers/instructeurs/procedures_controller.rb | 2 +- app/views/instructeurs/avis/_header.html.haml | 2 +- app/views/instructeurs/avis/index.html.haml | 4 ++-- app/views/layouts/_new_header.haml | 2 +- config/routes.rb | 1 + spec/controllers/instructeurs/avis_controller_spec.rb | 2 +- spec/controllers/instructeurs/procedures_controller_spec.rb | 2 +- 8 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/controllers/instructeurs/avis_controller.rb b/app/controllers/instructeurs/avis_controller.rb index e85e301f1..578ae1505 100644 --- a/app/controllers/instructeurs/avis_controller.rb +++ b/app/controllers/instructeurs/avis_controller.rb @@ -99,7 +99,7 @@ module Instructeurs sign_in(user) Avis.link_avis_to_instructeur(user.instructeur) - redirect_to url_for(instructeur_avis_index_path) + redirect_to url_for(instructeur_all_avis_path) else flash[:alert] = user.errors.full_messages redirect_to url_for(sign_up_instructeur_avis_path(params[:id], email)) diff --git a/app/controllers/instructeurs/procedures_controller.rb b/app/controllers/instructeurs/procedures_controller.rb index c5c7e948b..68e01c1b0 100644 --- a/app/controllers/instructeurs/procedures_controller.rb +++ b/app/controllers/instructeurs/procedures_controller.rb @@ -284,7 +284,7 @@ module Instructeurs def redirect_to_avis_if_needed if current_instructeur.procedures.count == 0 && current_instructeur.avis.count > 0 - redirect_to instructeur_avis_index_path + redirect_to instructeur_all_avis_path end end diff --git a/app/views/instructeurs/avis/_header.html.haml b/app/views/instructeurs/avis/_header.html.haml index f0bfcd50d..8f0e601a8 100644 --- a/app/views/instructeurs/avis/_header.html.haml +++ b/app/views/instructeurs/avis/_header.html.haml @@ -1,7 +1,7 @@ .sub-header .container %ul.breadcrumbs - %li= link_to('Avis', instructeur_avis_index_path) + %li= link_to('Avis', instructeur_all_avis_path) %li= "#{dossier.procedure.libelle}, dossier nº #{dossier.id}" %ul.tabs diff --git a/app/views/instructeurs/avis/index.html.haml b/app/views/instructeurs/avis/index.html.haml index 329995b7d..cf1232d47 100644 --- a/app/views/instructeurs/avis/index.html.haml +++ b/app/views/instructeurs/avis/index.html.haml @@ -7,13 +7,13 @@ %h1.tab-title Avis %ul.tabs = tab_item('avis à donner', - instructeur_avis_index_path(statut: Instructeurs::AvisController::A_DONNER_STATUS), + instructeur_all_avis_path(statut: Instructeurs::AvisController::A_DONNER_STATUS), active: @statut == Instructeurs::AvisController::A_DONNER_STATUS, badge: @avis_a_donner.count, notification: @avis_a_donner.any?) = tab_item("avis #{'donné'.pluralize(@avis_donnes.count)}", - instructeur_avis_index_path(statut: Instructeurs::AvisController::DONNES_STATUS), + instructeur_all_avis_path(statut: Instructeurs::AvisController::DONNES_STATUS), active: @statut == Instructeurs::AvisController::DONNES_STATUS, badge: @avis_donnes.count) diff --git a/app/views/layouts/_new_header.haml b/app/views/layouts/_new_header.haml index 02cd3e321..31497d84a 100644 --- a/app/views/layouts/_new_header.haml +++ b/app/views/layouts/_new_header.haml @@ -32,7 +32,7 @@ = active_link_to "Démarches", instructeur_procedures_path, active: :inclusive, class: 'tab-link' - if current_instructeur.avis.count > 0 %li - = active_link_to instructeur_avis_index_path, active: :inclusive, class: 'tab-link' do + = active_link_to instructeur_all_avis_path, active: :inclusive, class: 'tab-link' do Avis - avis_counter = current_instructeur.avis.without_answer.count - if avis_counter > 0 diff --git a/config/routes.rb b/config/routes.rb index f33c91bd2..75f669a41 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -300,6 +300,7 @@ Rails.application.routes.draw do # scope module: 'instructeurs', as: 'instructeur' do + get 'avis', to: 'avis#all', as: 'all_avis' resources :procedures, only: [:index, :show], param: :procedure_id do member do resources :groupes, only: [:index, :show], controller: 'groupe_instructeurs' do diff --git a/spec/controllers/instructeurs/avis_controller_spec.rb b/spec/controllers/instructeurs/avis_controller_spec.rb index aeef6fff9..581244e38 100644 --- a/spec/controllers/instructeurs/avis_controller_spec.rb +++ b/spec/controllers/instructeurs/avis_controller_spec.rb @@ -358,7 +358,7 @@ describe Instructeurs::AvisController, type: :controller do it { expect(Avis).to have_received(:link_avis_to_instructeur) } it { expect(subject.current_instructeur).to eq(created_instructeur) } - it { is_expected.to redirect_to instructeur_avis_index_path } + it { is_expected.to redirect_to instructeur_all_avis_path } it 'creates a corresponding user account for the email' do user = User.find_by(email: invited_email) diff --git a/spec/controllers/instructeurs/procedures_controller_spec.rb b/spec/controllers/instructeurs/procedures_controller_spec.rb index 9b91ed178..f48b9df44 100644 --- a/spec/controllers/instructeurs/procedures_controller_spec.rb +++ b/spec/controllers/instructeurs/procedures_controller_spec.rb @@ -76,7 +76,7 @@ describe Instructeurs::ProceduresController, type: :controller do end it "redirects avis" do - expect(@controller).to have_received(:redirect_to).with(instructeur_avis_index_path) + expect(@controller).to have_received(:redirect_to).with(instructeur_all_avis_path) end end end From 83fba55b2996eeaeb5849827d14323a79c85d81c Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Mon, 20 Apr 2020 14:47:24 +0200 Subject: [PATCH 05/18] refactor instruction_instructeur_avis_url --- app/controllers/instructeurs/avis_controller.rb | 4 ++-- app/models/avis.rb | 4 ++++ app/views/instructeurs/avis/_header.html.haml | 2 +- spec/controllers/instructeurs/avis_controller_spec.rb | 6 +++--- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/controllers/instructeurs/avis_controller.rb b/app/controllers/instructeurs/avis_controller.rb index 578ae1505..c5750f325 100644 --- a/app/controllers/instructeurs/avis_controller.rb +++ b/app/controllers/instructeurs/avis_controller.rb @@ -37,7 +37,7 @@ module Instructeurs def update if @avis.update(avis_params) flash.notice = 'Votre réponse est enregistrée.' - redirect_to instruction_instructeur_avis_path(@avis) + redirect_to instruction_instructeur_avis_path(@avis.procedure, @avis) else flash.now.alert = @avis.errors.full_messages @new_avis = Avis.new @@ -65,7 +65,7 @@ module Instructeurs @new_avis = create_avis_from_params(avis.dossier, avis.confidentiel) if @new_avis.nil? - redirect_to instruction_instructeur_avis_path(avis) + redirect_to instruction_instructeur_avis_path(avis.procedure, avis) else set_avis_and_dossier render :instruction diff --git a/app/models/avis.rb b/app/models/avis.rb index bf468b96a..7deb2cd6e 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -52,6 +52,10 @@ class Avis < ApplicationRecord ] end + def procedure + dossier.procedure + end + private def try_to_assign_instructeur diff --git a/app/views/instructeurs/avis/_header.html.haml b/app/views/instructeurs/avis/_header.html.haml index 8f0e601a8..c5208f982 100644 --- a/app/views/instructeurs/avis/_header.html.haml +++ b/app/views/instructeurs/avis/_header.html.haml @@ -6,5 +6,5 @@ %ul.tabs = dynamic_tab_item('Demande', instructeur_avis_path(avis)) - = dynamic_tab_item('Avis', instruction_instructeur_avis_path(avis), notification: avis.answer.blank?) + = dynamic_tab_item('Avis', instruction_instructeur_avis_path(avis.procedure, avis), notification: avis.answer.blank?) = dynamic_tab_item('Messagerie', messagerie_instructeur_avis_path(avis)) diff --git a/spec/controllers/instructeurs/avis_controller_spec.rb b/spec/controllers/instructeurs/avis_controller_spec.rb index 581244e38..87e2ba701 100644 --- a/spec/controllers/instructeurs/avis_controller_spec.rb +++ b/spec/controllers/instructeurs/avis_controller_spec.rb @@ -64,7 +64,7 @@ describe Instructeurs::AvisController, type: :controller do end it 'should be ok' do - expect(response).to redirect_to(instruction_instructeur_avis_path(avis_without_answer)) + expect(response).to redirect_to(instruction_instructeur_avis_path(avis_without_answer.procedure, avis_without_answer)) expect(avis_without_answer.answer).to eq('answer') expect(avis_without_answer.piece_justificative_file).to_not be_attached expect(flash.notice).to eq('Votre réponse est enregistrée.') @@ -84,7 +84,7 @@ describe Instructeurs::AvisController, type: :controller do end it 'should be ok' do - expect(response).to redirect_to(instruction_instructeur_avis_path(avis_without_answer)) + expect(response).to redirect_to(instruction_instructeur_avis_path(avis_without_answer.procedure, avis_without_answer)) expect(avis_without_answer.answer).to eq('answer') expect(avis_without_answer.piece_justificative_file).to be_attached expect(flash.notice).to eq('Votre réponse est enregistrée.') @@ -178,7 +178,7 @@ describe Instructeurs::AvisController, type: :controller do it { expect(created_avis.introduction).to eq(intro) } it { expect(created_avis.dossier).to eq(previous_avis.dossier) } it { expect(created_avis.claimant).to eq(instructeur) } - it { expect(response).to redirect_to(instruction_instructeur_avis_path(previous_avis)) } + it { expect(response).to redirect_to(instruction_instructeur_avis_path(previous_avis.procedure, previous_avis)) } end context 'when the user asked for a confidentiel avis' do From b0cfb2c02ab80f8e5aa1750e2eeedec514c66788 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Mon, 20 Apr 2020 15:05:36 +0200 Subject: [PATCH 06/18] refactor messagerie_instructeur_avis_url --- app/controllers/instructeurs/avis_controller.rb | 2 +- app/views/instructeurs/avis/_header.html.haml | 2 +- spec/controllers/instructeurs/avis_controller_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/instructeurs/avis_controller.rb b/app/controllers/instructeurs/avis_controller.rb index c5750f325..54081180b 100644 --- a/app/controllers/instructeurs/avis_controller.rb +++ b/app/controllers/instructeurs/avis_controller.rb @@ -54,7 +54,7 @@ module Instructeurs if @commentaire.save flash.notice = "Message envoyé" - redirect_to messagerie_instructeur_avis_path(avis) + redirect_to messagerie_instructeur_avis_path(avis.procedure, avis) else flash.alert = @commentaire.errors.full_messages render :messagerie diff --git a/app/views/instructeurs/avis/_header.html.haml b/app/views/instructeurs/avis/_header.html.haml index c5208f982..febb8e8b2 100644 --- a/app/views/instructeurs/avis/_header.html.haml +++ b/app/views/instructeurs/avis/_header.html.haml @@ -7,4 +7,4 @@ %ul.tabs = dynamic_tab_item('Demande', instructeur_avis_path(avis)) = dynamic_tab_item('Avis', instruction_instructeur_avis_path(avis.procedure, avis), notification: avis.answer.blank?) - = dynamic_tab_item('Messagerie', messagerie_instructeur_avis_path(avis)) + = dynamic_tab_item('Messagerie', messagerie_instructeur_avis_path(avis.procedure, avis)) diff --git a/spec/controllers/instructeurs/avis_controller_spec.rb b/spec/controllers/instructeurs/avis_controller_spec.rb index 87e2ba701..cbcc3579d 100644 --- a/spec/controllers/instructeurs/avis_controller_spec.rb +++ b/spec/controllers/instructeurs/avis_controller_spec.rb @@ -105,7 +105,7 @@ describe Instructeurs::AvisController, type: :controller do it do subject - expect(response).to redirect_to(messagerie_instructeur_avis_path(avis_without_answer)) + expect(response).to redirect_to(messagerie_instructeur_avis_path(avis_without_answer.procedure, avis_without_answer)) expect(dossier.commentaires.map(&:body)).to match(['commentaire body']) end From 4839506374e568a77c417dd82042b873417043e3 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Wed, 20 May 2020 16:32:06 +0200 Subject: [PATCH 07/18] refactor instructeur_avis_url --- app/controllers/instructeurs/avis_controller.rb | 2 +- app/helpers/dossier_link_helper.rb | 2 +- app/views/avis_mailer/avis_invitation.html.haml | 4 ++-- app/views/instructeurs/avis/_header.html.haml | 2 +- app/views/instructeurs/avis/index.html.haml | 6 +++--- app/views/instructeurs/avis/instruction.html.haml | 4 ++-- spec/controllers/instructeurs/avis_controller_spec.rb | 4 ++-- spec/helpers/dossier_link_helper_spec.rb | 2 +- spec/mailers/avis_mailer_spec.rb | 2 +- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/controllers/instructeurs/avis_controller.rb b/app/controllers/instructeurs/avis_controller.rb index 54081180b..4f6df0866 100644 --- a/app/controllers/instructeurs/avis_controller.rb +++ b/app/controllers/instructeurs/avis_controller.rb @@ -119,7 +119,7 @@ module Instructeurs if current_instructeur.present? # a instructeur is authenticated ... lets see if it can view the dossier - redirect_to instructeur_avis_url(avis) + redirect_to instructeur_avis_url(avis.procedure, avis) elsif avis.instructeur&.email == params[:email] # the avis instructeur has already signed up and it sould sign in diff --git a/app/helpers/dossier_link_helper.rb b/app/helpers/dossier_link_helper.rb index 93c9d9c16..8c356e925 100644 --- a/app/helpers/dossier_link_helper.rb +++ b/app/helpers/dossier_link_helper.rb @@ -6,7 +6,7 @@ module DossierLinkHelper else avis = dossier.avis.find_by(instructeur: user) if avis.present? - instructeur_avis_path(avis) + instructeur_avis_path(avis.procedure, avis) end end elsif user.owns_or_invite?(dossier) diff --git a/app/views/avis_mailer/avis_invitation.html.haml b/app/views/avis_mailer/avis_invitation.html.haml index c0f3f4272..c1c8381d5 100644 --- a/app/views/avis_mailer/avis_invitation.html.haml +++ b/app/views/avis_mailer/avis_invitation.html.haml @@ -1,5 +1,5 @@ - content_for(:title, 'Invitation à donner votre avis') -- avis_link = @avis.instructeur.present? ? instructeur_avis_url(@avis) : sign_up_instructeur_avis_url(@avis.id, @avis.email) +- avis_link = @avis.instructeur.present? ? instructeur_avis_url(@avis.procedure, @avis) : sign_up_instructeur_avis_url(@avis.id, @avis.email) - content_for(:footer) do Merci de ne pas répondre à cet email. Donnez votre avis @@ -15,7 +15,7 @@ Vous avez été invité par %strong= @avis.claimant.email = "à donner votre avis sur le dossier nº #{@avis.dossier.id} de la démarche :" - %strong= @avis.dossier.procedure.libelle + %strong= @avis.procedure.libelle %p = "#{@avis.claimant.email} vous a écrit :" diff --git a/app/views/instructeurs/avis/_header.html.haml b/app/views/instructeurs/avis/_header.html.haml index febb8e8b2..85830909c 100644 --- a/app/views/instructeurs/avis/_header.html.haml +++ b/app/views/instructeurs/avis/_header.html.haml @@ -5,6 +5,6 @@ %li= "#{dossier.procedure.libelle}, dossier nº #{dossier.id}" %ul.tabs - = dynamic_tab_item('Demande', instructeur_avis_path(avis)) + = dynamic_tab_item('Demande', instructeur_avis_path(avis.procedure, avis)) = dynamic_tab_item('Avis', instruction_instructeur_avis_path(avis.procedure, avis), notification: avis.answer.blank?) = dynamic_tab_item('Messagerie', messagerie_instructeur_avis_path(avis.procedure, avis)) diff --git a/app/views/instructeurs/avis/index.html.haml b/app/views/instructeurs/avis/index.html.haml index cf1232d47..dddb3946b 100644 --- a/app/views/instructeurs/avis/index.html.haml +++ b/app/views/instructeurs/avis/index.html.haml @@ -29,11 +29,11 @@ - @avis.each do |avis| %tr %td.number-col - = link_to(instructeur_avis_path(avis), class: 'cell-link') do + = link_to(instructeur_avis_path(avis.procedure, avis), class: 'cell-link') do %span.icon.folder #{avis.dossier.id} - %td= link_to(avis.dossier.user.email, instructeur_avis_path(avis), class: 'cell-link') - %td= link_to(avis.dossier.procedure.libelle, instructeur_avis_path(avis), class: 'cell-link') + %td= link_to(avis.dossier.user.email, instructeur_avis_path(avis.procedure, avis), class: 'cell-link') + %td= link_to(avis.procedure.libelle, instructeur_avis_path(avis.procedure, avis), class: 'cell-link') = paginate(@avis) - else %h2.empty-text Aucun avis diff --git a/app/views/instructeurs/avis/instruction.html.haml b/app/views/instructeurs/avis/instruction.html.haml index c891620c1..1cefc6aea 100644 --- a/app/views/instructeurs/avis/instruction.html.haml +++ b/app/views/instructeurs/avis/instruction.html.haml @@ -15,7 +15,7 @@ = render partial: 'shared/attachment/show', locals: { attachment: @avis.introduction_file.attachment } %br/ - = form_for @avis, url: instructeur_avis_path(@avis), html: { class: 'form' } do |f| + = form_for @avis, url: instructeur_avis_path(@avis.procedure, @avis), html: { class: 'form' } do |f| = f.text_area :answer, rows: 3, placeholder: 'Votre avis', required: true = render 'shared/attachment/edit', { form: f, @@ -35,7 +35,7 @@ = f.submit 'Envoyer votre avis', class: 'button send' - if !@dossier.termine? - = render partial: "instructeurs/shared/avis/form", locals: { url: avis_instructeur_avis_path(@avis), linked_dossiers: @dossier.linked_dossiers_for(current_instructeur), must_be_confidentiel: @avis.confidentiel?, avis: @new_avis } + = render partial: "instructeurs/shared/avis/form", locals: { url: avis_instructeur_avis_path(@avis.procedure, @avis), linked_dossiers: @dossier.linked_dossiers_for(current_instructeur), must_be_confidentiel: @avis.confidentiel?, avis: @new_avis } - if @dossier.avis_for(current_instructeur).present? = render partial: 'instructeurs/shared/avis/list', locals: { avis: @dossier.avis_for(current_instructeur), avis_seen_at: nil } diff --git a/spec/controllers/instructeurs/avis_controller_spec.rb b/spec/controllers/instructeurs/avis_controller_spec.rb index cbcc3579d..b62173e13 100644 --- a/spec/controllers/instructeurs/avis_controller_spec.rb +++ b/spec/controllers/instructeurs/avis_controller_spec.rb @@ -290,7 +290,7 @@ describe Instructeurs::AvisController, type: :controller do get :sign_up, params: { id: avis.id, procedure_id: procedure.id, email: invited_email } end - it { is_expected.to redirect_to instructeur_avis_url(avis) } + it { is_expected.to redirect_to instructeur_avis_url(avis.procedure, avis) } end context 'when the instructeur is not authenticated' do @@ -312,7 +312,7 @@ describe Instructeurs::AvisController, type: :controller do end # redirected to dossier but then the instructeur gonna be banished ! - it { is_expected.to redirect_to instructeur_avis_url(avis) } + it { is_expected.to redirect_to instructeur_avis_url(avis.procedure, avis) } end end diff --git a/spec/helpers/dossier_link_helper_spec.rb b/spec/helpers/dossier_link_helper_spec.rb index 7b43b37ec..c8f04fab1 100644 --- a/spec/helpers/dossier_link_helper_spec.rb +++ b/spec/helpers/dossier_link_helper_spec.rb @@ -29,7 +29,7 @@ describe DossierLinkHelper do let(:instructeur) { create(:instructeur) } let!(:avis) { create(:avis, dossier: dossier, instructeur: instructeur) } - it { expect(helper.dossier_linked_path(instructeur, dossier)).to eq(instructeur_avis_path(avis)) } + it { expect(helper.dossier_linked_path(instructeur, dossier)).to eq(instructeur_avis_path(avis.dossier.procedure, avis)) } end context "when access as user" do diff --git a/spec/mailers/avis_mailer_spec.rb b/spec/mailers/avis_mailer_spec.rb index ff9f5bd7d..75b61d27b 100644 --- a/spec/mailers/avis_mailer_spec.rb +++ b/spec/mailers/avis_mailer_spec.rb @@ -7,7 +7,7 @@ RSpec.describe AvisMailer, type: :mailer do it { expect(subject.subject).to eq("Donnez votre avis sur le dossier nº #{avis.dossier.id} (#{avis.dossier.procedure.libelle})") } it { expect(subject.body).to have_text("Vous avez été invité par\r\n#{avis.claimant.email}\r\nà donner votre avis sur le dossier nº #{avis.dossier.id} de la démarche :\r\n#{avis.dossier.procedure.libelle}") } it { expect(subject.body).to include(avis.introduction) } - it { expect(subject.body).to include(instructeur_avis_url(avis)) } + it { expect(subject.body).to include(instructeur_avis_url(avis.dossier.procedure.id, avis)) } context 'when the recipient is not already registered' do before do From b0aa005769bf83bee879e4d91f8b4afa82118748 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Wed, 20 May 2020 16:53:38 +0200 Subject: [PATCH 08/18] remove dead code --- spec/features/instructeurs/instruction_spec.rb | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/spec/features/instructeurs/instruction_spec.rb b/spec/features/instructeurs/instruction_spec.rb index 017942f90..2b03cfa8c 100644 --- a/spec/features/instructeurs/instruction_spec.rb +++ b/spec/features/instructeurs/instruction_spec.rb @@ -159,12 +159,6 @@ feature 'Instructing a dossier:' do click_on 'Demander un avis' end - def test_mail(to, content) - mail = ActionMailer::Base.deliveries.last - expect(mail.to).to match([to]) - expect(mail.body.parts.map(&:to_s)).to all(include(content)) - end - def test_statut_bar(a_suivre: 0, suivi: 0, traite: 0, tous_les_dossiers: 0, archive: 0) texts = [ "à suivre #{a_suivre}", @@ -177,13 +171,6 @@ feature 'Instructing a dossier:' do texts.each { |text| expect(page).to have_text(text) } end - def avis_sign_up(avis, email) - visit sign_up_instructeur_avis_path(avis, email) - fill_in 'user_password', with: 'démarches-simplifiées-pwd' - click_on 'Créer un compte' - expect(page).to have_current_path(instructeur_avis_index_path) - end - def dossier_present?(id, statut) within(:css, '.dossiers-table') do expect(page).to have_text(id) From c565c9c87ba3cbe1f8e773f3663d2292b90f628e Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Wed, 20 May 2020 17:17:39 +0200 Subject: [PATCH 09/18] refactor sign_up_instructeur_avis_url --- app/controllers/instructeurs/avis_controller.rb | 4 +++- app/views/avis_mailer/avis_invitation.html.haml | 2 +- spec/controllers/instructeurs/avis_controller_spec.rb | 2 +- spec/features/instructeurs/expert_spec.rb | 6 +++--- spec/mailers/avis_mailer_spec.rb | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/controllers/instructeurs/avis_controller.rb b/app/controllers/instructeurs/avis_controller.rb index 4f6df0866..15a12cb32 100644 --- a/app/controllers/instructeurs/avis_controller.rb +++ b/app/controllers/instructeurs/avis_controller.rb @@ -89,6 +89,8 @@ module Instructeurs end def create_instructeur + procedure_id = params[:procedure_id] + avis_id = params[:id] email = params[:email] password = params[:user][:password] @@ -102,7 +104,7 @@ module Instructeurs redirect_to url_for(instructeur_all_avis_path) else flash[:alert] = user.errors.full_messages - redirect_to url_for(sign_up_instructeur_avis_path(params[:id], email)) + redirect_to url_for(sign_up_instructeur_avis_path(procedure_id, avis_id, email)) end end diff --git a/app/views/avis_mailer/avis_invitation.html.haml b/app/views/avis_mailer/avis_invitation.html.haml index c1c8381d5..31a4ca6d7 100644 --- a/app/views/avis_mailer/avis_invitation.html.haml +++ b/app/views/avis_mailer/avis_invitation.html.haml @@ -1,5 +1,5 @@ - content_for(:title, 'Invitation à donner votre avis') -- avis_link = @avis.instructeur.present? ? instructeur_avis_url(@avis.procedure, @avis) : sign_up_instructeur_avis_url(@avis.id, @avis.email) +- avis_link = @avis.instructeur.present? ? instructeur_avis_url(@avis.procedure, @avis) : sign_up_instructeur_avis_url(@avis.procedure, @avis.id, @avis.email) - content_for(:footer) do Merci de ne pas répondre à cet email. Donnez votre avis diff --git a/spec/controllers/instructeurs/avis_controller_spec.rb b/spec/controllers/instructeurs/avis_controller_spec.rb index b62173e13..1ae9002f3 100644 --- a/spec/controllers/instructeurs/avis_controller_spec.rb +++ b/spec/controllers/instructeurs/avis_controller_spec.rb @@ -378,7 +378,7 @@ describe Instructeurs::AvisController, type: :controller do let(:password) { '' } it { expect(created_instructeur).to be_nil } - it { is_expected.to redirect_to sign_up_instructeur_avis_path(avis_id, invited_email) } + it { is_expected.to redirect_to sign_up_instructeur_avis_path(procedure.id, avis_id, invited_email) } it { expect(flash.alert).to eq(['Le mot de passe doit être rempli']) } end end diff --git a/spec/features/instructeurs/expert_spec.rb b/spec/features/instructeurs/expert_spec.rb index aa3ebf0b8..fb5d021e7 100644 --- a/spec/features/instructeurs/expert_spec.rb +++ b/spec/features/instructeurs/expert_spec.rb @@ -42,7 +42,7 @@ feature 'Inviting an expert:' do invitation_email = open_email('expert2@exemple.fr') avis = Avis.find_by(email: 'expert2@exemple.fr', dossier: dossier) - sign_up_link = sign_up_instructeur_avis_path(avis.id, avis.email) + sign_up_link = sign_up_instructeur_avis_path(avis.dossier.procedure, avis, avis.email) expect(invitation_email.body).to include(sign_up_link) end @@ -71,7 +71,7 @@ feature 'Inviting an expert:' do let(:avis_email) { 'not-signed-up-expert@exemple.fr' } scenario 'I can sign up' do - visit sign_up_instructeur_avis_path(avis.id, avis_email) + visit sign_up_instructeur_avis_path(avis.dossier.procedure, avis, avis_email) expect(page).to have_field('Email', with: avis_email, disabled: true) fill_in 'Mot de passe', with: 'This is a very complicated password !' @@ -86,7 +86,7 @@ feature 'Inviting an expert:' do let(:avis_email) { expert.email } scenario 'I can sign in' do - visit sign_up_instructeur_avis_path(avis.id, avis_email) + visit sign_up_instructeur_avis_path(avis.dossier.procedure, avis, avis_email) expect(page).to have_current_path(new_user_session_path) sign_in_with(expert.email, expert_password) diff --git a/spec/mailers/avis_mailer_spec.rb b/spec/mailers/avis_mailer_spec.rb index 75b61d27b..163e77205 100644 --- a/spec/mailers/avis_mailer_spec.rb +++ b/spec/mailers/avis_mailer_spec.rb @@ -15,7 +15,7 @@ RSpec.describe AvisMailer, type: :mailer do avis.instructeur = nil end - it { expect(subject.body).to include(sign_up_instructeur_avis_url(avis.id, avis.email)) } + it { expect(subject.body).to include(sign_up_instructeur_avis_url(avis.dossier.procedure.id, avis.id, avis.email)) } end end end From 29e2d3d7eb239ba071658fe971d4c8b63fb01c1f Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Wed, 24 Jun 2020 22:25:10 +0200 Subject: [PATCH 10/18] display all avis for a procedure for an expert --- .../instructeurs/avis_controller.rb | 3 +- app/views/instructeurs/avis/_header.html.haml | 3 +- app/views/instructeurs/avis/index.html.haml | 34 +++++++++++-------- .../instructeurs/avis_controller_spec.rb | 10 +++--- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/app/controllers/instructeurs/avis_controller.rb b/app/controllers/instructeurs/avis_controller.rb index 15a12cb32..98735f751 100644 --- a/app/controllers/instructeurs/avis_controller.rb +++ b/app/controllers/instructeurs/avis_controller.rb @@ -11,7 +11,8 @@ module Instructeurs DONNES_STATUS = 'donnes' def index - instructeur_avis = current_instructeur.avis.includes(dossier: [:procedure, :user]) + @procedure = Procedure.find(params[:procedure_id]) + instructeur_avis = current_instructeur.avis.includes(:dossier).where(dossiers: { groupe_instructeur: GroupeInstructeur.where(procedure: @procedure.id) }) @avis_a_donner = instructeur_avis.without_answer @avis_donnes = instructeur_avis.with_answer diff --git a/app/views/instructeurs/avis/_header.html.haml b/app/views/instructeurs/avis/_header.html.haml index 85830909c..59458b904 100644 --- a/app/views/instructeurs/avis/_header.html.haml +++ b/app/views/instructeurs/avis/_header.html.haml @@ -2,7 +2,8 @@ .container %ul.breadcrumbs %li= link_to('Avis', instructeur_all_avis_path) - %li= "#{dossier.procedure.libelle}, dossier nº #{dossier.id}" + %li= link_to(dossier.procedure.libelle, instructeur_avis_index_path(avis.procedure)) + %li= link_to("Dossier nº #{dossier.id}", instructeur_avis_path(avis.procedure, avis)) %ul.tabs = dynamic_tab_item('Demande', instructeur_avis_path(avis.procedure, avis)) diff --git a/app/views/instructeurs/avis/index.html.haml b/app/views/instructeurs/avis/index.html.haml index dddb3946b..76e473be3 100644 --- a/app/views/instructeurs/avis/index.html.haml +++ b/app/views/instructeurs/avis/index.html.haml @@ -1,21 +1,27 @@ - avis_statut = (@statut == Instructeurs::AvisController::A_DONNER_STATUS) ? 'à donner' : 'rendus' - content_for(:title, "Avis #{avis_statut}") -.sub-header - .container.flex - .width-100 - %h1.tab-title Avis - %ul.tabs - = tab_item('avis à donner', - instructeur_all_avis_path(statut: Instructeurs::AvisController::A_DONNER_STATUS), - active: @statut == Instructeurs::AvisController::A_DONNER_STATUS, - badge: @avis_a_donner.count, - notification: @avis_a_donner.any?) +#procedure-show + .sub-header + .container.flex - = tab_item("avis #{'donné'.pluralize(@avis_donnes.count)}", - instructeur_all_avis_path(statut: Instructeurs::AvisController::DONNES_STATUS), - active: @statut == Instructeurs::AvisController::DONNES_STATUS, - badge: @avis_donnes.count) + .procedure-logo{ style: "background-image: url(#{@procedure.logo_url})", + role: 'img', 'aria-label': "logo de la démarche #{@procedure.libelle}" } + + .procedure-header + %h1= procedure_libelle @procedure + + %ul.tabs + = tab_item('avis à donner', + instructeur_avis_index_path(statut: Instructeurs::AvisController::A_DONNER_STATUS), + active: @statut == Instructeurs::AvisController::A_DONNER_STATUS, + badge: @avis_a_donner.count, + notification: @avis_a_donner.any?) + + = tab_item("avis #{'donné'.pluralize(@avis_donnes.count)}", + instructeur_avis_index_path(statut: Instructeurs::AvisController::DONNES_STATUS), + active: @statut == Instructeurs::AvisController::DONNES_STATUS, + badge: @avis_donnes.count) .container - if @avis.present? diff --git a/spec/controllers/instructeurs/avis_controller_spec.rb b/spec/controllers/instructeurs/avis_controller_spec.rb index 1ae9002f3..f8bcad65d 100644 --- a/spec/controllers/instructeurs/avis_controller_spec.rb +++ b/spec/controllers/instructeurs/avis_controller_spec.rb @@ -14,15 +14,15 @@ describe Instructeurs::AvisController, type: :controller do describe '#index' do before { get :index, params: { procedure_id: procedure.id } } - xit { expect(response).to have_http_status(:success) } - xit { expect(assigns(:avis_a_donner)).to match([avis_without_answer]) } - xit { expect(assigns(:avis_donnes)).to match([avis_with_answer]) } - xit { expect(assigns(:statut)).to eq('a-donner') } + it { expect(response).to have_http_status(:success) } + it { expect(assigns(:avis_a_donner)).to match([avis_without_answer]) } + it { expect(assigns(:avis_donnes)).to match([avis_with_answer]) } + it { expect(assigns(:statut)).to eq('a-donner') } context 'with a statut equal to donnes' do before { get :index, params: { statut: 'donnes', procedure_id: procedure.id } } - xit { expect(assigns(:statut)).to eq('donnes') } + it { expect(assigns(:statut)).to eq('donnes') } end end From 63dd71aed494565728076f07ecf0de7ad1399af5 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Thu, 25 Jun 2020 10:05:39 +0200 Subject: [PATCH 11/18] display all avis for an expert --- .../instructeurs/avis_controller.rb | 5 +++ app/views/instructeurs/avis/all.html.haml | 41 +++++++++++++++++++ .../instructeurs/avis_controller_spec.rb | 9 ++++ spec/features/instructeurs/expert_spec.rb | 19 +++++---- 4 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 app/views/instructeurs/avis/all.html.haml diff --git a/app/controllers/instructeurs/avis_controller.rb b/app/controllers/instructeurs/avis_controller.rb index 98735f751..97f762cb9 100644 --- a/app/controllers/instructeurs/avis_controller.rb +++ b/app/controllers/instructeurs/avis_controller.rb @@ -10,6 +10,11 @@ module Instructeurs A_DONNER_STATUS = 'a-donner' DONNES_STATUS = 'donnes' + def all + avis = current_instructeur.avis.includes(dossier: [groupe_instructeur: :procedure]) + @avis_by_procedure = avis.to_a.group_by(&:procedure) + end + def index @procedure = Procedure.find(params[:procedure_id]) instructeur_avis = current_instructeur.avis.includes(:dossier).where(dossiers: { groupe_instructeur: GroupeInstructeur.where(procedure: @procedure.id) }) diff --git a/app/views/instructeurs/avis/all.html.haml b/app/views/instructeurs/avis/all.html.haml new file mode 100644 index 000000000..fdb91650d --- /dev/null +++ b/app/views/instructeurs/avis/all.html.haml @@ -0,0 +1,41 @@ +- content_for(:title, "Avis") + +.container + %h1.page-title Avis + + %ul.procedure-list + - @avis_by_procedure.each do |p, procedure_avis| + %li.procedure-item.flex.align-start + = link_to(instructeur_avis_index_path(p)) do + .flex + + .procedure-logo{ style: "background-image: url(#{p.logo_url})" } + + .procedure-details + %p.procedure-title + = procedure_libelle p + %ul.procedure-stats.flex + %li + %object + = link_to(instructeur_avis_index_path(p, statut: Instructeurs::AvisController::A_DONNER_STATUS)) do + - without_answer_count = procedure_avis.select { |a| a.answer.nil? }.size + - if without_answer_count > 0 + %span.notifications{ 'aria-label': "notifications" } + .stats-number + = without_answer_count + .stats-legend + avis à donner + %li + %object + = link_to(instructeur_avis_index_path(p, statut: Instructeurs::AvisController::DONNES_STATUS)) do + - with_answer_count = procedure_avis.select { |a| a.answer.present? }.size + .stats-number= with_answer_count + .stats-legend + = pluralize(with_answer_count, "avis donné") + + - if p.close? + .procedure-status + %span.label Close + - elsif p.depubliee? + .procedure-status + %span.label Dépubliée diff --git a/spec/controllers/instructeurs/avis_controller_spec.rb b/spec/controllers/instructeurs/avis_controller_spec.rb index f8bcad65d..4eb5682a3 100644 --- a/spec/controllers/instructeurs/avis_controller_spec.rb +++ b/spec/controllers/instructeurs/avis_controller_spec.rb @@ -5,12 +5,21 @@ describe Instructeurs::AvisController, type: :controller do let(:claimant) { create(:instructeur) } let(:instructeur) { create(:instructeur) } let(:procedure) { create(:procedure, :published, instructeurs: [claimant]) } + let(:another_procedure) { create(:procedure, :published, instructeurs: [claimant]) } let(:dossier) { create(:dossier, :en_construction, procedure: procedure) } let!(:avis_without_answer) { Avis.create(dossier: dossier, claimant: claimant, instructeur: instructeur) } let!(:avis_with_answer) { Avis.create(dossier: dossier, claimant: claimant, instructeur: instructeur, answer: 'yop') } before { sign_in(instructeur.user) } + describe '#all' do + before { get :all } + + it { expect(response).to have_http_status(:success) } + it { expect(assigns(:avis_by_procedure).flatten).to include(procedure) } + it { expect(assigns(:avis_by_procedure).flatten).not_to include(another_procedure) } + end + describe '#index' do before { get :index, params: { procedure_id: procedure.id } } diff --git a/spec/features/instructeurs/expert_spec.rb b/spec/features/instructeurs/expert_spec.rb index fb5d021e7..c8700e5d3 100644 --- a/spec/features/instructeurs/expert_spec.rb +++ b/spec/features/instructeurs/expert_spec.rb @@ -77,8 +77,8 @@ feature 'Inviting an expert:' do fill_in 'Mot de passe', with: 'This is a very complicated password !' click_on 'Créer un compte' - expect(page).to have_current_path(instructeur_avis_index_path) - expect(page).to have_text('avis à donner 1') + expect(page).to have_current_path(instructeur_all_avis_path) + expect(page).to have_text('1 avis à donner') end end @@ -91,8 +91,8 @@ feature 'Inviting an expert:' do expect(page).to have_current_path(new_user_session_path) sign_in_with(expert.email, expert_password) - expect(page).to have_current_path(instructeur_avis_index_path) - expect(page).to have_text('avis à donner 1') + expect(page).to have_current_path(instructeur_all_avis_path) + expect(page).to have_text('1 avis à donner') end end @@ -100,10 +100,11 @@ feature 'Inviting an expert:' do avis # create avis login_as expert.user, scope: :user - visit instructeur_avis_index_path - expect(page).to have_text('avis à donner 1') - expect(page).to have_text('avis donnés 0') + visit instructeur_all_avis_path + expect(page).to have_text('1 avis à donner') + expect(page).to have_text('0 avis donnés') + click_on '1 avis à donner' click_on avis.dossier.user.email within('.tabs') { click_on 'Avis' } @@ -119,8 +120,8 @@ feature 'Inviting an expert:' do expect(page).to have_content('RIB.pdf') within('.new-header') { click_on 'Avis' } - expect(page).to have_text('avis à donner 0') - expect(page).to have_text('avis donné 1') + expect(page).to have_text('0 avis à donner') + expect(page).to have_text('1 avis donné') end # TODO From 8f2b09ae06d4a981761bcf3dedf9353e887b912f Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Thu, 25 Jun 2020 18:32:13 +0200 Subject: [PATCH 12/18] fix active_links in header --- app/views/layouts/_new_header.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/_new_header.haml b/app/views/layouts/_new_header.haml index 31497d84a..c97277397 100644 --- a/app/views/layouts/_new_header.haml +++ b/app/views/layouts/_new_header.haml @@ -29,10 +29,10 @@ %ul.header-tabs - if current_instructeur.procedures.count > 0 %li - = active_link_to "Démarches", instructeur_procedures_path, active: :inclusive, class: 'tab-link' + = active_link_to "Démarches", instructeur_procedures_path, active: /^((?!avis).)*$/, class: 'tab-link' - if current_instructeur.avis.count > 0 %li - = active_link_to instructeur_all_avis_path, active: :inclusive, class: 'tab-link' do + = active_link_to instructeur_all_avis_path, active: /avis/, class: 'tab-link' do Avis - avis_counter = current_instructeur.avis.without_answer.count - if avis_counter > 0 From 84d619c974642450d047e5a73a070a1d863a4098 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Fri, 26 Jun 2020 11:21:13 +0200 Subject: [PATCH 13/18] redirect old urls in avis mails with new urls --- config/routes.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/routes.rb b/config/routes.rb index 75f669a41..30dcd5f6c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -301,6 +301,8 @@ Rails.application.routes.draw do scope module: 'instructeurs', as: 'instructeur' do get 'avis', to: 'avis#all', as: 'all_avis' + get 'avis/:id', to: redirect('/procedures/old/avis/%{id}') + get 'avis/:id/sign_up/email/:email', to: redirect("/procedures/old/avis/%{id}/sign_up/email/%{email}"), constraints: { email: /.*/ } resources :procedures, only: [:index, :show], param: :procedure_id do member do resources :groupes, only: [:index, :show], controller: 'groupe_instructeurs' do From 90d6d337a98a5cb5ce2fcb4e25498fe284d95d25 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Fri, 26 Jun 2020 17:26:46 +0200 Subject: [PATCH 14/18] explain redirection urls for expert --- config/routes.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/routes.rb b/config/routes.rb index 30dcd5f6c..a02152cad 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -301,8 +301,12 @@ Rails.application.routes.draw do scope module: 'instructeurs', as: 'instructeur' do get 'avis', to: 'avis#all', as: 'all_avis' + + # this redirections are ephemeral, to ensure that emails sent to experts before are still valid + # TODO : they will be removed in September, 2020 get 'avis/:id', to: redirect('/procedures/old/avis/%{id}') get 'avis/:id/sign_up/email/:email', to: redirect("/procedures/old/avis/%{id}/sign_up/email/%{email}"), constraints: { email: /.*/ } + resources :procedures, only: [:index, :show], param: :procedure_id do member do resources :groupes, only: [:index, :show], controller: 'groupe_instructeurs' do From bbec76d33b02c88c7c44673abdcfd07f0c272ed7 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Fri, 26 Jun 2020 19:28:28 +0200 Subject: [PATCH 15/18] rename avis#index to avis#procedure --- app/controllers/instructeurs/avis_controller.rb | 2 +- app/views/instructeurs/avis/_header.html.haml | 2 +- app/views/instructeurs/avis/all.html.haml | 6 +++--- .../avis/{index.html.haml => procedure.html.haml} | 4 ++-- config/routes.rb | 3 ++- spec/controllers/instructeurs/avis_controller_spec.rb | 6 +++--- 6 files changed, 12 insertions(+), 11 deletions(-) rename app/views/instructeurs/avis/{index.html.haml => procedure.html.haml} (88%) diff --git a/app/controllers/instructeurs/avis_controller.rb b/app/controllers/instructeurs/avis_controller.rb index 97f762cb9..600bc983b 100644 --- a/app/controllers/instructeurs/avis_controller.rb +++ b/app/controllers/instructeurs/avis_controller.rb @@ -15,7 +15,7 @@ module Instructeurs @avis_by_procedure = avis.to_a.group_by(&:procedure) end - def index + def procedure @procedure = Procedure.find(params[:procedure_id]) instructeur_avis = current_instructeur.avis.includes(:dossier).where(dossiers: { groupe_instructeur: GroupeInstructeur.where(procedure: @procedure.id) }) @avis_a_donner = instructeur_avis.without_answer diff --git a/app/views/instructeurs/avis/_header.html.haml b/app/views/instructeurs/avis/_header.html.haml index 59458b904..0d2ab24e6 100644 --- a/app/views/instructeurs/avis/_header.html.haml +++ b/app/views/instructeurs/avis/_header.html.haml @@ -2,7 +2,7 @@ .container %ul.breadcrumbs %li= link_to('Avis', instructeur_all_avis_path) - %li= link_to(dossier.procedure.libelle, instructeur_avis_index_path(avis.procedure)) + %li= link_to(dossier.procedure.libelle, procedure_instructeur_avis_index_path(avis.procedure)) %li= link_to("Dossier nº #{dossier.id}", instructeur_avis_path(avis.procedure, avis)) %ul.tabs diff --git a/app/views/instructeurs/avis/all.html.haml b/app/views/instructeurs/avis/all.html.haml index fdb91650d..7b8838a3e 100644 --- a/app/views/instructeurs/avis/all.html.haml +++ b/app/views/instructeurs/avis/all.html.haml @@ -6,7 +6,7 @@ %ul.procedure-list - @avis_by_procedure.each do |p, procedure_avis| %li.procedure-item.flex.align-start - = link_to(instructeur_avis_index_path(p)) do + = link_to(procedure_instructeur_avis_index_path(p)) do .flex .procedure-logo{ style: "background-image: url(#{p.logo_url})" } @@ -17,7 +17,7 @@ %ul.procedure-stats.flex %li %object - = link_to(instructeur_avis_index_path(p, statut: Instructeurs::AvisController::A_DONNER_STATUS)) do + = link_to(procedure_instructeur_avis_index_path(p, statut: Instructeurs::AvisController::A_DONNER_STATUS)) do - without_answer_count = procedure_avis.select { |a| a.answer.nil? }.size - if without_answer_count > 0 %span.notifications{ 'aria-label': "notifications" } @@ -27,7 +27,7 @@ avis à donner %li %object - = link_to(instructeur_avis_index_path(p, statut: Instructeurs::AvisController::DONNES_STATUS)) do + = link_to(procedure_instructeur_avis_index_path(p, statut: Instructeurs::AvisController::DONNES_STATUS)) do - with_answer_count = procedure_avis.select { |a| a.answer.present? }.size .stats-number= with_answer_count .stats-legend diff --git a/app/views/instructeurs/avis/index.html.haml b/app/views/instructeurs/avis/procedure.html.haml similarity index 88% rename from app/views/instructeurs/avis/index.html.haml rename to app/views/instructeurs/avis/procedure.html.haml index 76e473be3..f38d6cde3 100644 --- a/app/views/instructeurs/avis/index.html.haml +++ b/app/views/instructeurs/avis/procedure.html.haml @@ -13,13 +13,13 @@ %ul.tabs = tab_item('avis à donner', - instructeur_avis_index_path(statut: Instructeurs::AvisController::A_DONNER_STATUS), + procedure_instructeur_avis_index_path(statut: Instructeurs::AvisController::A_DONNER_STATUS), active: @statut == Instructeurs::AvisController::A_DONNER_STATUS, badge: @avis_a_donner.count, notification: @avis_a_donner.any?) = tab_item("avis #{'donné'.pluralize(@avis_donnes.count)}", - instructeur_avis_index_path(statut: Instructeurs::AvisController::DONNES_STATUS), + procedure_instructeur_avis_index_path(statut: Instructeurs::AvisController::DONNES_STATUS), active: @statut == Instructeurs::AvisController::DONNES_STATUS, badge: @avis_donnes.count) diff --git a/config/routes.rb b/config/routes.rb index a02152cad..3fe255442 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -316,7 +316,8 @@ Rails.application.routes.draw do end end - resources :avis, only: [:index, :show, :update] do + resources :avis, only: [:show, :update] do + get '', action: 'procedure', on: :collection, as: :procedure member do get 'instruction' get 'messagerie' diff --git a/spec/controllers/instructeurs/avis_controller_spec.rb b/spec/controllers/instructeurs/avis_controller_spec.rb index 4eb5682a3..22687c059 100644 --- a/spec/controllers/instructeurs/avis_controller_spec.rb +++ b/spec/controllers/instructeurs/avis_controller_spec.rb @@ -20,8 +20,8 @@ describe Instructeurs::AvisController, type: :controller do it { expect(assigns(:avis_by_procedure).flatten).not_to include(another_procedure) } end - describe '#index' do - before { get :index, params: { procedure_id: procedure.id } } + describe '#procedure' do + before { get :procedure, params: { procedure_id: procedure.id } } it { expect(response).to have_http_status(:success) } it { expect(assigns(:avis_a_donner)).to match([avis_without_answer]) } @@ -29,7 +29,7 @@ describe Instructeurs::AvisController, type: :controller do it { expect(assigns(:statut)).to eq('a-donner') } context 'with a statut equal to donnes' do - before { get :index, params: { statut: 'donnes', procedure_id: procedure.id } } + before { get :procedure, params: { statut: 'donnes', procedure_id: procedure.id } } it { expect(assigns(:statut)).to eq('donnes') } end From 1d86f863d35310c38f2eb29b37a87f7cf97587ad Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Fri, 26 Jun 2020 20:02:01 +0200 Subject: [PATCH 16/18] rename avis#all to avis#index --- app/controllers/instructeurs/avis_controller.rb | 2 +- .../instructeurs/avis/{all.html.haml => index.html.haml} | 0 config/routes.rb | 2 +- spec/controllers/instructeurs/avis_controller_spec.rb | 4 ++-- 4 files changed, 4 insertions(+), 4 deletions(-) rename app/views/instructeurs/avis/{all.html.haml => index.html.haml} (100%) diff --git a/app/controllers/instructeurs/avis_controller.rb b/app/controllers/instructeurs/avis_controller.rb index 600bc983b..6382da31d 100644 --- a/app/controllers/instructeurs/avis_controller.rb +++ b/app/controllers/instructeurs/avis_controller.rb @@ -10,7 +10,7 @@ module Instructeurs A_DONNER_STATUS = 'a-donner' DONNES_STATUS = 'donnes' - def all + def index avis = current_instructeur.avis.includes(dossier: [groupe_instructeur: :procedure]) @avis_by_procedure = avis.to_a.group_by(&:procedure) end diff --git a/app/views/instructeurs/avis/all.html.haml b/app/views/instructeurs/avis/index.html.haml similarity index 100% rename from app/views/instructeurs/avis/all.html.haml rename to app/views/instructeurs/avis/index.html.haml diff --git a/config/routes.rb b/config/routes.rb index 3fe255442..67801ac80 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -300,7 +300,7 @@ Rails.application.routes.draw do # scope module: 'instructeurs', as: 'instructeur' do - get 'avis', to: 'avis#all', as: 'all_avis' + get 'avis', to: 'avis#index', as: 'all_avis' # this redirections are ephemeral, to ensure that emails sent to experts before are still valid # TODO : they will be removed in September, 2020 diff --git a/spec/controllers/instructeurs/avis_controller_spec.rb b/spec/controllers/instructeurs/avis_controller_spec.rb index 22687c059..811bc060e 100644 --- a/spec/controllers/instructeurs/avis_controller_spec.rb +++ b/spec/controllers/instructeurs/avis_controller_spec.rb @@ -12,8 +12,8 @@ describe Instructeurs::AvisController, type: :controller do before { sign_in(instructeur.user) } - describe '#all' do - before { get :all } + describe '#index' do + before { get :index } it { expect(response).to have_http_status(:success) } it { expect(assigns(:avis_by_procedure).flatten).to include(procedure) } From bc8d88af738592f23a1a84cc444f02bcb1240784 Mon Sep 17 00:00:00 2001 From: maatinito <15379878+maatinito@users.noreply.github.com> Date: Tue, 30 Jun 2020 15:09:38 -1000 Subject: [PATCH 17/18] pdf dossier: better layout for etablissement fields --- app/views/dossiers/show.pdf.prawn | 55 +++++++++++++++++-------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/app/views/dossiers/show.pdf.prawn b/app/views/dossiers/show.pdf.prawn index 366dc6fc6..b2eed9c09 100644 --- a/app/views/dossiers/show.pdf.prawn +++ b/app/views/dossiers/show.pdf.prawn @@ -8,11 +8,17 @@ def format_in_2_lines(pdf, label, text) pdf.text "\n", size: 9 end +def render_box(pdf, text, x, width) + box = ::Prawn::Text::Box.new(text, { document: pdf, width: width, overflow: :expand, at: [x, pdf.cursor] }) + box.render + box.height +end + def format_in_2_columns(pdf, label, text) - pdf.text_box label, width: 200, height: 100, overflow: :expand, at: [0, pdf.cursor] - pdf.text_box ":", width: 10, height: 100, overflow: :expand, at: [100, pdf.cursor] - pdf.text_box text, width: 420, height: 100, overflow: :expand, at: [110, pdf.cursor] - pdf.text "\n" + h1 = render_box(pdf, label, 0, 100) + h2 = render_box(pdf, ':', 100, 10) + h3 = render_box(pdf, text, 110, pdf.bounds.width - 110) + pdf.move_down 5 + [h1,h2,h3].max end def add_title(pdf, title) @@ -47,33 +53,32 @@ def render_siret_info(pdf, etablissement) end def render_identite_etablissement(pdf, etablissement) - pdf.text " - SIRET : #{etablissement.siret}" - pdf.text " - SIRET du siège social: #{etablissement.entreprise.siret_siege_social}" - pdf.text " - Dénomination : #{raison_sociale_or_name(etablissement)}" - pdf.text " - Forme juridique : #{etablissement.entreprise_forme_juridique}" + format_in_2_columns(pdf, "SIRET", etablissement.siret) + format_in_2_columns(pdf, "SIRET du siège social", etablissement.entreprise.siret_siege_social) if etablissement.entreprise.siret_siege_social.present? + format_in_2_columns(pdf, "Dénomination", raison_sociale_or_name(etablissement)) + format_in_2_columns(pdf, "Forme juridique ", etablissement.entreprise_forme_juridique) if etablissement.entreprise_capital_social.present? - pdf.text " - Capital social : #{pretty_currency(etablissement.entreprise_capital_social)}" + format_in_2_columns(pdf, "Capital social ", pretty_currency(etablissement.entreprise_capital_social)) end - pdf.text " - Libellé NAF : #{etablissement.libelle_naf}" - pdf.text " - Code NAF : #{etablissement.naf}" - pdf.text " - Date de création : #{try_format_date(etablissement.entreprise.date_creation)}" + format_in_2_columns(pdf, "Libellé NAF ", etablissement.libelle_naf) + format_in_2_columns(pdf, "Code NAF ", etablissement.naf) + format_in_2_columns(pdf, "Date de création ", try_format_date(etablissement.entreprise.date_creation)) if @include_infos_administration - pdf.text " - Effectif mensuel #{try_format_mois_effectif(etablissement)} (URSSAF) : #{etablissement.entreprise_effectif_mensuel}" - pdf.text " - Effectif moyen annuel #{etablissement.entreprise_effectif_annuel_annee} (URSSAF) : #{etablissement.entreprise_effectif_annuel}" + format_in_2_columns(pdf, "Effectif mensuel #{try_format_mois_effectif(etablissement)} (URSSAF) ", etablissement.entreprise_effectif_mensuel) + format_in_2_columns(pdf, "Effectif moyen annuel #{etablissement.entreprise_effectif_annuel_annee} (URSSAF) ", etablissement.entreprise_effectif_annuel) end - pdf.text " - Effectif de l'organisation (INSEE) : #{effectif(etablissement)}" - pdf.text " - Code effectif : #{etablissement.entreprise.code_effectif_entreprise}" - pdf.text " - Numéro de TVA intracommunautaire : #{etablissement.entreprise.numero_tva_intracommunautaire}" - pdf.text " - Adresse : #{etablissement.adresse}" + format_in_2_columns(pdf, "Effectif (ISPF) ", effectif(etablissement)) + format_in_2_columns(pdf, "Code effectif ", etablissement.entreprise.code_effectif_entreprise) + format_in_2_columns(pdf, "Numéro de TVA intracommunautaire ", etablissement.entreprise.numero_tva_intracommunautaire) if etablissement.entreprise.numero_tva_intracommunautaire.present? + format_in_2_columns(pdf, "Adresse ", etablissement.adresse) if etablissement.association? - pdf.text " - Numéro RNA : #{etablissement.association_rna}" - pdf.text " - Titre : #{etablissement.association_titre}" - pdf.text " - Objet : #{etablissement.association_objet}" - pdf.text " - Date de création : #{try_format_date(etablissement.association_date_creation)}" - pdf.text " - Date de publication : #{try_format_date(etablissement.association_date_publication)}" - pdf.text " - Date de déclaration : #{try_format_date(etablissement.association_date_declaration)}" + format_in_2_columns(pdf, "Numéro RNA ", etablissement.association_rna) + format_in_2_columns(pdf, "Titre ", etablissement.association_titre) + format_in_2_columns(pdf, "Objet ", etablissement.association_objet) + format_in_2_columns(pdf, "Date de création ", try_format_date(etablissement.association_date_creation)) + format_in_2_columns(pdf, "Date de publication ", try_format_date(etablissement.association_date_publication)) + format_in_2_columns(pdf, "Date de déclaration ", try_format_date(etablissement.association_date_declaration)) end - pdf.text "\n" end def render_single_champ(pdf, champ) From cce1435faff8f00c22840499b5205190511fa69d Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Wed, 1 Jul 2020 09:28:18 +0200 Subject: [PATCH 18/18] remove precision for currency --- app/helpers/etablissement_helper.rb | 2 +- spec/helpers/etablissement_helper_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/etablissement_helper.rb b/app/helpers/etablissement_helper.rb index 15128ce0d..4b23ba030 100644 --- a/app/helpers/etablissement_helper.rb +++ b/app/helpers/etablissement_helper.rb @@ -1,6 +1,6 @@ module EtablissementHelper def pretty_currency(capital_social, unit: '€') - number_to_currency(capital_social, locale: :fr, unit: unit) + number_to_currency(capital_social, locale: :fr, unit: unit, precision: 0) end def pretty_currency_unit(unit) diff --git a/spec/helpers/etablissement_helper_spec.rb b/spec/helpers/etablissement_helper_spec.rb index 94632791e..6573797e8 100644 --- a/spec/helpers/etablissement_helper_spec.rb +++ b/spec/helpers/etablissement_helper_spec.rb @@ -49,13 +49,13 @@ RSpec.describe EtablissementHelper, type: :helper do describe '#pretty_currency' do subject { pretty_currency(etablissement.entreprise_capital_social) } - it { is_expected.to eq('123 000,00 €') } + it { is_expected.to eq('123 000 €') } end describe '#pretty_currency with special unit' do subject { pretty_currency(12345, unit: 'k€') } - it { is_expected.to eq('12 345,00 k€') } + it { is_expected.to eq('12 345 k€') } end describe '#pretty_date_exercice' do subject { pretty_date_exercice("201908") }