diff --git a/app/assets/stylesheets/new_design/avis.scss b/app/assets/stylesheets/new_design/avis.scss index 0217f3d76..42e7c354d 100644 --- a/app/assets/stylesheets/new_design/avis.scss +++ b/app/assets/stylesheets/new_design/avis.scss @@ -105,6 +105,10 @@ margin-top: $default-padding; } + .answer-body p:not(:last-of-type) { + margin-bottom: $default-padding; + } + .avis-icon { margin-right: $default-spacer; } diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7551320aa..8ab881d8b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -195,7 +195,7 @@ class ApplicationController < ActionController::Base def sentry_user user = logged_user - { id: user&.id, role: user&.class&.name || 'Guest' }.compact + { id: user ? "#{user.class.name}##{user.id}" : 'Guest' } end def sentry_config @@ -205,6 +205,7 @@ class ApplicationController < ActionController::Base key: sentry[:client_key], enabled: sentry[:enabled], environment: sentry[:environment], + browser: { modern: browser.modern? }, user: sentry_user } end diff --git a/app/controllers/users/commencer_controller.rb b/app/controllers/users/commencer_controller.rb index a20a009fe..9a16ee2aa 100644 --- a/app/controllers/users/commencer_controller.rb +++ b/app/controllers/users/commencer_controller.rb @@ -4,38 +4,39 @@ module Users def commencer @procedure = Procedure.publiees.find_by(path: params[:path]) - - if @procedure.blank? - flash.alert = "La démarche est inconnue, ou la création de nouveaux dossiers pour cette démarche est terminée." - return redirect_to root_path - end + return procedure_not_found if @procedure.blank? render 'commencer/show' end def commencer_test @procedure = Procedure.brouillons.find_by(path: params[:path]) - - if @procedure.blank? - flash.alert = "La démarche est inconnue, ou cette démarche n’est maintenant plus en test." - return redirect_to root_path - end + return procedure_not_found if @procedure.blank? render 'commencer/show' end def sign_in - store_user_location! + @procedure = Procedure.find_by(path: params[:path]) + return procedure_not_found if @procedure.blank? + + store_user_location!(@procedure) redirect_to new_user_session_path end def sign_up - store_user_location! + @procedure = Procedure.find_by(path: params[:path]) + return procedure_not_found if @procedure.blank? + + store_user_location!(@procedure) redirect_to new_user_registration_path end def france_connect - store_user_location! + @procedure = Procedure.find_by(path: params[:path]) + return procedure_not_found if @procedure.blank? + + store_user_location!(@procedure) redirect_to france_connect_particulier_path end @@ -45,8 +46,21 @@ module Users private - def store_user_location! + def procedure_not_found procedure = Procedure.find_by(path: params[:path]) + + if procedure&.archivee? + flash.alert = t('errors.messages.procedure_archived') + elsif procedure&.publiee? + flash.alert = t('errors.messages.procedure_not_draft') + else + flash.alert = t('errors.messages.procedure_not_found') + end + + return redirect_to root_path + end + + def store_user_location!(procedure) store_location_for(:user, helpers.procedure_lien(procedure)) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 08565167f..91df7a137 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -60,6 +60,12 @@ module ApplicationHelper # rubocop:enable Rails/OutputSafety end + def show_element(selector) + # rubocop:disable Rails/OutputSafety + raw("document.querySelector('#{selector}').classList.remove('hidden');") + # rubocop:enable Rails/OutputSafety + end + def disable_element(selector) # rubocop:disable Rails/OutputSafety raw("document.querySelector('#{selector}').disabled = true;") diff --git a/app/javascript/shared/track/sentry.js b/app/javascript/shared/track/sentry.js index 5c3bafc17..23410535a 100644 --- a/app/javascript/shared/track/sentry.js +++ b/app/javascript/shared/track/sentry.js @@ -1,14 +1,13 @@ import * as Sentry from '@sentry/browser'; -const { key, enabled, user, environment } = gon.sentry || {}; +const { key, enabled, user, environment, browser } = gon.sentry || {}; // We need to check for key presence here as we do not have a dsn for browser yet if (enabled && key) { Sentry.init({ dsn: key, environment }); - if (user.email) { - Sentry.configureScope(scope => { - scope.setUser(user); - }); - } + Sentry.configureScope(scope => { + scope.setUser(user); + scope.setExtra('browser', browser.modern ? 'modern' : 'legacy'); + }); } diff --git a/app/views/gestionnaires/shared/avis/_list.html.haml b/app/views/gestionnaires/shared/avis/_list.html.haml index 23acc5a0b..c5837aac5 100644 --- a/app/views/gestionnaires/shared/avis/_list.html.haml +++ b/app/views/gestionnaires/shared/avis/_list.html.haml @@ -29,4 +29,5 @@ - else %span.waiting En attente de réponse = render partial: 'shared/piece_jointe/pj_link', locals: { object: avis, pj: avis.piece_justificative_file } - %p= avis.answer + .answer-body + = simple_format(avis.answer) diff --git a/app/views/users/dossiers/purge_champ_piece_justificative.js.erb b/app/views/users/dossiers/purge_champ_piece_justificative.js.erb index 0aae810ba..9d8807116 100644 --- a/app/views/users/dossiers/purge_champ_piece_justificative.js.erb +++ b/app/views/users/dossiers/purge_champ_piece_justificative.js.erb @@ -1,5 +1,3 @@ <%= render_flash(timeout: 5000, sticky: true) %> <%= remove_element("#piece_justificative_#{@champ.id}") %> - -let fileInputSelector = '<%= "#champs_#{@champ.id}" %>'; -document.querySelector(fileInputSelector).classList.remove('hidden'); +<%= show_element("#champs_#{@champ.id}") %> diff --git a/config/locales/fr.yml b/config/locales/fr.yml index f1a446173..c7aa81890 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -188,6 +188,7 @@ fr: connexion: "Erreur lors de la connexion à France Connect." extension_white_list_error: "Le format de fichier de la pièce jointe n'est pas valide." procedure_archived: "Cette démarche en ligne a été fermée, il n'est plus possible de déposer de dossier." + procedure_not_draft: "Cette démarche n’est maintenant plus en brouillon." cadastres_empty: one: "Aucune parcelle cadastrale sur la zone séléctionnée" other: "Aucune parcelle cadastrale sur les zones séléctionnées" diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index f07bd8737..d8070743d 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -34,7 +34,7 @@ describe ApplicationController, type: :controller do context 'when no one is logged in' do it do expect(Raven).to have_received(:user_context) - .with({ role: 'Guest' }) + .with({ id: 'Guest' }) end it do @@ -53,7 +53,7 @@ describe ApplicationController, type: :controller do it do expect(Raven).to have_received(:user_context) - .with({ id: current_user.id, role: 'User' }) + .with({ id: "User##{current_user.id}" }) end it do @@ -77,7 +77,7 @@ describe ApplicationController, type: :controller do it do expect(Raven).to have_received(:user_context) - .with({ id: current_user.id, role: 'User' }) + .with({ id: "User##{current_user.id}" }) end it do diff --git a/spec/controllers/users/commencer_controller_spec.rb b/spec/controllers/users/commencer_controller_spec.rb index ae8f2d01a..539cfaa7c 100644 --- a/spec/controllers/users/commencer_controller_spec.rb +++ b/spec/controllers/users/commencer_controller_spec.rb @@ -87,6 +87,14 @@ describe Users::CommencerController, type: :controller do it { expect(subject).to redirect_to(new_user_session_path) } end + + context 'when the path doesn’t exist' do + subject { get :sign_in, params: { path: 'hello' } } + + it 'redirects with an error message' do + expect(subject).to redirect_to(root_path) + end + end end describe '#sign_up' do @@ -111,6 +119,14 @@ describe Users::CommencerController, type: :controller do it { expect(subject).to redirect_to(new_user_registration_path) } end + + context 'when the path doesn’t exist' do + subject { get :sign_up, params: { path: 'hello' } } + + it 'redirects with an error message' do + expect(subject).to redirect_to(root_path) + end + end end describe '#france_connect' do @@ -135,5 +151,13 @@ describe Users::CommencerController, type: :controller do it { expect(subject).to redirect_to(france_connect_particulier_path) } end + + context 'when the path doesn’t exist' do + subject { get :france_connect, params: { path: 'hello' } } + + it 'redirects with an error message' do + expect(subject).to redirect_to(root_path) + end + end end end diff --git a/spec/factories/avis.rb b/spec/factories/avis.rb index 97abb989b..b7f4f556e 100644 --- a/spec/factories/avis.rb +++ b/spec/factories/avis.rb @@ -19,5 +19,9 @@ FactoryBot.define do avis.claimant = create :gestionnaire end end + + trait :with_answer do + answer { "Mon avis se décompose en deux points :\n- La demande semble pertinente\n- Le demandeur remplit les conditions." } + end end end diff --git a/spec/views/gestionnaire/shared/avis/list.html.haml_spec.rb b/spec/views/gestionnaire/shared/avis/list.html.haml_spec.rb index 1f8797785..d8abdcbe8 100644 --- a/spec/views/gestionnaire/shared/avis/list.html.haml_spec.rb +++ b/spec/views/gestionnaire/shared/avis/list.html.haml_spec.rb @@ -1,3 +1,5 @@ +require 'spec_helper' + describe 'gestionnaires/shared/avis/_list.html.haml', type: :view do before { view.extend DossierHelper } @@ -5,16 +7,22 @@ describe 'gestionnaires/shared/avis/_list.html.haml', type: :view do let(:gestionnaire) { create(:gestionnaire) } let(:avis) { [create(:avis, claimant: gestionnaire)] } + let(:seen_at) { avis.first.created_at + 1.hour } - context "with a seen_at after avis created_at" do - let(:seen_at) { avis.first.created_at + 1.hour } + it { is_expected.to have_text(avis.first.introduction) } + it { is_expected.not_to have_css(".highlighted") } - it { is_expected.not_to have_css(".highlighted") } - end - - context "with a seen_at after avis created_at" do + context 'with a seen_at before avis created_at' do let(:seen_at) { avis.first.created_at - 1.hour } it { is_expected.to have_css(".highlighted") } end + + context 'with an answer' do + let(:avis) { [create(:avis, :with_answer, claimant: gestionnaire)] } + + it 'renders the answer formatted with newlines' do + expect(subject).to include(simple_format(avis.first.answer)) + end + end end