From fcb478eb53d55cd94eadd49ee0595157681646b4 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 14 Sep 2022 16:19:14 +0200 Subject: [PATCH] refactor(fc_info): use Dsfr::Notice for france connect informations --- .../france-connect-informations.scss | 12 ------ app/helpers/dossier_helper.rb | 12 ++++++ app/views/layouts/_header.haml | 3 ++ app/views/layouts/application.html.haml | 1 + app/views/shared/dossiers/_demande.html.haml | 7 ++-- app/views/shared/dossiers/_edit.html.haml | 7 ++-- .../_france_connect_informations.html.haml | 13 ------ ...ance_connect_informations_notice.html.haml | 3 ++ config/locales/fr.yml | 4 -- config/locales/shared.en.yml | 4 ++ config/locales/shared.fr.yml | 4 ++ spec/helpers/dossier_helper_spec.rb | 36 +++++++++++++++++ .../dossiers/show.html.haml_spec.rb | 2 +- ...ance_connect_information.html.haml_spec.rb | 40 ------------------- .../users/dossiers/demande.html.haml_spec.rb | 2 +- 15 files changed, 73 insertions(+), 77 deletions(-) delete mode 100644 app/assets/stylesheets/france-connect-informations.scss delete mode 100644 app/views/shared/dossiers/_france_connect_informations.html.haml create mode 100644 app/views/shared/dossiers/_france_connect_informations_notice.html.haml delete mode 100644 spec/views/shared/dossiers/_france_connect_information.html.haml_spec.rb diff --git a/app/assets/stylesheets/france-connect-informations.scss b/app/assets/stylesheets/france-connect-informations.scss deleted file mode 100644 index 739c9734f..000000000 --- a/app/assets/stylesheets/france-connect-informations.scss +++ /dev/null @@ -1,12 +0,0 @@ -@import "constants"; - -.france-connect-informations.card { - width: 100%; - padding-top: $default-spacer; - padding-bottom: $default-spacer; -} - -.france-connect-informations-logo img { - width: 100px; - margin-right: $default-padding; -} diff --git a/app/helpers/dossier_helper.rb b/app/helpers/dossier_helper.rb index 61496b0cf..fc18c15d2 100644 --- a/app/helpers/dossier_helper.rb +++ b/app/helpers/dossier_helper.rb @@ -115,4 +115,16 @@ module DossierHelper end end end + + def france_connect_informations(user_information) + if user_information.full_name.empty? + t("shared.dossiers.france_connect_informations.details_no_name") + elsif user_information.updated_at.present? + t("shared.dossiers.france_connect_informations.details_updated", + name: user_information.full_name, + date: l(user_information.updated_at.to_date, format: :default)) + else + t("shared.dossiers.france_connect_informations.details", name: user_information.full_name) + end + end end diff --git a/app/views/layouts/_header.haml b/app/views/layouts/_header.haml index 474b1f2eb..5bbe9d008 100644 --- a/app/views/layouts/_header.haml +++ b/app/views/layouts/_header.haml @@ -100,3 +100,6 @@ %li.fr-nav__item= active_link_to t('.files'), dossiers_path, active: :inclusive, class: 'fr-nav__link' - if current_user.expert && current_expert.avis_summary[:total] > 0 = render partial: 'layouts/header/avis_tab', locals: { current_expert: current_expert } + += yield(:notice_info) + diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index a35632fe2..742c6e85a 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -48,6 +48,7 @@ = render partial: "layouts/header" %main{ role: :main } = render partial: "layouts/flash_messages" + = content_for?(:content) ? yield(:content) : yield - if content_for?(:footer) diff --git a/app/views/shared/dossiers/_demande.html.haml b/app/views/shared/dossiers/_demande.html.haml index 28e9836bd..3f7957e23 100644 --- a/app/views/shared/dossiers/_demande.html.haml +++ b/app/views/shared/dossiers/_demande.html.haml @@ -1,3 +1,7 @@ +- if dossier.france_connect_information.present? + - content_for(:notice_info) do + = render partial: "shared/dossiers/france_connect_informations_notice", locals: { user_information: dossier.france_connect_information } + .container - if dossier.depose_at.present? .card @@ -11,9 +15,6 @@ modifié le = try_format_datetime(dossier.identity_updated_at) - - if dossier.france_connect_information.present? - = render partial: "shared/dossiers/france_connect_informations", locals: { user_information: dossier.france_connect_information } - .card = render partial: "shared/dossiers/user_infos", locals: { user_deleted: dossier.user_deleted?, email: dossier.user_email_for(:display) } diff --git a/app/views/shared/dossiers/_edit.html.haml b/app/views/shared/dossiers/_edit.html.haml index 4205b54ee..1eced6ae7 100644 --- a/app/views/shared/dossiers/_edit.html.haml +++ b/app/views/shared/dossiers/_edit.html.haml @@ -1,3 +1,7 @@ +- if dossier.france_connect_information.present? + - content_for(:notice_info) do + = render partial: "shared/dossiers/france_connect_informations_notice", locals: { user_information: dossier.france_connect_information } + .dossier-edit.container = render partial: "shared/dossiers/submit_is_over", locals: { dossier: dossier } @@ -22,9 +26,6 @@ class: "fr-btn fr-btn--secondary mt-2", title: t("views.shared.dossiers.edit.notice_title"), **external_link_attributes - - if dossier.france_connect_information.present? - = render partial: "shared/dossiers/france_connect_informations", locals: { user_information: dossier.france_connect_information } - - if dossier.show_groupe_instructeur_selector? %span{ data: { controller: 'autosave' } } = f.label :groupe_instructeur_id do diff --git a/app/views/shared/dossiers/_france_connect_informations.html.haml b/app/views/shared/dossiers/_france_connect_informations.html.haml deleted file mode 100644 index 81378ad1d..000000000 --- a/app/views/shared/dossiers/_france_connect_informations.html.haml +++ /dev/null @@ -1,13 +0,0 @@ -.fr-tile.fr-tile--horizontal.mb-4 - .fr-tile__body - %h4.fr-tile__title - FranceConnect - %p - - if user_information.full_name.empty? - = t("views.shared.dossiers.france_connect_informations.details_no_name") - - elsif user_information.updated_at.present? - = t("views.shared.dossiers.france_connect_informations.details_updated", name: user_information.full_name, date: l(user_information.updated_at.to_date, format: :default)) - - else - = t("views.shared.dossiers.france_connect_informations.details", name: user_information.full_name) - .fr-tile__img - = image_tag "logo-france-connect.png", alt: "", class: "fr-responsive-img" diff --git a/app/views/shared/dossiers/_france_connect_informations_notice.html.haml b/app/views/shared/dossiers/_france_connect_informations_notice.html.haml new file mode 100644 index 000000000..d283af0d3 --- /dev/null +++ b/app/views/shared/dossiers/_france_connect_informations_notice.html.haml @@ -0,0 +1,3 @@ += render Dsfr::NoticeComponent.new(closable: true) do |c| + - c.with_title do + = france_connect_informations(user_information) diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 3ac131bb1..768c715d1 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -145,10 +145,6 @@ fr: form: "Formulaire" edit_siret: "Modifier le SIRET" edit_identity: "Modifier l’identité" - france_connect_informations: - details_no_name: "Le dossier a été déposé par un compte FranceConnect." - details: "Le dossier a été déposé par le compte de %{name}." - details_updated: "Le dossier a été déposé par le compte de %{name}, authentifié par FranceConnect le %{date}." instructeurs: dossiers: tab_steps: diff --git a/config/locales/shared.en.yml b/config/locales/shared.en.yml index 1276e41a5..a718d09a5 100644 --- a/config/locales/shared.en.yml +++ b/config/locales/shared.en.yml @@ -1,6 +1,10 @@ en: shared: dossiers: + france_connect_informations: + details_no_name: "The file was submitted by a FranceConnect account." + details: "The file was submitted by the account of %{name}." + details_updated: "The file was submitted by the account of %{name}, authenticated by FranceConnect on %{date}." header: expires_at: brouillon: "Expires on %{date} (%{duree_conservation_totale} months after this file was created)" diff --git a/config/locales/shared.fr.yml b/config/locales/shared.fr.yml index 1b055183d..16bfeb13b 100644 --- a/config/locales/shared.fr.yml +++ b/config/locales/shared.fr.yml @@ -1,6 +1,10 @@ fr: shared: dossiers: + france_connect_informations: + details_no_name: "Le dossier a été déposé par un compte FranceConnect." + details: "Le dossier a été déposé par le compte de %{name}." + details_updated: "Le dossier a été déposé par le compte de %{name}, authentifié par FranceConnect le %{date}." header: expires_at: brouillon: "Expirera le %{date} (%{duree_conservation_totale} mois après la création du dossier)" diff --git a/spec/helpers/dossier_helper_spec.rb b/spec/helpers/dossier_helper_spec.rb index 9835cba2d..72dcc91b6 100644 --- a/spec/helpers/dossier_helper_spec.rb +++ b/spec/helpers/dossier_helper_spec.rb @@ -215,4 +215,40 @@ RSpec.describe DossierHelper, type: :helper do it { is_expected.to eq('without_continuation') } end end + + describe ".france_connect_information" do + subject { france_connect_informations(user_information) } + + context "with complete france_connect information" do + let(:user_information) { build(:france_connect_information, updated_at: Time.zone.now) } + it { + expect(subject).to have_text("Le dossier a été déposé par le compte de #{user_information.given_name} #{user_information.family_name}, authentifié par FranceConnect le #{user_information.updated_at.strftime('%d/%m/%Y')}") + } + end + + context "with missing updated_at" do + let(:user_information) { build(:france_connect_information, updated_at: nil) } + + it { + expect(subject).to have_text("Le dossier a été déposé par le compte de #{user_information.given_name} #{user_information.family_name}") + expect(subject).not_to have_text("authentifié par FranceConnect le ") + } + end + + context "with missing given_name" do + let(:user_information) { build(:france_connect_information, given_name: nil) } + + it { + expect(subject).to have_text("Le dossier a été déposé par le compte de #{user_information.family_name}") + } + end + + context "with all names missing" do + let(:user_information) { build(:france_connect_information, given_name: nil, family_name: nil) } + + it { + expect(subject).to have_text("Le dossier a été déposé par un compte FranceConnect.") + } + end + end end diff --git a/spec/views/instructeur/dossiers/show.html.haml_spec.rb b/spec/views/instructeur/dossiers/show.html.haml_spec.rb index 15be1e83f..a7aea8390 100644 --- a/spec/views/instructeur/dossiers/show.html.haml_spec.rb +++ b/spec/views/instructeur/dossiers/show.html.haml_spec.rb @@ -30,7 +30,7 @@ describe 'instructeurs/dossiers/show.html.haml', type: :view do end it 'fills the individual with the informations from France Connect' do - expect(rendered).to have_text("Le dossier a été déposé par le compte de #{france_connect_information.given_name} #{france_connect_information.family_name}, authentifié par FranceConnect le #{france_connect_information.updated_at.strftime('%d/%m/%Y')}") + expect(view.content_for(:notice_info)).to have_text("Le dossier a été déposé par le compte de #{france_connect_information.given_name} #{france_connect_information.family_name}, authentifié par FranceConnect le #{france_connect_information.updated_at.strftime('%d/%m/%Y')}") end end end diff --git a/spec/views/shared/dossiers/_france_connect_information.html.haml_spec.rb b/spec/views/shared/dossiers/_france_connect_information.html.haml_spec.rb deleted file mode 100644 index 19de91cdd..000000000 --- a/spec/views/shared/dossiers/_france_connect_information.html.haml_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -describe 'shared/dossiers/france_connect_informations.html.haml', type: :view do - subject do - render( - 'shared/dossiers/france_connect_informations.html.haml', - user_information: user_information - ) - end - - context "with complete france_connect information" do - let(:user_information) { build(:france_connect_information, updated_at: Time.zone.now) } - it { - expect(subject).to have_text("Le dossier a été déposé par le compte de #{user_information.given_name} #{user_information.family_name}, authentifié par FranceConnect le #{user_information.updated_at.strftime('%d/%m/%Y')}") - } - end - - context "with missing updated_at" do - let(:user_information) { build(:france_connect_information, updated_at: nil) } - - it { - expect(subject).to have_text("Le dossier a été déposé par le compte de #{user_information.given_name} #{user_information.family_name}") - expect(subject).not_to have_text("authentifié par FranceConnect le ") - } - end - - context "with missing given_name" do - let(:user_information) { build(:france_connect_information, given_name: nil) } - - it { - expect(subject).to have_text("Le dossier a été déposé par le compte de #{user_information.family_name}") - } - end - - context "with all names missing" do - let(:user_information) { build(:france_connect_information, given_name: nil, family_name: nil) } - - it { - expect(subject).to have_text("Le dossier a été déposé par un compte FranceConnect.") - } - end -end diff --git a/spec/views/users/dossiers/demande.html.haml_spec.rb b/spec/views/users/dossiers/demande.html.haml_spec.rb index 15dce5776..a87d710b0 100644 --- a/spec/views/users/dossiers/demande.html.haml_spec.rb +++ b/spec/views/users/dossiers/demande.html.haml_spec.rb @@ -45,7 +45,7 @@ describe 'users/dossiers/demande.html.haml', type: :view do end it 'fills the individual with the informations from France Connect' do - expect(rendered).to have_text("Le dossier a été déposé par le compte de #{france_connect_information.given_name} #{france_connect_information.family_name}, authentifié par FranceConnect le #{france_connect_information.updated_at.strftime('%d/%m/%Y')}") + expect(view.content_for(:notice_info)).to have_text("Le dossier a été déposé par le compte de #{france_connect_information.given_name} #{france_connect_information.family_name}, authentifié par FranceConnect le #{france_connect_information.updated_at.strftime('%d/%m/%Y')}") end end end