Merge pull request #10577 from colinux/alert-procedure-draft

ETQ usager et admin, je suis prévenu au moment de commencer un dossier sur une démarche ou révision en test
This commit is contained in:
Colin Darie 2024-07-08 09:43:57 +00:00 committed by GitHub
commit f954d07cf6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 115 additions and 30 deletions

View file

@ -2,6 +2,17 @@
class Dsfr::AlertComponent < ApplicationComponent class Dsfr::AlertComponent < ApplicationComponent
renders_one :body renders_one :body
attr_reader :state, :title, :size, :block, :extra_class_names, :heading_level
def initialize(state:, title: '', size: '', extra_class_names: nil, heading_level: 'h3')
@state = state
@title = title
@size = size
@block = block
@extra_class_names = extra_class_names
@heading_level = heading_level
end
def prefix_for_state def prefix_for_state
case state case state
when :error then "Erreur : " when :error then "Erreur : "
@ -19,19 +30,4 @@ class Dsfr::AlertComponent < ApplicationComponent
extra_class_names => true extra_class_names => true
) )
end end
private
def initialize(state:, title: '', size: '', extra_class_names: nil, heading_level: 'h3')
@state = state
@title = title
@size = size
@block = block
@extra_class_names = extra_class_names
@heading_level = heading_level
end
attr_reader :state, :title, :size, :block, :extra_class_names, :heading_level
private
end end

View file

@ -0,0 +1,21 @@
# frozen_string_literal: true
class ProcedureDraftWarningComponent < ApplicationComponent
attr_reader :revision
attr_reader :current_administrateur
attr_reader :extra_class_names
def initialize(revision:, current_administrateur:, extra_class_names: nil)
@revision = revision
@current_administrateur = current_administrateur
@extra_class_names = extra_class_names
end
def render?
revision.draft?
end
def admin?
current_administrateur.present? && revision.procedure.administrateurs.include?(current_administrateur)
end
end

View file

@ -0,0 +1,13 @@
---
en:
title: Procedure in testing
intro_procedure_brouillon_html: This procedure is currently in <b>testing</b>
intro_revision_draft_html: This page allows you to <b>test</b> a new version of the procedure
body_general_html: |
and this page is reserved for the administration in charge of its deployment.
If you start or submit a file, it may be <b>deleted at any time</b> without notice, even if it is accepted later.
body_user: |
If this link was shared with you, please contact the service in charge of this procedure
to obtain the public link for the procedure in order to submit your application.
body_admin_procedure_brouillon: Do not share this link with your users. When you publish the procedure, you will access the public link for the procedure to be shared.
body_admin_revision_draft: Do not share this link with your users, but rather the public link for the procedure displayed in your administrator dashboard.

View file

@ -0,0 +1,13 @@
---
fr:
title: Démarche en test
intro_procedure_brouillon_html: Cette démarche est actuellement en <b>test</b>
intro_revision_draft_html: Cette page permet de <b>tester</b> une nouvelle version de la démarche
body_general_html: |
et cette page est réservée à ladministration en charge de son déploiement.
Si vous commencez ou déposez un dossier, il pourra être <b>supprimé à tout moment</b> et sans préavis, même après avoir été accepté.
body_user: |
Si ce lien vous a été communiqué, contactez le service en charge de cette démarche
pour obtenir le lien public de la démarche afin de déposer votre dossier.
body_admin_procedure_brouillon: Ne communiquez pas ce lien à vos usagers. Lorsque vous publierez la démarche, vous accéderez au lien public de la démarche à communiquer.
body_admin_revision_draft: Ne communiquez pas ce lien à vos usagers, mais le lien public de la démarche affiché dans votre tableau de bord administrateur.

View file

@ -0,0 +1,10 @@
= render Dsfr::AlertComponent.new(state: :warning, extra_class_names:, title: t(".title")) do |c|
- c.with_body do
%p
= revision.procedure.brouillon? ? t(".intro_procedure_brouillon_html") : t(".intro_revision_draft_html")
= t(".body_general_html")
- if admin?
%p= revision.procedure.brouillon? ? t(".body_admin_procedure_brouillon") : t(".body_admin_revision_draft")
- else
%p= t(".body_user")

View file

@ -13,7 +13,11 @@
#{Current.application_name} #{Current.application_name}
%li= link_to t('views.shared.account.already_user'), commencer_sign_in_path(path: @procedure.path, prefill_token: @prefilled_dossier&.prefill_token), class: 'fr-btn fr-btn--secondary' %li= link_to t('views.shared.account.already_user'), commencer_sign_in_path(path: @procedure.path, prefill_token: @prefilled_dossier&.prefill_token), class: 'fr-btn fr-btn--secondary'
= render ProcedureDraftWarningComponent.new(revision: @revision, current_administrateur:, extra_class_names: "fr-mb-2w")
- else - else
= render ProcedureDraftWarningComponent.new(revision: @revision, current_administrateur:, extra_class_names: "fr-mb-2w")
- if @prefilled_dossier - if @prefilled_dossier
= render Dsfr::CalloutComponent.new(title: t(".prefilled_draft"), heading_level: 'h2') do |c| = render Dsfr::CalloutComponent.new(title: t(".prefilled_draft"), heading_level: 'h2') do |c|
- c.with_body do - c.with_body do

View file

@ -10,7 +10,7 @@ fr:
since: "depuis le %{date}" since: "depuis le %{date}"
closed: "Close" closed: "Close"
published: "Publiée" published: "Publiée"
draft: "En test" draft: "En test"
more_info_on_test: "Pour plus dinformation sur la phase de test" more_info_on_test: "Pour plus dinformation sur la phase de test"
go_to_FAQ: "consulter la FAQ" go_to_FAQ: "consulter la FAQ"
url_FAQ: "/faq#accordion-administrateur-2" url_FAQ: "/faq#accordion-administrateur-2"

View file

@ -16,17 +16,11 @@ describe 'administrateurs/procedures/show', type: :view do
render render
end end
describe 'publish button is visible' do it "render content" do
it { expect(rendered).to have_css('#publish-procedure-link') } expect(rendered).to have_css('#publish-procedure-link')
it { expect(rendered).not_to have_css('#close-procedure-link') } expect(rendered).not_to have_css('#close-procedure-link')
end expect(rendered).to have_content('En test')
expect(rendered).not_to have_css('#archive-procedure')
describe 'procedure path is not customized' do
it { expect(rendered).to have_content('En test') }
end
describe 'archive button' do
it { expect(rendered).not_to have_css('#archive-procedure') }
end end
end end
end end

View file

@ -7,10 +7,15 @@ RSpec.describe 'commencer/show', type: :view do
let(:drafts) { [] } let(:drafts) { [] }
let(:not_drafts) { [] } let(:not_drafts) { [] }
let(:preview_dossiers) { dossiers.take(3) } let(:preview_dossiers) { dossiers.take(3) }
let(:user) { nil }
before do
allow(view).to receive(:current_administrateur).and_return(user&.administrateur)
end
before do before do
assign(:procedure, procedure) assign(:procedure, procedure)
assign(:revision, procedure.published_revision) assign(:revision, procedure.active_revision)
assign(:dossiers, dossiers) assign(:dossiers, dossiers)
assign(:drafts, drafts) assign(:drafts, drafts)
assign(:not_drafts, not_drafts) assign(:not_drafts, not_drafts)
@ -25,8 +30,6 @@ RSpec.describe 'commencer/show', type: :view do
subject { render } subject { render }
context 'when no user is signed in' do context 'when no user is signed in' do
let(:user) { nil }
it 'renders sign-in and sign-up links' do it 'renders sign-in and sign-up links' do
subject subject
expect(rendered).to have_link('Créer un compte') expect(rendered).to have_link('Créer un compte')
@ -98,4 +101,35 @@ RSpec.describe 'commencer/show', type: :view do
end end
end end
end end
context "procedure is draft" do
let(:procedure) { create(:procedure, :draft) }
let(:user) { create :user }
it 'renders a warning' do
subject
expect(rendered).to have_text("Cette démarche est actuellement en test")
end
context "when user is admin" do
let(:user) { procedure.administrateurs.first.user }
it "renders warning about draft" do
subject
expect(rendered).to have_text("Cette démarche est actuellement en test")
expect(rendered).to have_text("Ne communiquez pas ce lien")
end
end
end
context "revision is draft" do
before {
assign(:revision, procedure.draft_revision)
}
it "renders warning about draft" do
subject
expect(rendered).to have_text("Démarche en test")
end
end
end end