From 3cc09c98f9dbd1bfb39d884ea571788b46e98e5d Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 6 Sep 2017 11:21:29 +0200 Subject: [PATCH 01/13] Avis: index --- .../new_gestionnaire/avis_controller.rb | 22 ++++++++++++ .../new_gestionnaire/avis/index.html.haml | 35 +++++++++++++++++++ config/routes.rb | 1 + .../new_gestionnaire/avis_controller_spec.rb | 29 +++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 app/controllers/new_gestionnaire/avis_controller.rb create mode 100644 app/views/new_gestionnaire/avis/index.html.haml create mode 100644 spec/controllers/new_gestionnaire/avis_controller_spec.rb diff --git a/app/controllers/new_gestionnaire/avis_controller.rb b/app/controllers/new_gestionnaire/avis_controller.rb new file mode 100644 index 000000000..0c003c17a --- /dev/null +++ b/app/controllers/new_gestionnaire/avis_controller.rb @@ -0,0 +1,22 @@ +module NewGestionnaire + class AvisController < ApplicationController + layout 'new_application' + + A_DONNER_STATUS = 'a-donner' + DONNES_STATUS = 'donnes' + + def index + gestionnaire_avis = current_gestionnaire.avis.includes(dossier: [:procedure, :user]) + @avis_a_donner, @avis_donnes = gestionnaire_avis.partition { |avis| avis.answer.nil? } + + @statut = params[:statut].present? ? params[:statut] : A_DONNER_STATUS + + @avis = case @statut + when A_DONNER_STATUS + @avis_a_donner + when DONNES_STATUS + @avis_donnes + end + end + end +end diff --git a/app/views/new_gestionnaire/avis/index.html.haml b/app/views/new_gestionnaire/avis/index.html.haml new file mode 100644 index 000000000..ee71f4d09 --- /dev/null +++ b/app/views/new_gestionnaire/avis/index.html.haml @@ -0,0 +1,35 @@ +#avis-index + .backoffice-header + .container.flex + .width-100 + %h1 Avis + %ul.tabs + %li{ class: (@statut == NewGestionnaire::AvisController::A_DONNER_STATUS) ? 'active' : nil }> + = link_to(avis_index_path(statut: NewGestionnaire::AvisController::A_DONNER_STATUS)) do + avis à donner + %span.badge= @avis_a_donner.count + + %li{ class: (@statut == NewGestionnaire::AvisController::DONNES_STATUS) ? 'active' : nil }> + = link_to(avis_index_path(statut: NewGestionnaire::AvisController::DONNES_STATUS)) do + avis #{'donné'.pluralize(@avis_donnes.count)} + %span.badge= @avis_donnes.count + + .container + - if @avis.present? + %table.table.dossiers-table.hoverable + %thead + %tr + %th.number-col Nº dossier + %th Demandeur + %th Procédure + %tbody + - @avis.each do |avis| + %tr + %td.number-col + = link_to(avis_path(avis), class: 'cell-link') do + %i.folder + #{avis.dossier.id} + %td= link_to(avis.dossier.user.email, avis_path(avis), class: 'cell-link') + %td= link_to(avis.dossier.procedure.libelle, avis_path(avis), class: 'cell-link') + - else + %h2 Aucun avis diff --git a/config/routes.rb b/config/routes.rb index 83adc5228..54694cee2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -258,6 +258,7 @@ Rails.application.routes.draw do end end end + resources :avis, only: [:index] get "recherche" => "recherches#index" end diff --git a/spec/controllers/new_gestionnaire/avis_controller_spec.rb b/spec/controllers/new_gestionnaire/avis_controller_spec.rb new file mode 100644 index 000000000..13f4e4925 --- /dev/null +++ b/spec/controllers/new_gestionnaire/avis_controller_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe NewGestionnaire::AvisController, type: :controller do + render_views + + let(:claimant) { create(:gestionnaire) } + let(:gestionnaire) { create(:gestionnaire) } + let(:procedure) { create(:procedure, :published, gestionnaires: [gestionnaire]) } + let(:dossier) { create(:dossier, :replied, procedure: procedure) } + let!(:avis_without_answer) { Avis.create(dossier: dossier, claimant: claimant, gestionnaire: gestionnaire) } + let!(:avis_with_answer) { Avis.create(dossier: dossier, claimant: claimant, gestionnaire: gestionnaire, answer: 'yop') } + + before { sign_in(gestionnaire) } + + describe '#index' do + before { get :index } + + 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, statut: 'donnes' } + + it { expect(assigns(:statut)).to eq('donnes') } + end + end +end From a1f9f7aa750bf9aecd29ec2d52f6427851e933ee Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 6 Sep 2017 11:26:32 +0200 Subject: [PATCH 02/13] Avis: show --- .../new_gestionnaire/avis_controller.rb | 11 +++++ .../new_gestionnaire/avis/_header.html.haml | 9 ++++ .../new_gestionnaire/avis/show.html.haml | 47 +++++++++++++++++++ config/routes.rb | 2 +- .../new_gestionnaire/avis_controller_spec.rb | 8 ++++ 5 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 app/views/new_gestionnaire/avis/_header.html.haml create mode 100644 app/views/new_gestionnaire/avis/show.html.haml diff --git a/app/controllers/new_gestionnaire/avis_controller.rb b/app/controllers/new_gestionnaire/avis_controller.rb index 0c003c17a..e97768f0c 100644 --- a/app/controllers/new_gestionnaire/avis_controller.rb +++ b/app/controllers/new_gestionnaire/avis_controller.rb @@ -18,5 +18,16 @@ module NewGestionnaire @avis_donnes end end + + def show + @avis = avis + @dossier = avis.dossier + end + + private + + def avis + current_gestionnaire.avis.includes(dossier: [:avis]).find(params[:id]) + end end end diff --git a/app/views/new_gestionnaire/avis/_header.html.haml b/app/views/new_gestionnaire/avis/_header.html.haml new file mode 100644 index 000000000..e38916596 --- /dev/null +++ b/app/views/new_gestionnaire/avis/_header.html.haml @@ -0,0 +1,9 @@ +.backoffice-header + .container + %ul.breadcrumbs + %li= link_to('Avis', avis_index_path) + %li= "#{dossier.procedure.libelle}, dossier nº #{dossier.id}" + + %ul.tabs + %li{ class: current_page?(avis_path(avis)) ? 'active' : nil } + = link_to 'Demande', avis_path(avis) diff --git a/app/views/new_gestionnaire/avis/show.html.haml b/app/views/new_gestionnaire/avis/show.html.haml new file mode 100644 index 000000000..e88d364f3 --- /dev/null +++ b/app/views/new_gestionnaire/avis/show.html.haml @@ -0,0 +1,47 @@ +#avis-show + = render partial: 'header', locals: { avis: @avis, dossier: @dossier } + + .container + .card + .card-title Identité du demandeur + - if @dossier.entreprise.present? + = render partial: 'new_gestionnaire/dossiers/identite_entreprise', locals: { entreprise: @dossier.entreprise } + + - if @dossier.individual.present? + = render partial: 'new_gestionnaire/dossiers/identite_individual', locals: { individual: @dossier.individual } + + .backoffice-title Formulaire + + - champs = @dossier.ordered_champs.decorate + - if champs.any? + .card.featured + = render partial: 'new_gestionnaire/dossiers/champs', locals: { champs: champs } + + - if @dossier.procedure.use_api_carto + = render partial: 'new_gestionnaire/dossiers/map', locals: { dossier: @dossier } + + - if @dossier.procedure.cerfa_flag? || @dossier.types_de_piece_justificative.any? + .card.featured + .card-title Pièces jointes + + %table.table.vertical + %tbody + - if @dossier.procedure.cerfa_flag? + %tr + %th Formulaire : + %td + - if @dossier.cerfa_available? + = link_to 'Télécharger', @dossier.cerfa.last.content_url, class: 'button', target: :blank + - else + Pièce non fournie + + - @dossier.procedure.types_de_piece_justificative.each do |type_de_piece_justificative| + %tr + %th= "#{type_de_piece_justificative.libelle} :" + %td + - pj = @dossier.retrieve_last_piece_justificative_by_type(type_de_piece_justificative.id) + - if pj.present? + Pièce fournie - + = link_to "Consulter", pj.content_url, class: "link", target: :blank + - else + Pièce non fournie diff --git a/config/routes.rb b/config/routes.rb index 54694cee2..5026843f1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -258,7 +258,7 @@ Rails.application.routes.draw do end end end - resources :avis, only: [:index] + resources :avis, only: [:index, :show] get "recherche" => "recherches#index" end diff --git a/spec/controllers/new_gestionnaire/avis_controller_spec.rb b/spec/controllers/new_gestionnaire/avis_controller_spec.rb index 13f4e4925..b5874754a 100644 --- a/spec/controllers/new_gestionnaire/avis_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/avis_controller_spec.rb @@ -26,4 +26,12 @@ describe NewGestionnaire::AvisController, type: :controller do it { expect(assigns(:statut)).to eq('donnes') } end end + + describe '#show' do + before { get :show, { id: avis_without_answer.id } } + + it { expect(response).to have_http_status(:success) } + it { expect(assigns(:avis)).to eq(avis_without_answer) } + it { expect(assigns(:dossier)).to eq(dossier) } + end end From 88c27479ee5e6b7ac600a61b13bd92bc29207b81 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 6 Sep 2017 16:14:03 +0200 Subject: [PATCH 03/13] Avis: instruction --- app/assets/stylesheets/new_design/avis.scss | 14 ++++++ .../new_gestionnaire/avis_controller.rb | 15 ++++++ .../new_gestionnaire/avis/_header.html.haml | 2 + .../avis/instruction.html.haml | 47 +++++++++++++++++++ config/routes.rb | 6 ++- .../new_gestionnaire/avis_controller_spec.rb | 19 ++++++++ 6 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 app/views/new_gestionnaire/avis/instruction.html.haml diff --git a/app/assets/stylesheets/new_design/avis.scss b/app/assets/stylesheets/new_design/avis.scss index e2ebc5675..f765678f6 100644 --- a/app/assets/stylesheets/new_design/avis.scss +++ b/app/assets/stylesheets/new_design/avis.scss @@ -2,6 +2,20 @@ @import "common"; @import "constants"; +.give-avis { + h1 { + font-size: 18px; + font-weight: bold; + margin-bottom: $default-padding; + } + + .avis-notice { + font-size: 12px; + color: $grey; + margin-bottom: 2 * $default-padding; + } +} + .ask-avis { h1 { font-size: 18px; diff --git a/app/controllers/new_gestionnaire/avis_controller.rb b/app/controllers/new_gestionnaire/avis_controller.rb index e97768f0c..ce1337f41 100644 --- a/app/controllers/new_gestionnaire/avis_controller.rb +++ b/app/controllers/new_gestionnaire/avis_controller.rb @@ -24,10 +24,25 @@ module NewGestionnaire @dossier = avis.dossier end + def instruction + @avis = avis + @dossier = avis.dossier + end + + def update + avis.update_attributes(avis_params) + flash.notice = 'Votre réponse est enregistrée.' + redirect_to instruction_avis_path(avis) + end + private def avis current_gestionnaire.avis.includes(dossier: [:avis]).find(params[:id]) end + + def avis_params + params.require(:avis).permit(:answer) + end end end diff --git a/app/views/new_gestionnaire/avis/_header.html.haml b/app/views/new_gestionnaire/avis/_header.html.haml index e38916596..9a01c84af 100644 --- a/app/views/new_gestionnaire/avis/_header.html.haml +++ b/app/views/new_gestionnaire/avis/_header.html.haml @@ -7,3 +7,5 @@ %ul.tabs %li{ class: current_page?(avis_path(avis)) ? 'active' : nil } = link_to 'Demande', avis_path(avis) + %li{ class: current_page?(instruction_avis_path(avis)) ? 'active' : nil } + = link_to 'Instruction', instruction_avis_path(avis) diff --git a/app/views/new_gestionnaire/avis/instruction.html.haml b/app/views/new_gestionnaire/avis/instruction.html.haml new file mode 100644 index 000000000..afcf61bb9 --- /dev/null +++ b/app/views/new_gestionnaire/avis/instruction.html.haml @@ -0,0 +1,47 @@ +#avis-show + = render partial: 'header', locals: { avis: @avis, dossier: @dossier } + +.container + %section.give-avis + %h1 Donner votre avis + %p.avis-notice= "#{@avis.claimant.email}: #{@avis.introduction}" + + = form_for @avis, url: avis_path(@avis), html: { class: 'form' } do |f| + = f.text_area :answer, rows: 3, placeholder: 'Votre avis', required: true + .send-wrapper + = f.submit 'Envoyer votre avis', class: 'button send' + + %section.ask-avis + %h1 Inviter une personne à donner son avis + %p.avis-notice L'invité pourra consulter, donner un avis sur le dossier et contribuer au fil de messagerie, mais il ne pourra le modifier. + + = form_for Avis.new, url: avis_dossier_path(@dossier.procedure, @dossier), html: { class: 'form' } do |f| + = f.email_field :email, placeholder: 'Adresse email', required: true + = f.text_area :introduction, rows: 3, value: 'Bonjour, merci de me donner votre avis sur ce dossier.', required: true + .send-wrapper + = f.submit 'Demander un avis', class: 'button send' + + - if @dossier.avis.present? + %section.list-avis + %h1.title + Avis des invités + %span.count= @dossier.avis.count + + %ul + - @dossier.avis.each do |avis| + %li.one-avis + %h2.claimant + = (avis.claimant.email == current_gestionnaire.email) ? 'Vous' : avis.claimant.email + %span.date Demande d'avis envoyée le #{I18n.l(avis.created_at.localtime, format: '%d/%m/%y')} + %p= avis.introduction + + .answer.flex.align-start + %i.bubble.avis-icon + .width-100 + %h2.gestionnaire + = avis.gestionnaire.email + - if avis.answer.present? + %span.date Réponse donnée le #{I18n.l(avis.updated_at.localtime, format: '%d/%m/%y')} + - else + %span.waiting En attente de réponse + %p= avis.answer diff --git a/config/routes.rb b/config/routes.rb index 5026843f1..25e54394b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -258,7 +258,11 @@ Rails.application.routes.draw do end end end - resources :avis, only: [:index, :show] + resources :avis, only: [:index, :show, :update] do + member do + get 'instruction' + end + end get "recherche" => "recherches#index" end diff --git a/spec/controllers/new_gestionnaire/avis_controller_spec.rb b/spec/controllers/new_gestionnaire/avis_controller_spec.rb index b5874754a..624730a64 100644 --- a/spec/controllers/new_gestionnaire/avis_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/avis_controller_spec.rb @@ -34,4 +34,23 @@ describe NewGestionnaire::AvisController, type: :controller do it { expect(assigns(:avis)).to eq(avis_without_answer) } it { expect(assigns(:dossier)).to eq(dossier) } end + + describe '#instruction' do + before { get :instruction, { id: avis_without_answer.id } } + + it { expect(response).to have_http_status(:success) } + it { expect(assigns(:avis)).to eq(avis_without_answer) } + it { expect(assigns(:dossier)).to eq(dossier) } + end + + describe '#update' do + before do + patch :update, { id: avis_without_answer.id, avis: { answer: 'answer' } } + avis_without_answer.reload + end + + it { expect(response).to redirect_to(instruction_avis_path(avis_without_answer)) } + it { expect(avis_without_answer.answer).to eq('answer') } + it { expect(flash.notice).to eq('Votre réponse est enregistrée.') } + end end From d1540c4a68365043ea93b2dcfa476f0a9c6d9565 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 6 Sep 2017 11:13:59 +0200 Subject: [PATCH 04/13] Avis: add avis link in header --- app/views/layouts/_new_header.haml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/_new_header.haml b/app/views/layouts/_new_header.haml index 5fff9c479..e9a4f19ea 100644 --- a/app/views/layouts/_new_header.haml +++ b/app/views/layouts/_new_header.haml @@ -7,9 +7,14 @@ %img{ src: image_url("header/logo-tps.svg") } - if gestionnaire_signed_in? + - current_url = request.path_info %ul.header-tabs - %li - = link_to "Procédures", procedures_path, class: "active" + - if current_gestionnaire.procedures.count > 0 + %li + = link_to "Procédures", procedures_path, class: (controller_name != 'avis') ? "active" : nil + - if current_gestionnaire.avis.count > 0 + %li + = link_to "Avis", avis_index_path, class: (controller_name == 'avis') ? "active" : nil %li = link_to "Ancienne interface", backoffice_dossiers_path From 3dfd77e9144ac299dd9ebe3e701aebdd354a809a Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 6 Sep 2017 17:06:03 +0200 Subject: [PATCH 05/13] Avis: add messagerie --- .../new_gestionnaire/avis_controller.rb | 16 +++++++++++++- .../new_gestionnaire/avis/_header.html.haml | 2 ++ .../avis/messagerie.html.haml | 21 +++++++++++++++++++ config/routes.rb | 2 ++ .../new_gestionnaire/avis_controller_spec.rb | 17 +++++++++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 app/views/new_gestionnaire/avis/messagerie.html.haml diff --git a/app/controllers/new_gestionnaire/avis_controller.rb b/app/controllers/new_gestionnaire/avis_controller.rb index ce1337f41..a10b87c50 100644 --- a/app/controllers/new_gestionnaire/avis_controller.rb +++ b/app/controllers/new_gestionnaire/avis_controller.rb @@ -35,14 +35,28 @@ module NewGestionnaire redirect_to instruction_avis_path(avis) end + def messagerie + @avis = avis + @dossier = avis.dossier + end + + def create_commentaire + Commentaire.create(commentaire_params.merge(email: current_gestionnaire.email, dossier: avis.dossier)) + redirect_to messagerie_avis_path(avis) + end + private def avis - current_gestionnaire.avis.includes(dossier: [:avis]).find(params[:id]) + current_gestionnaire.avis.includes(dossier: [:avis, :commentaires]).find(params[:id]) end def avis_params params.require(:avis).permit(:answer) end + + def commentaire_params + params.require(:commentaire).permit(:body) + end end end diff --git a/app/views/new_gestionnaire/avis/_header.html.haml b/app/views/new_gestionnaire/avis/_header.html.haml index 9a01c84af..1933d5a71 100644 --- a/app/views/new_gestionnaire/avis/_header.html.haml +++ b/app/views/new_gestionnaire/avis/_header.html.haml @@ -9,3 +9,5 @@ = link_to 'Demande', avis_path(avis) %li{ class: current_page?(instruction_avis_path(avis)) ? 'active' : nil } = link_to 'Instruction', instruction_avis_path(avis) + %li{ class: current_page?(messagerie_avis_path(avis)) ? 'active' : nil } + = link_to 'Messagerie', messagerie_avis_path(avis) diff --git a/app/views/new_gestionnaire/avis/messagerie.html.haml b/app/views/new_gestionnaire/avis/messagerie.html.haml new file mode 100644 index 000000000..4365459e8 --- /dev/null +++ b/app/views/new_gestionnaire/avis/messagerie.html.haml @@ -0,0 +1,21 @@ += render partial: 'header', locals: { avis: @avis, dossier: @dossier } + +.messagerie.container + %ul + - @dossier.commentaires.ordered.each do |commentaire| + %li + = render partial: 'new_gestionnaire/dossiers/commentaire_icon', locals: { commentaire: commentaire, current_gestionnaire: current_gestionnaire } + + .width-100 + %h2 + %span.mail + = render partial: 'new_gestionnaire/dossiers/commentaire_issuer', locals: { commentaire: commentaire, current_gestionnaire: current_gestionnaire } + - if ![current_gestionnaire.email, @dossier.user.email, 'contact@tps.apientreprise.fr'].include?(commentaire.email) + %span.guest Invité + %span.date= I18n.l(commentaire.created_at.localtime, format: '%H:%M le %d/%m/%Y') + %p= sanitize(commentaire.body) + + = form_for(Commentaire.new, url: commentaire_avis_path(@avis), html: { class: 'form' }) do |f| + = f.text_area :body, rows: 5, placeholder: 'Répondre ici', required: true + .send-wrapper + = f.submit 'Envoyer', class: 'button send' diff --git a/config/routes.rb b/config/routes.rb index 25e54394b..0cef1b99b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -261,6 +261,8 @@ Rails.application.routes.draw do resources :avis, only: [:index, :show, :update] do member do get 'instruction' + get 'messagerie' + post 'commentaire' => 'avis#create_commentaire' end end get "recherche" => "recherches#index" diff --git a/spec/controllers/new_gestionnaire/avis_controller_spec.rb b/spec/controllers/new_gestionnaire/avis_controller_spec.rb index 624730a64..03691fd1d 100644 --- a/spec/controllers/new_gestionnaire/avis_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/avis_controller_spec.rb @@ -43,6 +43,14 @@ describe NewGestionnaire::AvisController, type: :controller do it { expect(assigns(:dossier)).to eq(dossier) } end + describe '#messagerie' do + before { get :messagerie, { id: avis_without_answer.id } } + + it { expect(response).to have_http_status(:success) } + it { expect(assigns(:avis)).to eq(avis_without_answer) } + it { expect(assigns(:dossier)).to eq(dossier) } + end + describe '#update' do before do patch :update, { id: avis_without_answer.id, avis: { answer: 'answer' } } @@ -53,4 +61,13 @@ describe NewGestionnaire::AvisController, type: :controller do it { expect(avis_without_answer.answer).to eq('answer') } it { expect(flash.notice).to eq('Votre réponse est enregistrée.') } end + + describe '#create_commentaire' do + before do + post :create_commentaire, { id: avis_without_answer.id, commentaire: { body: 'commentaire body' } } + end + + it { expect(response).to redirect_to(messagerie_avis_path(avis_without_answer)) } + it { expect(dossier.commentaires.map(&:body)).to match(['commentaire body']) } + end end From 112e3a57936f3b94761f21fae6918cbabe7ff9e9 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Thu, 7 Sep 2017 16:04:53 +0200 Subject: [PATCH 06/13] Procedures: redirect to avis if suitable --- .../new_gestionnaire/procedures_controller.rb | 7 ++++ .../procedures_controller_spec.rb | 41 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/app/controllers/new_gestionnaire/procedures_controller.rb b/app/controllers/new_gestionnaire/procedures_controller.rb index 0dcd55db4..ab78a563b 100644 --- a/app/controllers/new_gestionnaire/procedures_controller.rb +++ b/app/controllers/new_gestionnaire/procedures_controller.rb @@ -1,6 +1,7 @@ module NewGestionnaire class ProceduresController < GestionnaireController before_action :ensure_ownership!, except: [:index] + before_action :redirect_to_avis_if_needed, only: [:index] def index @procedures = current_gestionnaire.procedures.order(archived_at: :desc, published_at: :desc) @@ -76,5 +77,11 @@ module NewGestionnaire redirect_to root_path end end + + def redirect_to_avis_if_needed + if current_gestionnaire.procedures.count == 0 && current_gestionnaire.avis.count > 0 + redirect_to avis_index_path + end + end end end diff --git a/spec/controllers/new_gestionnaire/procedures_controller_spec.rb b/spec/controllers/new_gestionnaire/procedures_controller_spec.rb index 1a581eed9..30f70803a 100644 --- a/spec/controllers/new_gestionnaire/procedures_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/procedures_controller_spec.rb @@ -42,6 +42,47 @@ describe NewGestionnaire::ProceduresController, type: :controller do end end + describe "before_action: redirect_to_avis_if_needed" do + it "is present" do + before_actions = NewGestionnaire::ProceduresController + ._process_action_callbacks + .find_all{|process_action_callbacks| process_action_callbacks.kind == :before} + .map(&:filter) + + expect(before_actions).to include(:redirect_to_avis_if_needed) + end + end + + describe "redirect_to_avis_if_needed" do + let(:gestionnaire) { create(:gestionnaire) } + + before do + expect(@controller).to receive(:current_gestionnaire).at_least(:once).and_return(gestionnaire) + allow(@controller).to receive(:redirect_to) + end + + context "when a gestionnaire has some procedures" do + let!(:some_procedure) { create(:procedure, gestionnaires: [gestionnaire]) } + + before { @controller.send(:redirect_to_avis_if_needed) } + + it "does not redirects nor flash" do + expect(@controller).not_to have_received(:redirect_to) + end + end + + context "when a gestionnaire has no procedure and some avis" do + before do + Avis.create!(dossier: create(:dossier), claimant: create(:gestionnaire), gestionnaire: gestionnaire) + @controller.send(:redirect_to_avis_if_needed) + end + + it "redirects avis" do + expect(@controller).to have_received(:redirect_to).with(avis_index_path) + end + end + end + describe "#index" do let(:gestionnaire) { create(:gestionnaire) } subject { get :index } From f55c7a05128acfa6055af04a3a349e410faf89e6 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Fri, 8 Sep 2017 11:52:20 +0200 Subject: [PATCH 07/13] Avis: add confidentiel field --- .../20170908094900_add_confidentiel_field_to_avis.rb | 5 +++++ db/schema.rb | 9 +++++---- .../2017_09_19_set_confidentialite_to_old_avis.rake | 5 +++++ 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20170908094900_add_confidentiel_field_to_avis.rb create mode 100644 lib/tasks/2017_09_19_set_confidentialite_to_old_avis.rake diff --git a/db/migrate/20170908094900_add_confidentiel_field_to_avis.rb b/db/migrate/20170908094900_add_confidentiel_field_to_avis.rb new file mode 100644 index 000000000..eed554510 --- /dev/null +++ b/db/migrate/20170908094900_add_confidentiel_field_to_avis.rb @@ -0,0 +1,5 @@ +class AddConfidentielFieldToAvis < ActiveRecord::Migration[5.0] + def change + add_column :avis, :confidentiel, :boolean, default: false, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 04ae79e32..ec4a5d01a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170801083632) do +ActiveRecord::Schema.define(version: 20170908101023) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -99,9 +99,10 @@ ActiveRecord::Schema.define(version: 20170801083632) do t.text "answer" t.integer "gestionnaire_id" t.integer "dossier_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "claimant_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "claimant_id", null: false + t.boolean "confidentiel", default: false, null: false t.index ["claimant_id"], name: "index_avis_on_claimant_id", using: :btree t.index ["dossier_id"], name: "index_avis_on_dossier_id", using: :btree t.index ["gestionnaire_id"], name: "index_avis_on_gestionnaire_id", using: :btree diff --git a/lib/tasks/2017_09_19_set_confidentialite_to_old_avis.rake b/lib/tasks/2017_09_19_set_confidentialite_to_old_avis.rake new file mode 100644 index 000000000..9579811da --- /dev/null +++ b/lib/tasks/2017_09_19_set_confidentialite_to_old_avis.rake @@ -0,0 +1,5 @@ +namespace :'2017_09_19_set_confidentialite_to_old_avis' do + task set: :environment do + Avis.unscoped.update_all(confidentiel: true) + end +end From fdbf34f04bacc3b0a248dd267cfc619a2e69c778 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Fri, 8 Sep 2017 11:52:20 +0200 Subject: [PATCH 08/13] Avis instruction: only authorized avis --- app/models/dossier.rb | 12 +++++ .../avis/instruction.html.haml | 4 +- spec/models/dossier_spec.rb | 50 +++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 0c30adc50..c214479b0 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -348,6 +348,18 @@ class Dossier < ActiveRecord::Base parts.join end + def avis_for(gestionnaire) + if gestionnaire.dossiers.include?(self) + avis.order(created_at: :asc) + else + avis + .where(confidentiel: false) + .or(avis.where(claimant: gestionnaire)) + .or(avis.where(gestionnaire: gestionnaire)) + .order(created_at: :asc) + end + end + private def build_attestation diff --git a/app/views/new_gestionnaire/avis/instruction.html.haml b/app/views/new_gestionnaire/avis/instruction.html.haml index afcf61bb9..2df4cf918 100644 --- a/app/views/new_gestionnaire/avis/instruction.html.haml +++ b/app/views/new_gestionnaire/avis/instruction.html.haml @@ -25,10 +25,10 @@ %section.list-avis %h1.title Avis des invités - %span.count= @dossier.avis.count + %span.count= @dossier.avis_for(current_gestionnaire).count %ul - - @dossier.avis.each do |avis| + - @dossier.avis_for(current_gestionnaire).each do |avis| %li.one-avis %h2.claimant = (avis.claimant.email == current_gestionnaire.email) ? 'Vous' : avis.claimant.email diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index acba3c1ad..a0edb21b7 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -695,6 +695,56 @@ describe Dossier do end end + describe '#avis_for' do + let!(:procedure) { create(:procedure, :published) } + let!(:dossier) { create(:dossier, procedure: procedure, state: :initiated) } + + let!(:gestionnaire) { create(:gestionnaire, procedures: [procedure]) } + let!(:expert_1) { create(:gestionnaire) } + let!(:expert_2) { create(:gestionnaire) } + + context 'when there is a public advice asked from the dossiers gestionnaire' do + let!(:avis) { Avis.create(dossier: dossier, claimant: gestionnaire, gestionnaire: expert_1, confidentiel: false) } + + it { expect(dossier.avis_for(gestionnaire)).to match([avis]) } + it { expect(dossier.avis_for(expert_1)).to match([avis]) } + it { expect(dossier.avis_for(expert_2)).to match([avis]) } + end + + context 'when there is a private advice asked from the dossiers gestionnaire' do + let!(:avis) { Avis.create(dossier: dossier, claimant: gestionnaire, gestionnaire: expert_1, confidentiel: true) } + + it { expect(dossier.avis_for(gestionnaire)).to match([avis]) } + it { expect(dossier.avis_for(expert_1)).to match([avis]) } + it { expect(dossier.avis_for(expert_2)).to match([]) } + end + + context 'when there is a public advice asked from one expert to another' do + let!(:avis) { Avis.create(dossier: dossier, claimant: expert_1, gestionnaire: expert_2, confidentiel: false) } + + it { expect(dossier.avis_for(gestionnaire)).to match([avis]) } + it { expect(dossier.avis_for(expert_1)).to match([avis]) } + it { expect(dossier.avis_for(expert_2)).to match([avis]) } + end + + context 'when there is a private advice asked from one expert to another' do + let!(:avis) { Avis.create(dossier: dossier, claimant: expert_1, gestionnaire: expert_2, confidentiel: true) } + + it { expect(dossier.avis_for(gestionnaire)).to match([avis]) } + it { expect(dossier.avis_for(expert_1)).to match([avis]) } + it { expect(dossier.avis_for(expert_2)).to match([avis]) } + end + + context 'when they are a lot of advice' do + let!(:avis_1) { Avis.create(dossier: dossier, claimant: expert_1, gestionnaire: expert_2, confidentiel: false, created_at: DateTime.parse('10/01/2010')) } + let!(:avis_2) { Avis.create(dossier: dossier, claimant: expert_1, gestionnaire: expert_2, confidentiel: false, created_at: DateTime.parse('9/01/2010')) } + let!(:avis_3) { Avis.create(dossier: dossier, claimant: expert_1, gestionnaire: expert_2, confidentiel: false, created_at: DateTime.parse('11/01/2010')) } + + it { expect(dossier.avis_for(gestionnaire)).to match([avis_2, avis_1, avis_3]) } + it { expect(dossier.avis_for(expert_1)).to match([avis_2, avis_1, avis_3]) } + end + end + describe '#update_state_dates' do let(:state) { 'draft' } let(:dossier) { create(:dossier, state: state) } From f420cde53165c25d7dc789317f741dab5518fbdb Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Tue, 19 Sep 2017 17:43:07 +0200 Subject: [PATCH 09/13] Icons: add lock --- app/assets/images/icons/lock.svg | 1 + app/assets/stylesheets/new_design/icons.scss | 4 ++++ app/views/root/patron.html.haml | 1 + 3 files changed, 6 insertions(+) create mode 100644 app/assets/images/icons/lock.svg diff --git a/app/assets/images/icons/lock.svg b/app/assets/images/icons/lock.svg new file mode 100644 index 000000000..a2aa4f2ab --- /dev/null +++ b/app/assets/images/icons/lock.svg @@ -0,0 +1 @@ + diff --git a/app/assets/stylesheets/new_design/icons.scss b/app/assets/stylesheets/new_design/icons.scss index fe7d8add2..2e09bac25 100644 --- a/app/assets/stylesheets/new_design/icons.scss +++ b/app/assets/stylesheets/new_design/icons.scss @@ -52,4 +52,8 @@ i { &.attachment { background-image: image-url("icons/attachment.svg"); } + + &.lock { + background-image: image-url("icons/lock.svg"); + } } diff --git a/app/views/root/patron.html.haml b/app/views/root/patron.html.haml index 438f8de64..c5cc0164e 100644 --- a/app/views/root/patron.html.haml +++ b/app/views/root/patron.html.haml @@ -14,6 +14,7 @@ %i.in-progress %i.bubble %i.attachment + %i.lock %h1 Formulaires From 4dd20c17d13fb89cab2805209fb184a74750d722 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 20 Sep 2017 10:41:09 +0200 Subject: [PATCH 10/13] Avis: extract of avis list and add confidential icon --- .../avis/_avis_list.html.haml | 30 +++++++++++++++++++ .../avis/instruction.html.haml | 25 +--------------- .../dossiers/instruction.html.haml | 25 +--------------- 3 files changed, 32 insertions(+), 48 deletions(-) create mode 100644 app/views/new_gestionnaire/avis/_avis_list.html.haml diff --git a/app/views/new_gestionnaire/avis/_avis_list.html.haml b/app/views/new_gestionnaire/avis/_avis_list.html.haml new file mode 100644 index 000000000..ffcdcadc2 --- /dev/null +++ b/app/views/new_gestionnaire/avis/_avis_list.html.haml @@ -0,0 +1,30 @@ +- if avis.present? + %section.list-avis + %h1.title + Avis des invités + %span.count= avis.count + + %ul + - avis.each do |avis| + %li.one-avis.flex.align-start + .width-100 + %h2.claimant + Demandeur : + %span.email= (avis.claimant.email == current_gestionnaire.email) ? 'Vous' : avis.claimant.email + - if avis.confidentiel? + %span.confidentiel + confidentiel + %i.lock{ title: "Cet avis n'est pas affiché avec les autres experts consultés" } + %span.date Demande d'avis envoyée le #{I18n.l(avis.created_at.localtime, format: '%d/%m/%y')} + %p= avis.introduction + + .answer.flex.align-start + %i.bubble.avis-icon + .width-100 + %h2.gestionnaire + = (avis.gestionnaire.email == current_gestionnaire.email) ? 'Vous' : avis.gestionnaire.email + - if avis.answer.present? + %span.date Réponse donnée le #{I18n.l(avis.updated_at.localtime, format: '%d/%m/%y')} + - else + %span.waiting En attente de réponse + %p= avis.answer diff --git a/app/views/new_gestionnaire/avis/instruction.html.haml b/app/views/new_gestionnaire/avis/instruction.html.haml index 2df4cf918..dd11eada0 100644 --- a/app/views/new_gestionnaire/avis/instruction.html.haml +++ b/app/views/new_gestionnaire/avis/instruction.html.haml @@ -21,27 +21,4 @@ .send-wrapper = f.submit 'Demander un avis', class: 'button send' - - if @dossier.avis.present? - %section.list-avis - %h1.title - Avis des invités - %span.count= @dossier.avis_for(current_gestionnaire).count - - %ul - - @dossier.avis_for(current_gestionnaire).each do |avis| - %li.one-avis - %h2.claimant - = (avis.claimant.email == current_gestionnaire.email) ? 'Vous' : avis.claimant.email - %span.date Demande d'avis envoyée le #{I18n.l(avis.created_at.localtime, format: '%d/%m/%y')} - %p= avis.introduction - - .answer.flex.align-start - %i.bubble.avis-icon - .width-100 - %h2.gestionnaire - = avis.gestionnaire.email - - if avis.answer.present? - %span.date Réponse donnée le #{I18n.l(avis.updated_at.localtime, format: '%d/%m/%y')} - - else - %span.waiting En attente de réponse - %p= avis.answer + = render partial: 'avis_list', locals: { avis: @dossier.avis_for(current_gestionnaire) } diff --git a/app/views/new_gestionnaire/dossiers/instruction.html.haml b/app/views/new_gestionnaire/dossiers/instruction.html.haml index 016abc911..c07dcbe5c 100644 --- a/app/views/new_gestionnaire/dossiers/instruction.html.haml +++ b/app/views/new_gestionnaire/dossiers/instruction.html.haml @@ -11,30 +11,7 @@ .send-wrapper = f.submit 'Demander un avis', class: 'button send' - - if @dossier.avis.present? - %section.list-avis - %h1.title - Avis des invités - %span.count= @dossier.avis.count - - %ul - - @dossier.avis.each do |avis| - %li.one-avis - %h2.claimant - = (avis.claimant.email == current_gestionnaire.email) ? 'Vous' : avis.claimant.email - %span.date Demande d'avis envoyée le #{I18n.l(avis.created_at.localtime, format: '%d/%m/%y')} - %p= avis.introduction - - .answer.flex.align-start - %i.bubble.avis-icon - .width-100 - %h2.gestionnaire - = avis.gestionnaire.email - - if avis.answer.present? - %span.date Réponse donnée le #{I18n.l(avis.updated_at.localtime, format: '%d/%m/%y')} - - else - %span.waiting En attente de réponse - %p= avis.answer + = render partial: 'new_gestionnaire/avis/avis_list', locals: { avis: @dossier.avis } - if @dossier.ordered_champs_private.present? %section From caaa3169e5847006536553973e86b244bf0cf36f Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 20 Sep 2017 10:52:48 +0200 Subject: [PATCH 11/13] Avis instruction: can ask for a confidentiel avis --- app/assets/stylesheets/new_design/avis.scss | 59 ++++++++++++++++++- app/assets/stylesheets/new_design/flex.scss | 4 ++ .../new_gestionnaire/avis_controller.rb | 10 ++++ .../avis/instruction.html.haml | 30 ++++++++-- config/routes.rb | 1 + .../new_gestionnaire/avis_controller_spec.rb | 42 +++++++++++++ 6 files changed, 137 insertions(+), 9 deletions(-) diff --git a/app/assets/stylesheets/new_design/avis.scss b/app/assets/stylesheets/new_design/avis.scss index f765678f6..94ff4b0ee 100644 --- a/app/assets/stylesheets/new_design/avis.scss +++ b/app/assets/stylesheets/new_design/avis.scss @@ -9,10 +9,30 @@ margin-bottom: $default-padding; } - .avis-notice { + .lock { + margin-right: $default-spacer; + } + + h2 { + font-weight: bold; + margin-bottom: $default-padding; + } + + .introduction { + margin-bottom: $default-padding; + } + + .confidentiel { + color: $grey; + font-weight: normal; + margin-bottom: 2 * $default-padding; + } + + .date { font-size: 12px; color: $grey; - margin-bottom: 2 * $default-padding; + float: right; + font-weight: normal; } } @@ -24,7 +44,7 @@ } .avis-notice { - font-size: 12px; + font-size: 14px; color: $grey; margin-bottom: 2 * $default-padding; } @@ -32,6 +52,23 @@ input[type=email] { max-width: 500px; } + + form > label { + display: inline-block; + } + + .confidentiel { + color: $grey; + font-weight: normal; + margin-bottom: 2 * $default-padding; + } + + .confidentiel-wrapper { + label, + select { + display: inline-block; + } + } } .list-avis { @@ -57,6 +94,10 @@ border-top: 1px solid $grey; padding: $default-padding 0; + .lock { + margin-right: $default-spacer; + } + h2 { font-weight: bold; margin-bottom: $default-spacer; @@ -73,6 +114,18 @@ .avis-icon { margin-right: $default-spacer; } + + .confidentiel { + color: $grey; + font-size: 12px; + + .lock { + width: 12px; + height: 12px; + background-size: 12px 12px; + vertical-align: sub; + } + } } .date, diff --git a/app/assets/stylesheets/new_design/flex.scss b/app/assets/stylesheets/new_design/flex.scss index b3910bc37..43416c333 100644 --- a/app/assets/stylesheets/new_design/flex.scss +++ b/app/assets/stylesheets/new_design/flex.scss @@ -9,6 +9,10 @@ align-items: flex-start; } + &.align-baseline { + align-items: baseline; + } + &.justify-between { justify-content: space-between; } diff --git a/app/controllers/new_gestionnaire/avis_controller.rb b/app/controllers/new_gestionnaire/avis_controller.rb index a10b87c50..94f05886e 100644 --- a/app/controllers/new_gestionnaire/avis_controller.rb +++ b/app/controllers/new_gestionnaire/avis_controller.rb @@ -45,6 +45,12 @@ module NewGestionnaire redirect_to messagerie_avis_path(avis) end + def create_avis + confidentiel = avis.confidentiel || params[:avis][:confidentiel] + Avis.create(create_avis_params.merge(claimant: current_gestionnaire, dossier: avis.dossier, confidentiel: confidentiel)) + redirect_to instruction_avis_path(avis) + end + private def avis @@ -58,5 +64,9 @@ module NewGestionnaire def commentaire_params params.require(:commentaire).permit(:body) end + + def create_avis_params + params.require(:avis).permit(:email, :introduction) + end end end diff --git a/app/views/new_gestionnaire/avis/instruction.html.haml b/app/views/new_gestionnaire/avis/instruction.html.haml index dd11eada0..82380bb29 100644 --- a/app/views/new_gestionnaire/avis/instruction.html.haml +++ b/app/views/new_gestionnaire/avis/instruction.html.haml @@ -4,21 +4,39 @@ .container %section.give-avis %h1 Donner votre avis - %p.avis-notice= "#{@avis.claimant.email}: #{@avis.introduction}" + %h2.claimant + = @avis.claimant.email + %span.date Demande d'avis envoyée le #{I18n.l(@avis.created_at.localtime, format: '%d/%m/%y')} + %p.introduction= @avis.introduction = form_for @avis, url: avis_path(@avis), html: { class: 'form' } do |f| = f.text_area :answer, rows: 3, placeholder: 'Votre avis', required: true - .send-wrapper - = f.submit 'Envoyer votre avis', class: 'button send' + .flex.justify-between.align-baseline + %p.confidentiel + %i.lock + Cet avis est confidentiel et n'est pas affiché aux autres experts consultés + .send-wrapper + = f.submit 'Envoyer votre avis', class: 'button send' %section.ask-avis %h1 Inviter une personne à donner son avis %p.avis-notice L'invité pourra consulter, donner un avis sur le dossier et contribuer au fil de messagerie, mais il ne pourra le modifier. - = form_for Avis.new, url: avis_dossier_path(@dossier.procedure, @dossier), html: { class: 'form' } do |f| + = form_for Avis.new, url: avis_avis_path(@avis), html: { class: 'form' } do |f| = f.email_field :email, placeholder: 'Adresse email', required: true = f.text_area :introduction, rows: 3, value: 'Bonjour, merci de me donner votre avis sur ce dossier.', required: true - .send-wrapper - = f.submit 'Demander un avis', class: 'button send' + .flex.justify-between.align-baseline + - if @avis.confidentiel? + %p.confidentiel + %i.lock + Cet avis est confidentiel et n'est pas affiché aux autres experts consultés + .send-wrapper + = f.submit 'Demander un avis', class: 'button send' + - else + .confidentiel-wrapper + = f.label :confidentiel, 'Cet avis est' + = f.select :confidentiel, [['partagé avec les autres experts', false], ['confidentiel', true]] + .send-wrapper + = f.submit 'Demander un avis', class: 'button send' = render partial: 'avis_list', locals: { avis: @dossier.avis_for(current_gestionnaire) } diff --git a/config/routes.rb b/config/routes.rb index 0cef1b99b..755d30ff2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -263,6 +263,7 @@ Rails.application.routes.draw do get 'instruction' get 'messagerie' post 'commentaire' => 'avis#create_commentaire' + post 'avis' => 'avis#create_avis' end end get "recherche" => "recherches#index" diff --git a/spec/controllers/new_gestionnaire/avis_controller_spec.rb b/spec/controllers/new_gestionnaire/avis_controller_spec.rb index 03691fd1d..5254c3344 100644 --- a/spec/controllers/new_gestionnaire/avis_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/avis_controller_spec.rb @@ -70,4 +70,46 @@ describe NewGestionnaire::AvisController, type: :controller do it { expect(response).to redirect_to(messagerie_avis_path(avis_without_answer)) } it { expect(dossier.commentaires.map(&:body)).to match(['commentaire body']) } end + + describe '#create_avis' do + let!(:previous_avis) { Avis.create(dossier: dossier, claimant: claimant, gestionnaire: gestionnaire, confidentiel: previous_avis_confidentiel) } + let(:email) { 'a@b.com' } + let(:intro) { 'introduction' } + let(:created_avis) { Avis.last } + + before do + post :create_avis, { id: previous_avis.id, avis: { email: email, introduction: intro, confidentiel: asked_confidentiel } } + end + + context 'when the previous avis is public' do + let(:previous_avis_confidentiel) { false } + + context 'when the user asked for a public avis' do + let(:asked_confidentiel) { false } + + it { expect(created_avis.confidentiel).to be(false) } + it { expect(created_avis.email).to eq(email) } + 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(gestionnaire) } + it { expect(response).to redirect_to(instruction_avis_path(previous_avis)) } + end + + context 'when the user asked for a confidentiel avis' do + let(:asked_confidentiel) { true } + + it { expect(created_avis.confidentiel).to be(true) } + end + end + + context 'when the preivous avis is confidentiel' do + let(:previous_avis_confidentiel) { true } + + context 'when the user asked for a public avis' do + let(:asked_confidentiel) { false } + + it { expect(created_avis.confidentiel).to be(true) } + end + end + end end From 3c3e303a59ebed1cc76a7e110e597b9c9cd3a2fd Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 20 Sep 2017 10:42:16 +0200 Subject: [PATCH 12/13] Dossier instruction: can ask for a confidentiel avis --- app/controllers/new_gestionnaire/dossiers_controller.rb | 2 +- app/views/new_gestionnaire/dossiers/instruction.html.haml | 8 ++++++-- .../new_gestionnaire/dossiers_controller_spec.rb | 5 ++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/controllers/new_gestionnaire/dossiers_controller.rb b/app/controllers/new_gestionnaire/dossiers_controller.rb index 99ce6f033..69ea7ee99 100644 --- a/app/controllers/new_gestionnaire/dossiers_controller.rb +++ b/app/controllers/new_gestionnaire/dossiers_controller.rb @@ -87,7 +87,7 @@ module NewGestionnaire end def avis_params - params.require(:avis).permit(:email, :introduction) + params.require(:avis).permit(:email, :introduction, :confidentiel) end def champs_private_params diff --git a/app/views/new_gestionnaire/dossiers/instruction.html.haml b/app/views/new_gestionnaire/dossiers/instruction.html.haml index c07dcbe5c..19955f412 100644 --- a/app/views/new_gestionnaire/dossiers/instruction.html.haml +++ b/app/views/new_gestionnaire/dossiers/instruction.html.haml @@ -8,8 +8,12 @@ = form_for Avis.new, url: avis_dossier_path(@dossier.procedure, @dossier), html: { class: 'form' } do |f| = f.email_field :email, placeholder: 'Adresse email', required: true = f.text_area :introduction, rows: 3, value: 'Bonjour, merci de me donner votre avis sur ce dossier.', required: true - .send-wrapper - = f.submit 'Demander un avis', class: 'button send' + .flex.justify-between.align-baseline + .confidentiel-wrapper + = f.label :confidentiel, 'Cet avis est' + = f.select :confidentiel, [['partagé avec les autres experts', false], ['confidentiel', true]] + .send-wrapper + = f.submit 'Demander un avis', class: 'button send' = render partial: 'new_gestionnaire/avis/avis_list', locals: { avis: @dossier.avis } diff --git a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb index 084a52ed2..988e8e05a 100644 --- a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe NewGestionnaire::DossiersController, type: :controller do + render_views + let(:gestionnaire) { create(:gestionnaire) } let(:procedure) { create(:procedure, :published, gestionnaires: [gestionnaire]) } let(:dossier) { create(:dossier, :replied, procedure: procedure) } @@ -122,12 +124,13 @@ describe NewGestionnaire::DossiersController, type: :controller do post :create_avis, params: { procedure_id: procedure.id, dossier_id: dossier.id, - avis: { email: 'email@a.com', introduction: 'intro' } + avis: { email: 'email@a.com', introduction: 'intro', confidentiel: true } } end it { expect(saved_avis.email).to eq('email@a.com') } it { expect(saved_avis.introduction).to eq('intro') } + it { expect(saved_avis.confidentiel).to eq(true) } it { expect(saved_avis.dossier).to eq(dossier) } it { expect(saved_avis.claimant).to eq(gestionnaire) } it { expect(response).to redirect_to(instruction_dossier_path(dossier.procedure, dossier)) } From bacff0a17898c337e8cf577442afa2bd916f4375 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 20 Sep 2017 10:51:06 +0200 Subject: [PATCH 13/13] Avis: wording --- app/assets/stylesheets/new_design/avis.scss | 11 ++++++----- app/views/new_gestionnaire/avis/instruction.html.haml | 3 ++- .../new_gestionnaire/dossiers/instruction.html.haml | 2 +- app/views/root/patron.html.haml | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/new_design/avis.scss b/app/assets/stylesheets/new_design/avis.scss index 94ff4b0ee..2686d8311 100644 --- a/app/assets/stylesheets/new_design/avis.scss +++ b/app/assets/stylesheets/new_design/avis.scss @@ -14,8 +14,11 @@ } h2 { - font-weight: bold; margin-bottom: $default-padding; + + .email { + font-weight: bold; + } } .introduction { @@ -32,7 +35,6 @@ font-size: 12px; color: $grey; float: right; - font-weight: normal; } } @@ -99,11 +101,10 @@ } h2 { - font-weight: bold; margin-bottom: $default-spacer; - span { - font-weight: normal; + .email { + font-weight: bold; } } diff --git a/app/views/new_gestionnaire/avis/instruction.html.haml b/app/views/new_gestionnaire/avis/instruction.html.haml index 82380bb29..53c4dd8e7 100644 --- a/app/views/new_gestionnaire/avis/instruction.html.haml +++ b/app/views/new_gestionnaire/avis/instruction.html.haml @@ -5,7 +5,8 @@ %section.give-avis %h1 Donner votre avis %h2.claimant - = @avis.claimant.email + Demandeur : + %span.email= @avis.claimant.email %span.date Demande d'avis envoyée le #{I18n.l(@avis.created_at.localtime, format: '%d/%m/%y')} %p.introduction= @avis.introduction diff --git a/app/views/new_gestionnaire/dossiers/instruction.html.haml b/app/views/new_gestionnaire/dossiers/instruction.html.haml index 19955f412..ed597681f 100644 --- a/app/views/new_gestionnaire/dossiers/instruction.html.haml +++ b/app/views/new_gestionnaire/dossiers/instruction.html.haml @@ -3,7 +3,7 @@ #dossier-instruction.container %section.ask-avis %h1 Inviter une personne à donner son avis - %p.avis-notice Elle pourra consulter, donner un avis sur le dossier et contribuer au fil de messagerie, mais elle ne pourra le modifier. + %p.avis-notice L'invité pourra consulter, donner un avis sur le dossier et contribuer au fil de messagerie, mais il ne pourra le modifier. = form_for Avis.new, url: avis_dossier_path(@dossier.procedure, @dossier), html: { class: 'form' } do |f| = f.email_field :email, placeholder: 'Adresse email', required: true diff --git a/app/views/root/patron.html.haml b/app/views/root/patron.html.haml index c5cc0164e..6c7abfb16 100644 --- a/app/views/root/patron.html.haml +++ b/app/views/root/patron.html.haml @@ -162,7 +162,7 @@ .container %section.ask-avis %h1 Inviter une personne à donner son avis - %p.avis-notice Elle pourra consulter, donner un avis sur le dossier et contribuer au fil de messagerie, mais elle ne pourra le modifier. + %p.avis-notice L'invité pourra consulter, donner un avis sur le dossier et contribuer au fil de messagerie, mais il ne pourra le modifier. = form_for Avis.new, url: '/', html: { class: 'form' } do |f| = f.email_field :email, placeholder: 'Adresse email', required: true