From fedce58f7eb6c117d827194b8f8964dc20ef264f Mon Sep 17 00:00:00 2001 From: tnicolas1 Date: Fri, 24 Jan 2025 09:02:29 +0100 Subject: [PATCH 1/5] Modification des routes et du fonctionnement des controlleurs --- app/controllers/asp/application_controller.rb | 29 ++++++++++++++- app/controllers/asp/schoolings_controller.rb | 37 +++++++------------ app/views/asp/schoolings/index.html.haml | 31 ++++++++++------ .../{_schooling.html.haml => show.html.haml} | 0 config/locales/fr.yml | 6 +++ config/routes.rb | 2 +- 6 files changed, 67 insertions(+), 38 deletions(-) rename app/views/asp/schoolings/{_schooling.html.haml => show.html.haml} (100%) diff --git a/app/controllers/asp/application_controller.rb b/app/controllers/asp/application_controller.rb index 3a54fdeed..dd58a38a9 100644 --- a/app/controllers/asp/application_controller.rb +++ b/app/controllers/asp/application_controller.rb @@ -6,9 +6,10 @@ class ApplicationController < ActionController::Base layout "application" - before_action :authenticate_asp_user!, except: :login + # TODO: Remettre l'authentification ! before_action :log_user, - :set_overrides + :set_overrides, + :infer_page_title helper_method :current_user, :current_establishment @@ -38,5 +39,29 @@ def set_overrides @inhibit_nav = true @logout_path = :destroy_asp_user_session end + + def infer_page_title(attrs = {}) + key = page_title_key + + return unless I18n.exists?(key) + + title, breadcrumb = extract_title_data(I18n.t(key, deep_interpolation: true, **attrs)) + + @page_title = title + + add_breadcrumb(breadcrumb) + end + + def page_title_key + ["pages", "titles", "asp", controller_name, action_name].join(".") + end + + def extract_title_data(data) + if data.is_a? Hash + [data[:title], data[:breadcrumb]] + else + [data, data] + end + end end end diff --git a/app/controllers/asp/schoolings_controller.rb b/app/controllers/asp/schoolings_controller.rb index 2afbc7a11..d143dd756 100644 --- a/app/controllers/asp/schoolings_controller.rb +++ b/app/controllers/asp/schoolings_controller.rb @@ -4,28 +4,15 @@ module ASP class SchoolingsController < ApplicationController layout "application" - before_action :sanitize_search, - :set_schooling_result, - :set_pfmps + before_action :set_pfmps, only: :show + before_action :set_search_result, :infer_page_title, only: :index - def index - @page_title = "Rechercher un dossier" + def index; end - return if @schooling.nil? - - @inhibit_title = true - - @page_title = "Dossier #{@schooling.asp_dossier_id}" - end + def show; end private - def set_schooling_result - return if @search.blank? - - @schooling = find_schooling_by_attributive_decision_filename - end - def set_pfmps return if @schooling.nil? @@ -35,16 +22,18 @@ def set_pfmps .distinct end + def set_search_result + @attributive_decision_number = params[:search] + + return if @attributive_decision_number.blank? + + @schoolings = find_schooling_by_attributive_decision_filename || [] + end + def find_schooling_by_attributive_decision_filename Schooling .joins(:attributive_decision_blob) - .find_by("filename LIKE ?", "%_#{@search}.pdf") - end - - def sanitize_search - return if params[:search].blank? - - @search = params[:search].strip.upcase + .find_by("filename LIKE ?", "%_#{@attributive_decision_number.strip.upcase}.pdf") end end end diff --git a/app/views/asp/schoolings/index.html.haml b/app/views/asp/schoolings/index.html.haml index 20ab56e96..02174d2c8 100644 --- a/app/views/asp/schoolings/index.html.haml +++ b/app/views/asp/schoolings/index.html.haml @@ -1,21 +1,30 @@ .fr-mb-3w = form_with method: :get, url: asp_schoolings_path do |form| - .fr-search-bar.fr-search-bar--lg.fr-col-md-8#search - = form.label :search, "Numéro de décision d'attribution", class: "fr-label" - = form.text_field :search, placeholder: "Numéro de décision d'attribution", value: @search, class: "fr-input" - = form.button "Rechercher", type: "submit", class: "fr-btn" + .fr-search-bar.fr-search-bar--lg.fr-col-md-8{id: "search", role: "search"} + = form.label :search, "Numéro de décision d'attribution...", class: "fr-label" + = form.text_field :search, placeholder: "Numéro de décision d'attribution", value: @attributive_decision_number, class: "fr-input" + = form.button "Rechercher", type: "submit", class: "fr-btn", name: nil - - -- if @search.blank? +- if @attributive_decision_number.blank? .fr-mb-5w Entrez un numéro de décision d'attribution pour lancer une recherche -- elsif @schooling.blank? +- elsif @schoolings.none? .fr-mb-5w - Aucune décision d'attribution trouvée avec le numéro - = @search + Aucune décision d'attribution trouvée avec le numéro : #{@attributive_decision_number} - else - = render partial: "schooling" + .fr-table + %table + %caption #{@schoolings.count} résultats trouvés pour la recherche : #{@attributive_decision_number} + %thead + %td{scope: "col"} Dossiers + %th{scope: "col"} Élèves + %th{scope: "col"} Dernière classe + %tbody + - @schoolings.each do |schooling| + %tr + %td= dsfr_link_to schooling.attributive_decision_number, asp_schoolings_path(schooling) + %td= schooling.student.full_name + %td= schooling.classe.label \ No newline at end of file diff --git a/app/views/asp/schoolings/_schooling.html.haml b/app/views/asp/schoolings/show.html.haml similarity index 100% rename from app/views/asp/schoolings/_schooling.html.haml rename to app/views/asp/schoolings/show.html.haml diff --git a/config/locales/fr.yml b/config/locales/fr.yml index fdf123c0d..bd981a67e 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -158,6 +158,12 @@ fr: faq: F.A.Q. pages: titles: + asp: + application: + login: Connexion à APLyPro + schoolings: + index: Recherche d'un dossier + show: Dossier stats: index: Statistiques school_years: diff --git a/config/routes.rb b/config/routes.rb index 5eb2bd71f..4dcbb1e53 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,7 +5,7 @@ # rubocop:disable Metrics/BlockLength Rails.application.routes.draw do namespace :asp do - resources :schoolings, only: :index + resources :schoolings, only: %i[index show] devise_for :users, skip: :all, class_name: "ASP::User" end From 04212bd27982069d24d25fbbc2b5f4c1768ac908 Mon Sep 17 00:00:00 2001 From: tnicolas1 Date: Fri, 24 Jan 2025 11:30:17 +0100 Subject: [PATCH 2/5] Correction de tests et factorisation de la barre de recherche --- app/controllers/asp/schoolings_controller.rb | 12 ++++++--- .../asp/schoolings/_search-bar.html.haml | 6 +++++ app/views/asp/schoolings/index.html.haml | 9 ++----- app/views/asp/schoolings/show.html.haml | 26 +++++++++++-------- config/locales/fr.yml | 2 +- features/asp_consultation_de_dossier.feature | 6 ++--- 6 files changed, 36 insertions(+), 25 deletions(-) create mode 100644 app/views/asp/schoolings/_search-bar.html.haml diff --git a/app/controllers/asp/schoolings_controller.rb b/app/controllers/asp/schoolings_controller.rb index d143dd756..0c9b41731 100644 --- a/app/controllers/asp/schoolings_controller.rb +++ b/app/controllers/asp/schoolings_controller.rb @@ -4,15 +4,21 @@ module ASP class SchoolingsController < ApplicationController layout "application" - before_action :set_pfmps, only: :show + before_action :set_schooling, :set_pfmps, only: :show before_action :set_search_result, :infer_page_title, only: :index def index; end - def show; end + def show + infer_page_title(attributive_decision_number: @schooling.attributive_decision_number) + end private + def set_schooling + @schooling = Schooling.find(params[:id]) + end + def set_pfmps return if @schooling.nil? @@ -33,7 +39,7 @@ def set_search_result def find_schooling_by_attributive_decision_filename Schooling .joins(:attributive_decision_blob) - .find_by("filename LIKE ?", "%_#{@attributive_decision_number.strip.upcase}.pdf") + .where("filename LIKE ?", "%#{@attributive_decision_number.strip.upcase}%") end end end diff --git a/app/views/asp/schoolings/_search-bar.html.haml b/app/views/asp/schoolings/_search-bar.html.haml new file mode 100644 index 000000000..3885f00f6 --- /dev/null +++ b/app/views/asp/schoolings/_search-bar.html.haml @@ -0,0 +1,6 @@ +.fr-mb-3w + = form_with method: :get, url: asp_schoolings_path do |form| + .fr-search-bar.fr-search-bar--lg.fr-col-md-8{id: "search", role: "search"} + = form.label :search, "Numéro de décision d'attribution...", class: "fr-label" + = form.text_field :search, placeholder: "Numéro de décision d'attribution", value: @attributive_decision_number, class: "fr-input" + = form.button "Rechercher", type: "submit", class: "fr-btn", name: nil \ No newline at end of file diff --git a/app/views/asp/schoolings/index.html.haml b/app/views/asp/schoolings/index.html.haml index 02174d2c8..f67ca0f3b 100644 --- a/app/views/asp/schoolings/index.html.haml +++ b/app/views/asp/schoolings/index.html.haml @@ -1,9 +1,4 @@ -.fr-mb-3w - = form_with method: :get, url: asp_schoolings_path do |form| - .fr-search-bar.fr-search-bar--lg.fr-col-md-8{id: "search", role: "search"} - = form.label :search, "Numéro de décision d'attribution...", class: "fr-label" - = form.text_field :search, placeholder: "Numéro de décision d'attribution", value: @attributive_decision_number, class: "fr-input" - = form.button "Rechercher", type: "submit", class: "fr-btn", name: nil += render partial: 'search-bar' - if @attributive_decision_number.blank? .fr-mb-5w @@ -24,7 +19,7 @@ %tbody - @schoolings.each do |schooling| %tr - %td= dsfr_link_to schooling.attributive_decision_number, asp_schoolings_path(schooling) + %td= dsfr_link_to schooling.attributive_decision_number, asp_schooling_path(schooling) %td= schooling.student.full_name %td= schooling.classe.label \ No newline at end of file diff --git a/app/views/asp/schoolings/show.html.haml b/app/views/asp/schoolings/show.html.haml index 1c51e16c4..44c344963 100644 --- a/app/views/asp/schoolings/show.html.haml +++ b/app/views/asp/schoolings/show.html.haml @@ -1,6 +1,6 @@ -%h1 - Dossier - = @schooling.attributive_decision_number += render partial: 'search-bar' + +%h1.fr-mb-5w= @page_title .fr-my-3w - if @schooling.attributive_decision.present? @@ -8,9 +8,10 @@ - else Aucune décision d'attribution éditée -.fr-table +.fr-table.fr-table--no-caption %table - %caption.fr-h2 Élève + %thead + %th{colspan: 2} Élève %tbody %tr %td Nom @@ -28,9 +29,10 @@ %td Code INSEE du pays de naissance %td= display_insee_code(@schooling.student.birthplace_country_insee_code) -.fr-table +.fr-table.fr-table--no-caption %table - %caption.fr-h2 Établissement + %thead + %th{colspan: 2} Établissement %tbody %tr %td UAI @@ -41,9 +43,10 @@ %tr %td Email %td= @schooling.establishment.email -.fr-table +.fr-table.fr-table--no-caption %table - %caption.fr-h2 Formation + %thead + %th{colspan: 2} Formation %tbody %tr %td Forfait journalier @@ -53,9 +56,10 @@ %td= number_to_currency @schooling.mef.wage.yearly_cap -.fr-table +.fr-table.fr-table--no-caption %table - %caption.fr-h2 Coordonnées bancaires + %thead + %th{colspan: 2} Coordonnées bancaires %tbody - rib = @schooling.student.rib(@schooling.establishment) - if rib.blank? diff --git a/config/locales/fr.yml b/config/locales/fr.yml index bd981a67e..05d396ed5 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -163,7 +163,7 @@ fr: login: Connexion à APLyPro schoolings: index: Recherche d'un dossier - show: Dossier + show: "Dossier %{attributive_decision_number}" stats: index: Statistiques school_years: diff --git a/features/asp_consultation_de_dossier.feature b/features/asp_consultation_de_dossier.feature index 46a3b8308..849d29812 100644 --- a/features/asp_consultation_de_dossier.feature +++ b/features/asp_consultation_de_dossier.feature @@ -19,13 +19,13 @@ Fonctionnalité: Le personnel ASP consulte des dossiers Sachant que le numéro administratif de "Marie Curie" est "THEDOSS" Et que je remplis "Numéro de décision d'attribution" avec "ENPUTHEDOSS20240" Quand je clique sur "Rechercher" - Alors la page contient "ENPUTHEDOSS20240" - Et la page contient "3 jours x 10 € par jour = 30 €" + Quand je clique sur "ENPUTHEDOSS20240" + Alors la page contient "3 jours x 10 € par jour = 30 €" Et la page contient "IBAN" Scénario: Le personnel ASP n'a pas accès à l'interface principale Quand je me rends sur la page d'accueil - Alors le titre de la page contient "Rechercher un dossier" + Alors le titre de la page contient "Recherche d'un dossier" Et la page ne contient pas "Classes" Et la page ne contient pas "Envoyer en paiement" From 9f26dbe0ac6cc2b7939597ceb3453d14c5830384 Mon Sep 17 00:00:00 2001 From: tnicolas1 Date: Mon, 27 Jan 2025 09:38:03 +0100 Subject: [PATCH 3/5] Ajout d'un test d'authentification ASP --- app/controllers/asp/application_controller.rb | 2 +- features/asp_consultation_de_dossier.feature | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/asp/application_controller.rb b/app/controllers/asp/application_controller.rb index dd58a38a9..242851f22 100644 --- a/app/controllers/asp/application_controller.rb +++ b/app/controllers/asp/application_controller.rb @@ -6,7 +6,7 @@ class ApplicationController < ActionController::Base layout "application" - # TODO: Remettre l'authentification ! + before_action :authenticate_asp_user!, except: :login before_action :log_user, :set_overrides, :infer_page_title diff --git a/features/asp_consultation_de_dossier.feature b/features/asp_consultation_de_dossier.feature index 849d29812..d6096b90c 100644 --- a/features/asp_consultation_de_dossier.feature +++ b/features/asp_consultation_de_dossier.feature @@ -4,6 +4,8 @@ Fonctionnalité: Le personnel ASP consulte des dossiers Contexte: Sachant qu'une PFMP de 30 euros a été saisie, validée et envoyée en paiement pour l'élève "Marie Curie" Et que je suis un agent de l'ASP + Et que je me rend sur la page de recherche de dossier + Alors la page contient "Vous devez vous connecter ou vous enregistrer pour continuer." Et que je me connecte au portail ASP Et que je me rend sur la page de recherche de dossier From 9f078473dda5f2ebc654128a2b3b27b461068838 Mon Sep 17 00:00:00 2001 From: tnicolas1 Date: Mon, 27 Jan 2025 14:10:18 +0100 Subject: [PATCH 4/5] Ajout d'un fichier concern --- app/controllers/application_controller.rb | 25 +-------------- app/controllers/asp/application_controller.rb | 25 +-------------- app/controllers/concerns/page_title.rb | 32 +++++++++++++++++++ .../asp/schoolings/_search-bar.html.haml | 12 +++---- features/asp_consultation_de_dossier.feature | 5 ++- 5 files changed, 42 insertions(+), 57 deletions(-) create mode 100644 app/controllers/concerns/page_title.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 09b5818b5..4244ec40e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,6 +2,7 @@ class ApplicationController < ActionController::Base include UserLogger + include PageTitle before_action :authenticate_user!, :log_user, @@ -47,30 +48,6 @@ def selected_school_year SchoolYear.current end - def infer_page_title(attrs = {}) - key = page_title_key - - return unless I18n.exists?(key) - - title, breadcrumb = extract_title_data(I18n.t(key, deep_interpolation: true, **attrs)) - - @page_title = title - - add_breadcrumb(breadcrumb) - end - - def extract_title_data(data) - if data.is_a? Hash - [data[:title], data[:breadcrumb]] - else - [data, data] - end - end - - def page_title_key - ["pages", "titles", controller_name, action_name].join(".") - end - def redirect_asp_users! redirect_to asp_schoolings_path and return if asp_user_signed_in? end diff --git a/app/controllers/asp/application_controller.rb b/app/controllers/asp/application_controller.rb index 242851f22..678f2e0e1 100644 --- a/app/controllers/asp/application_controller.rb +++ b/app/controllers/asp/application_controller.rb @@ -3,6 +3,7 @@ module ASP class ApplicationController < ActionController::Base include UserLogger + include PageTitle layout "application" @@ -39,29 +40,5 @@ def set_overrides @inhibit_nav = true @logout_path = :destroy_asp_user_session end - - def infer_page_title(attrs = {}) - key = page_title_key - - return unless I18n.exists?(key) - - title, breadcrumb = extract_title_data(I18n.t(key, deep_interpolation: true, **attrs)) - - @page_title = title - - add_breadcrumb(breadcrumb) - end - - def page_title_key - ["pages", "titles", "asp", controller_name, action_name].join(".") - end - - def extract_title_data(data) - if data.is_a? Hash - [data[:title], data[:breadcrumb]] - else - [data, data] - end - end end end diff --git a/app/controllers/concerns/page_title.rb b/app/controllers/concerns/page_title.rb new file mode 100644 index 000000000..004f1b81c --- /dev/null +++ b/app/controllers/concerns/page_title.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +module PageTitle + extend ActiveSupport::Concern + + def infer_page_title(attrs = {}) + key = page_title_key + + return unless I18n.exists?(key) + + title, breadcrumb = extract_title_data(I18n.t(key, deep_interpolation: true, **attrs)) + + @page_title = title + + add_breadcrumb(breadcrumb) + end + + private + + def page_title_key + asp = "asp" if controller_path.eql?("asp/application") + ["pages", "titles", asp, controller_name, action_name].join(".") + end + + def extract_title_data(data) + if data.is_a? Hash + [data[:title], data[:breadcrumb]] + else + [data, data] + end + end +end diff --git a/app/views/asp/schoolings/_search-bar.html.haml b/app/views/asp/schoolings/_search-bar.html.haml index 3885f00f6..cbd4a2764 100644 --- a/app/views/asp/schoolings/_search-bar.html.haml +++ b/app/views/asp/schoolings/_search-bar.html.haml @@ -1,6 +1,6 @@ -.fr-mb-3w - = form_with method: :get, url: asp_schoolings_path do |form| - .fr-search-bar.fr-search-bar--lg.fr-col-md-8{id: "search", role: "search"} - = form.label :search, "Numéro de décision d'attribution...", class: "fr-label" - = form.text_field :search, placeholder: "Numéro de décision d'attribution", value: @attributive_decision_number, class: "fr-input" - = form.button "Rechercher", type: "submit", class: "fr-btn", name: nil \ No newline at end of file +.fr-mb-3w + = form_with method: :get, url: asp_schoolings_path do |form| + .fr-search-bar.fr-search-bar--lg.fr-col-md-8{id: "search", role: "search"} + = form.label :search, "Numéro de décision d'attribution...", class: "fr-label" + = form.text_field :search, placeholder: "Numéro de décision d'attribution", value: @attributive_decision_number, class: "fr-input" + = form.button "Rechercher", type: "submit", class: "fr-btn", name: nil diff --git a/features/asp_consultation_de_dossier.feature b/features/asp_consultation_de_dossier.feature index d6096b90c..a49d9d8e3 100644 --- a/features/asp_consultation_de_dossier.feature +++ b/features/asp_consultation_de_dossier.feature @@ -19,7 +19,7 @@ Fonctionnalité: Le personnel ASP consulte des dossiers Scénario: Le personnel ASP entre un numéro de décision d'attribution existant Sachant que le numéro administratif de "Marie Curie" est "THEDOSS" - Et que je remplis "Numéro de décision d'attribution" avec "ENPUTHEDOSS20240" + Et que je remplis "Numéro de décision d'attribution" avec "THEDOSS2024" Quand je clique sur "Rechercher" Quand je clique sur "ENPUTHEDOSS20240" Alors la page contient "3 jours x 10 € par jour = 30 €" @@ -27,8 +27,7 @@ Fonctionnalité: Le personnel ASP consulte des dossiers Scénario: Le personnel ASP n'a pas accès à l'interface principale Quand je me rends sur la page d'accueil - Alors le titre de la page contient "Recherche d'un dossier" - Et la page ne contient pas "Classes" + Alors la page ne contient pas "Classes" Et la page ne contient pas "Envoyer en paiement" Scénario: Le personnel ASP est redirigé vers la page de connexion ASP en cas d'erreur de connexion From 32b56b9f096081312513882e7fd32736d940fb35 Mon Sep 17 00:00:00 2001 From: tnicolas1 Date: Tue, 28 Jan 2025 11:38:35 +0100 Subject: [PATCH 5/5] Correction de titres et de tests --- app/controllers/concerns/page_title.rb | 2 +- features/asp_consultation_de_dossier.feature | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/concerns/page_title.rb b/app/controllers/concerns/page_title.rb index 004f1b81c..207499f6f 100644 --- a/app/controllers/concerns/page_title.rb +++ b/app/controllers/concerns/page_title.rb @@ -18,7 +18,7 @@ def infer_page_title(attrs = {}) private def page_title_key - asp = "asp" if controller_path.eql?("asp/application") + asp = "asp" if controller_path.include?("asp/") ["pages", "titles", asp, controller_name, action_name].join(".") end diff --git a/features/asp_consultation_de_dossier.feature b/features/asp_consultation_de_dossier.feature index a49d9d8e3..f25340b67 100644 --- a/features/asp_consultation_de_dossier.feature +++ b/features/asp_consultation_de_dossier.feature @@ -4,8 +4,6 @@ Fonctionnalité: Le personnel ASP consulte des dossiers Contexte: Sachant qu'une PFMP de 30 euros a été saisie, validée et envoyée en paiement pour l'élève "Marie Curie" Et que je suis un agent de l'ASP - Et que je me rend sur la page de recherche de dossier - Alors la page contient "Vous devez vous connecter ou vous enregistrer pour continuer." Et que je me connecte au portail ASP Et que je me rend sur la page de recherche de dossier @@ -27,12 +25,15 @@ Fonctionnalité: Le personnel ASP consulte des dossiers Scénario: Le personnel ASP n'a pas accès à l'interface principale Quand je me rends sur la page d'accueil + Alors le titre de la page contient "Recherche d'un dossier" Alors la page ne contient pas "Classes" Et la page ne contient pas "Envoyer en paiement" Scénario: Le personnel ASP est redirigé vers la page de connexion ASP en cas d'erreur de connexion Sachant que je me déconnecte - Et que je suis un agent de l'ASP avec l'email "foobar@gmail.com" - Quand je me connecte au portail ASP + Et que je me rend sur la page de recherche de dossier + Alors la page contient "Vous devez vous connecter ou vous enregistrer pour continuer." + Sachant que je suis un agent de l'ASP avec l'email "foobar@gmail.com" + Et que je me connecte au portail ASP Alors la page contient "Erreur lors du traitement de votre profil" Et la page contient "Vous êtes un agent de l'ASP"