From ac834b0c0a09e142b456c1cf78e5231957b22ddb Mon Sep 17 00:00:00 2001 From: Lisa Durand Date: Mon, 6 Nov 2023 17:46:22 +0100 Subject: [PATCH] add confirmation page after publishing procedure for admin --- .../administrateurs/procedures_controller.rb | 30 +++++++++++-------- .../procedures/confirmation.html.haml | 23 ++++++++++++++ .../administrateurs/procedures/show.html.haml | 5 +++- .../views/administrateurs/procedures/en.yml | 4 +++ .../views/administrateurs/procedures/fr.yml | 4 +++ config/routes.rb | 2 ++ .../procedures_controller_spec.rb | 10 +++---- .../procedure_attestation_template_spec.rb | 1 + .../administrateurs/procedure_publish_spec.rb | 7 +++-- .../api_particulier/api_particulier_spec.rb | 2 +- .../routing/rules_full_scenario_spec.rb | 2 +- 11 files changed, 65 insertions(+), 25 deletions(-) create mode 100644 app/views/administrateurs/procedures/confirmation.html.haml diff --git a/app/controllers/administrateurs/procedures_controller.rb b/app/controllers/administrateurs/procedures_controller.rb index f7e8c44ac..b4e70ca84 100644 --- a/app/controllers/administrateurs/procedures_controller.rb +++ b/app/controllers/administrateurs/procedures_controller.rb @@ -3,7 +3,7 @@ module Administrateurs layout 'all', only: [:all, :administrateurs] respond_to :html, :xlsx - before_action :retrieve_procedure, only: [:champs, :annotations, :modifications, :edit, :zones, :monavis, :update_monavis, :jeton, :update_jeton, :publication, :publish, :transfert, :close, :allow_expert_review, :allow_expert_messaging, :experts_require_administrateur_invitation, :reset_draft] + before_action :retrieve_procedure, only: [:champs, :annotations, :modifications, :edit, :zones, :monavis, :update_monavis, :jeton, :update_jeton, :publication, :publish, :transfert, :close, :confirmation, :allow_expert_review, :allow_expert_messaging, :experts_require_administrateur_invitation, :reset_draft, :publish_revision] before_action :draft_valid?, only: [:apercu] after_action :reset_procedure, only: [:update] @@ -277,18 +277,10 @@ module Administrateurs def publish @procedure.assign_attributes(publish_params) + @procedure.publish_or_reopen!(current_administrateur) + if @procedure.draft_changed? - if @procedure.close? - if @procedure.publish_or_reopen!(current_administrateur) - @procedure.publish_revision! - flash.notice = "Démarche publiée" - end - else - @procedure.publish_revision! - flash.notice = "Nouvelle version de la démarche publiée" - end - elsif @procedure.publish_or_reopen!(current_administrateur) - flash.notice = "Démarche publiée" + @procedure.publish_revision! end if params[:old_procedure].present? && @procedure.errors.empty? @@ -300,7 +292,7 @@ module Administrateurs .update!(replaced_by_procedure: @procedure) end - redirect_to admin_procedure_path(@procedure) + redirect_to admin_procedure_confirmation_path(@procedure) rescue ActiveRecord::RecordInvalid flash.alert = @procedure.errors.full_messages redirect_to admin_procedure_publication_path(@procedure) @@ -312,12 +304,24 @@ module Administrateurs redirect_to admin_procedure_path(@procedure) end + def publish_revision + if @procedure.draft_changed? + @procedure.publish_revision! + flash.notice = "Nouvelle version de la démarche publiée" + + redirect_to admin_procedure_path(@procedure) + end + end + def transfert end def close end + def confirmation + end + def allow_expert_review @procedure.update!(allow_expert_review: !@procedure.allow_expert_review) flash.notice = @procedure.allow_expert_review? ? "Avis externes activés" : "Avis externes désactivés" diff --git a/app/views/administrateurs/procedures/confirmation.html.haml b/app/views/administrateurs/procedures/confirmation.html.haml new file mode 100644 index 000000000..13c2b2538 --- /dev/null +++ b/app/views/administrateurs/procedures/confirmation.html.haml @@ -0,0 +1,23 @@ += render partial: 'administrateurs/breadcrumbs', + locals: { steps: [['Démarches', admin_procedures_back_path(@procedure)], + [@procedure.libelle.truncate_words(10), admin_procedure_path(@procedure)], + ['Confirmation']] } + +.fr-container + .fr-grid-row + .fr-col-12.fr-col-offset-md-2.fr-col-md-8 + %h1= t('administrateurs.procedures.publication.confirmation') + + = render Dsfr::CalloutComponent.new(title: nil) do |c| + - c.with_body do + %p= t('administrateurs.procedures.publication.share_link') + %p + %strong= commencer_url(@procedure.path) + = render Dsfr::CopyButtonComponent.new(text: commencer_url(@procedure.path), title: t("administrateurs.procedures.publication.copy_url")) + + %ul.fr-mt-2w.fr-btns-group.fr-btns-group--inline + %li= link_to t('administrateurs.procedures.publication.back_to_procedure'), admin_procedure_path(id: @procedure), class: 'fr-btn' + %li= link_to t('administrateurs.procedures.publication.new_procedure'), new_from_existing_admin_procedures_path, class: 'fr-btn fr-btn--secondary' + + .text-center + = image_tag('landing/hero/dematerialiser.svg', "aria-hidden": true) diff --git a/app/views/administrateurs/procedures/show.html.haml b/app/views/administrateurs/procedures/show.html.haml index 0df9bb013..2e9e3944d 100644 --- a/app/views/administrateurs/procedures/show.html.haml +++ b/app/views/administrateurs/procedures/show.html.haml @@ -38,7 +38,10 @@ - c.bottom do %ul.fr-mt-2w.fr-btns-group.fr-btns-group--inline - %li= button_to 'Publier les modifications', admin_procedure_publication_path(@procedure), class: 'fr-btn', id: 'publish-procedure-link', data: { disable_with: "Publication..." }, disabled: !@procedure.draft_revision.valid?, method: :get + - if @procedure.publiee? + %li= button_to 'Publier les modifications', admin_procedure_publish_revision_path(@procedure), class: 'fr-btn', id: 'publish-procedure-link', data: { disable_with: "Publication...", confirm: 'Êtes-vous sûr de vouloir publier les modifications ?' }, disabled: !@procedure.draft_revision.valid?, method: :put + - else + %li= button_to 'Publier les modifications', admin_procedure_publication_path(@procedure), class: 'fr-btn', id: 'publish-procedure-link', data: { disable_with: "Publication..." }, disabled: !@procedure.draft_revision.valid?, method: :get %li= button_to "Réinitialiser les modifications", admin_procedure_reset_draft_path(@procedure), class: 'fr-btn fr-btn--secondary fr-mr-2w', data: { confirm: 'Êtes-vous sûr de vouloir réinitialiser les modifications ?' }, method: :put - if !@procedure.procedure_expires_when_termine_enabled? diff --git a/config/locales/views/administrateurs/procedures/en.yml b/config/locales/views/administrateurs/procedures/en.yml index 31eb2f428..a37ec2c64 100644 --- a/config/locales/views/administrateurs/procedures/en.yml +++ b/config/locales/views/administrateurs/procedures/en.yml @@ -22,6 +22,9 @@ en: other: "%{count} files « instructing » on this procedure version." publication: publish_title: Publish your procedure + confirmation: Your procedure is now published ! + copy_url: Copy procedure URL + share_link: "To share your procedure, always use the full link below:" closed_procedure_html: "This procedure is closed and is therefore no longer accessible to the public. You can publish it back" draft_changed_procedure_html: "This procedure is already published. It has been edited since publication. You can publish the changes made in a new version." published_procedure_html: "This procedure is published, some elements can no longer be modified. To access it you can use the link:" @@ -34,6 +37,7 @@ en: dubious_fields: "Please note that some fields cannot be requested by the administration. Here are the fields that look suspicious to us:" click_here: Click here back_to_procedure: Return to the procedure page + new_procedure: Create a new procedure publication_form: faq_test_alert: Have you thought about testing your procedure before publishing it? To help you in this test phase, you can faq_test_alert_link: consult our best practices guide. diff --git a/config/locales/views/administrateurs/procedures/fr.yml b/config/locales/views/administrateurs/procedures/fr.yml index 3442c4370..cee3ed677 100644 --- a/config/locales/views/administrateurs/procedures/fr.yml +++ b/config/locales/views/administrateurs/procedures/fr.yml @@ -22,6 +22,9 @@ fr: other: Il y a %{count} dossiers « en instruction » sur cette version de la démarche. publication: publish_title: Publier votre démarche + confirmation: Votre démarche est désormais publiée ! + copy_url: Copiez le lien de la procédure + share_link: "Pour partager votre démarche, utilisez toujours le lien complet ci-dessous :" closed_procedure_html: "Cette démarche est close et n’est donc plus accessible par le public. Vous pouvez la réactiver :" draft_changed_procedure_html: "Cette démarche est déjà publiée. Elle a été modifiée depuis sa publication. Vous pouvez publier les changements effectués dans une nouvelle version de cette démarche :" published_procedure_html: "Cette démarche est publiée, certains éléments ne peuvent plus être modifiés. Pour y accéder vous pouvez utiliser le lien :" @@ -34,6 +37,7 @@ fr: dubious_fields: "Attention, certains champs ne peuvent être demandés par l’administration. Voici les champs qui nous semblent suspects :" click_here: Cliquez ici. back_to_procedure: Revenir à la page de la démarche + new_procedure: Créer une nouvelle démarche publication_form: faq_test_alert: Avez-vous bien pensé à tester votre démarche avant de la publier ? Pour vous aider dans cette phase de test, vous pouvez faq_test_alert_link: consulter notre guide de bonnes pratiques. diff --git a/config/routes.rb b/config/routes.rb index 4443b6525..b5ae89c81 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -554,8 +554,10 @@ Rails.application.routes.draw do get 'publication' => 'procedures#publication', as: :publication put 'publish' => 'procedures#publish', as: :publish put 'reset_draft' => 'procedures#reset_draft', as: :reset_draft + put 'publish_revision' => 'procedures#publish_revision', as: :publish_revision get 'transfert' => 'procedures#transfert', as: :transfert get 'close' => 'procedures#close', as: :close + get 'confirmation' => 'procedures#confirmation', as: :confirmation post 'transfer' => 'procedures#transfer', as: :transfer resources :mail_templates, only: [:edit, :update, :show] diff --git a/spec/controllers/administrateurs/procedures_controller_spec.rb b/spec/controllers/administrateurs/procedures_controller_spec.rb index 0d460c6af..227465621 100644 --- a/spec/controllers/administrateurs/procedures_controller_spec.rb +++ b/spec/controllers/administrateurs/procedures_controller_spec.rb @@ -965,10 +965,9 @@ describe Administrateurs::ProceduresController, type: :controller do expect(procedure.lien_site_web).to eq(lien_site_web) end - it 'redirects to the procedure page' do + it 'redirects to the confirmation page' do expect(response.status).to eq 302 - expect(response.body).to include(admin_procedure_path(procedure.id)) - expect(flash[:notice]).to have_content 'Démarche publiée' + expect(response.body).to include(admin_procedure_confirmation_path(procedure.id)) end end @@ -992,10 +991,9 @@ describe Administrateurs::ProceduresController, type: :controller do expect(procedure2.depubliee?).to be_truthy end - it 'redirects to the procedures page' do + it 'redirects to the confirmation page' do expect(response.status).to eq 302 - expect(response.body).to include(admin_procedure_path(procedure.id)) - expect(flash[:notice]).to have_content 'Démarche publiée' + expect(response.body).to include(admin_procedure_confirmation_path(procedure.id)) end end diff --git a/spec/system/administrateurs/procedure_attestation_template_spec.rb b/spec/system/administrateurs/procedure_attestation_template_spec.rb index aa6bb6d98..98dcde49b 100644 --- a/spec/system/administrateurs/procedure_attestation_template_spec.rb +++ b/spec/system/administrateurs/procedure_attestation_template_spec.rb @@ -45,6 +45,7 @@ describe 'As an administrateur, I want to manage the procedure’s attestation', click_on("Publier") # validate publication within('form') { click_on 'Publier' } + click_on("Revenir à la page de la démarche") # now process to disable attestation find_attestation_card.click diff --git a/spec/system/administrateurs/procedure_publish_spec.rb b/spec/system/administrateurs/procedure_publish_spec.rb index b9a100c7f..66e527930 100644 --- a/spec/system/administrateurs/procedure_publish_spec.rb +++ b/spec/system/administrateurs/procedure_publish_spec.rb @@ -43,7 +43,8 @@ describe 'Publishing a procedure', js: true, retry: 3 do fill_in 'lien_site_web', with: 'http://some.website' within('form') { click_on 'Publier' } - expect(page).to have_text('Démarche publiée') + expect(page).to have_text('Votre démarche est désormais publiée !') + expect(page).to have_button(title: 'Copiez le lien de la procédure') end context 'when the procedure has invalid champs' do @@ -91,7 +92,7 @@ describe 'Publishing a procedure', js: true, retry: 3 do fill_in 'lien_site_web', with: 'http://some.website' click_on 'publish' - expect(page).to have_text('Démarche publiée') + expect(page).to have_text('Votre démarche est désormais publiée !') end end @@ -122,7 +123,7 @@ describe 'Publishing a procedure', js: true, retry: 3 do fill_in 'lien_site_web', with: 'http://some.website' find('#publish').click - expect(page).to have_text('Démarche publiée') + expect(page).to have_text('Votre démarche est désormais publiée !') end end diff --git a/spec/system/api_particulier/api_particulier_spec.rb b/spec/system/api_particulier/api_particulier_spec.rb index 4fe12f340..065de57b1 100644 --- a/spec/system/api_particulier/api_particulier_spec.rb +++ b/spec/system/api_particulier/api_particulier_spec.rb @@ -230,7 +230,7 @@ describe 'fetch API Particulier Data', js: true, retry: 3 do fill_in 'lien_site_web', with: 'http://some.website' within('form') { click_on 'Publier' } - expect(page).to have_text('Démarche publiée') + expect(page).to have_text('Votre démarche est désormais publiée !') end end diff --git a/spec/system/routing/rules_full_scenario_spec.rb b/spec/system/routing/rules_full_scenario_spec.rb index f8f5414ec..67160c1d4 100644 --- a/spec/system/routing/rules_full_scenario_spec.rb +++ b/spec/system/routing/rules_full_scenario_spec.rb @@ -254,7 +254,7 @@ describe 'The routing with rules', js: true, retry: 3 do fill_in 'lien_site_web', with: 'http://some.website' within('form') { click_on 'Publier' } - expect(page).to have_text('Démarche publiée') + expect(page).to have_text('Votre démarche est désormais publiée !') end def user_send_dossier(user, groupe)