Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/components/dsfr/callout_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def theme_class
case theme
when :warning
"fr-callout--brown-caramel"
when :orange_terre_battue
"fr-callout--orange-terre-battue"
when :success
"fr-callout--green-emeraude"
when :neutral
Expand Down
16 changes: 16 additions & 0 deletions app/helpers/dossier_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,22 @@ def deletion_reason_badge(reason)
tag.span(status_text, class: "fr-badge #{status_class} ")
end

def expiration_badge(dossier, html_class: nil)
return unless dossier.expirable? && dossier.close_to_expiration?

tag.span(
t('views.users.dossiers.dossiers_list.expiration_badge', count: dossier.nb_days_before_expiration),
class: class_names("fr-badge fr-badge--sm fr-badge--warning", html_class => true)
)
end

def partage_badge(html_class: nil)
tag.span(
Dossier.human_attribute_name("partage.for_user"),
class: class_names("fr-badge fr-badge--sm fr-badge--blue-cumulus", html_class => true)
)
end

def pending_correction_badge(profile, html_class: nil)
tag.span(Dossier.human_attribute_name("pending_correction.#{profile}"), class:
class_names(
Expand Down
5 changes: 5 additions & 0 deletions app/models/dossier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,14 @@ def expirable?

def close_to_expiration?
return false if en_instruction? || en_construction?
return false if expired_at.nil?
expired_at < Expired::REMAINING_WEEKS_BEFORE_EXPIRATION.weeks.from_now && Time.zone.now < expired_at
end

def nb_days_before_expiration
(expired_at.to_date - Date.current).to_i
end

def has_expired?
return false if en_instruction? || en_construction?

Expand Down
46 changes: 27 additions & 19 deletions app/views/users/dossiers/_dossiers_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,21 @@
<%= number_with_html_delimiter(dossier.id) %>
</p>

<%= status_badge_user(dossier, 'fr-mb-1w') %>
<div class="flex column align-start flex-gap-1">
<%= status_badge_user(dossier) %>

<% if dossier.pending_correction? %>
<br>
<%= pending_correction_badge(:for_user) %>
<% end %>
<% if dossier.pending_correction? %>
<%= pending_correction_badge(:for_user) %>
<% end %>

<% if dossier.pending_response? %>
<br>
<%= pending_response_badge(:for_user) %>
<% end %>
<% if dossier.pending_response? %>
<%= pending_response_badge(:for_user) %>
<% end %>

<%= expiration_badge(dossier) %>

<%= partage_badge unless current_user.owns?(dossier) %>
</div>
</div>

<p class="fr-icon--sm fr-icon-user-line">
Expand Down Expand Up @@ -70,7 +74,7 @@
<% end %>
</p>
<% if dossier.invites.present? %>
<p class="fr-icon--sm fr-icon-shield-line">
<p class="fr-icon--sm fr-icon-group-line">
<%= t('views.users.dossiers.dossiers_list.shared_with', owner: dossier.user_email_for(:display)) %>
<%= dossier.invites.map(&:email).join(', ') %>
</p>
Expand All @@ -84,17 +88,21 @@
<%= number_with_html_delimiter(dossier.id) %>
</p>

<%= status_badge_user(dossier, 'fr-mb-1w') %>
<div class="flex column align-end flex-gap-1">
<%= status_badge_user(dossier) %>

<% if dossier.pending_correction? %>
<br>
<%= pending_correction_badge(:for_user) %>
<% end %>
<% if dossier.pending_correction? %>
<%= pending_correction_badge(:for_user) %>
<% end %>

<% if dossier.pending_response? %>
<br>
<%= pending_response_badge(:for_user) %>
<% end %>
<% if dossier.pending_response? %>
<%= pending_response_badge(:for_user) %>
<% end %>

<%= expiration_badge(dossier) %>

<%= partage_badge unless current_user.owns?(dossier) %>
</div>
</div>
</div>

Expand Down
4 changes: 1 addition & 3 deletions app/views/users/dossiers/_expiration_banner.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@

- if dossier.close_to_expiration? || dossier.has_expired?
- title = dossier.has_expired? ? 'title_expired' : 'title'
= render Dsfr::CalloutComponent.new(title: t("users.dossiers.header.banner.#{title}"), theme: :warning) do |c|
= render Dsfr::CalloutComponent.new(title: t("users.dossiers.header.banner.#{title}"), theme: :orange_terre_battue) do |c|
- c.with_body do
- if dossier.brouillon?
= t('users.dossiers.header.banner.states.brouillon')
- elsif dossier.en_construction?
= t('users.dossiers.header.banner.states.en_construction', nominal_duration_months: dossier.procedure.duree_conservation_dossiers_dans_ds)
- elsif dossier.termine?
= t('users.dossiers.header.banner.states.termine')

Expand Down
2 changes: 2 additions & 0 deletions app/views/users/dossiers/show/_header.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
= status_badge_user(dossier, 'super')
= pending_correction_badge(:for_user) if dossier.pending_correction?
= pending_response_badge(:for_user) if dossier.pending_response?
= expiration_badge(dossier, html_class: 'super')
= partage_badge(html_class: 'super') unless current_user.owns?(dossier)

= render(partial: 'users/dossiers/expiration_banner', locals: {dossier: dossier})

Expand Down
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,10 @@ en:
administration_no_longer_processes: "The administration will no longer process your request."
dossiers_list:
n_dossier: "File no."
expiration_badge:
zero: "Expires today"
one: "Expires tomorrow"
other: "Expires in %{count} days"
no_result_title: No files
no_result_text_html: "To fill a procedure, contact your administration asking for the procedure link. <br> It should look like %{app_base}/commencer/xxx."
no_result_text_with_search: found with search terms
Expand Down
4 changes: 4 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,10 @@ fr:
administration_no_longer_processes: "L’administration ne traitera plus votre demande."
dossiers_list:
n_dossier: "dossier n°"
expiration_badge:
zero: "Expire aujourd’hui"
one: "Expire demain"
other: "Expire dans %{count} j."
no_result_title: Aucun dossier
no_result_text_html: "Pour remplir une démarche, contactez votre administration en lui demandant le lien de la démarche. <br> Celui ci doit ressembler à %{app_base}/commencer/xxx."
no_result_text_with_search: ne correspond aux termes recherchés
Expand Down
2 changes: 2 additions & 0 deletions config/locales/models/dossier/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ en:
for_user: "PENDING RESPONSE"
for_instructeur: "pending response"
responded: "Response given"
partage:
for_user: "Shared with me"
traitement:
state: "State"
traitement/state:
Expand Down
2 changes: 2 additions & 0 deletions config/locales/models/dossier/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ fr:
for_instructeur: "en attente de réponse"
responded: "Réponse donnée"
discarded: "Demande de réponse annulée"
partage:
for_user: "Partagé avec moi"
traitement:
state: "État"
traitement/state:
Expand Down
1 change: 0 additions & 1 deletion config/locales/views/users/header/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ en:
contact_service_html: For more information, please contact the service %{service_name}, available at %{service_phone_number} or by email to <a href="mailto:%{service_email}">%{service_email}</a>
states:
brouillon: Your file is still in draft and will soon expire. So it will be deleted soon without being instructed. If you want to pursue your procedure you can submit it now. Otherwise you are able to delay its expiration by clicking on the underneath button.
en_construction: Your file is pending for instruction. The maximum delay is %{nominal_duration_months} months, but you can extend the duration by clicking on the underneath button.
termine: Your file had been processed and will soon expire. So it will be deleted soon. If you want to keep it, you can dowload a PDF file of it.
button_delay_expiration:
one: "Keep for %{count} more month"
Expand Down
3 changes: 1 addition & 2 deletions config/locales/views/users/header/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ fr:
title: Votre dossier va expirer
title_expired: Votre dossier a expiré
states:
brouillon: Votre dossier est en brouillon, mais va bientôt être supprimé sans avoir été déposé. Si vous souhaitez le conserver afin de poursuivre la démarche, vous pouvez étendre la durée de conversation en cliquant sur le bouton ci-dessous.
en_construction: Votre dossier est en attente de prise en charge par l’administration. Le délai de prise en charge maximal est de %{nominal_duration_months} mois. Vous pouvez toutefois étendre cette durée en cliquant sur le bouton ci-dessous.
brouillon: Votre dossier est en brouillon, mais va bientôt être supprimé sans avoir été déposé. Si vous souhaitez le conserver afin de poursuivre la démarche, vous pouvez étendre la durée de conservation en cliquant sur le bouton ci-dessous.
termine: Le traitement de votre dossier est terminé, mais il va bientôt être supprimé. Si vous souhaitez en conserver une trace, vous pouvez le télécharger au format PDF.
button_delay_expiration:
one: "Conserver %{count} mois supplémentaire"
Expand Down
19 changes: 19 additions & 0 deletions spec/components/dsfr/callout_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe Dsfr::CalloutComponent, type: :component do
subject(:rendered) { render_inline(described_class.new(title: "Mon titre", theme:)) }

context "with the orange_terre_battue theme" do
let(:theme) { :orange_terre_battue }

it { is_expected.to have_css(".fr-callout.fr-callout--orange-terre-battue") }
end

context "with the warning theme" do
let(:theme) { :warning }

it { is_expected.to have_css(".fr-callout.fr-callout--brown-caramel") }
end
end
59 changes: 59 additions & 0 deletions spec/helpers/dossier_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,65 @@
end
end

describe ".partage_badge" do
subject { partage_badge }

it { is_expected.to have_css(".fr-badge--blue-cumulus", text: "Partagé avec moi") }
end

describe ".expiration_badge" do
subject { expiration_badge(dossier) }

context "when dossier is a brouillon close to expiration" do
let(:dossier) { create(:dossier) }

before { dossier.update_column(:expired_at, 5.days.from_now.change(hour: 23)) }

it { is_expected.to have_css(".fr-badge--warning", text: "Expire dans 5 j.") }
end

context "when dossier expires tomorrow" do
let(:dossier) { create(:dossier) }

before { dossier.update_column(:expired_at, 1.day.from_now.change(hour: 23)) }

it { is_expected.to have_css(".fr-badge--warning", text: "Expire demain") }
end

context "when dossier expires today" do
let(:dossier) { create(:dossier) }

before { dossier.update_column(:expired_at, Time.zone.now.end_of_day) }

it { is_expected.to have_css(".fr-badge--warning", text: "Expire aujourd’hui") }
end

context "when dossier is not close to expiration" do
let(:dossier) { create(:dossier) }

before { dossier.update_column(:expired_at, 1.year.from_now) }

it { is_expected.to be_nil }
end

context "when dossier is en_construction (never expires)" do
let(:dossier) { create(:dossier, :en_construction) }

before { dossier.update_column(:expired_at, 5.days.from_now) }

it { is_expected.to be_nil }
end

context "when dossier is termine without procedure_expires_when_termine_enabled" do
let(:procedure) { create(:procedure, :published, procedure_expires_when_termine_enabled: false) }
let(:dossier) { create(:dossier, :accepte, procedure:) }

before { dossier.update_column(:expired_at, 5.days.from_now) }

it { is_expected.to be_nil }
end
end

describe ".clean_string_for_pdf" do
subject { clean_string_for_pdf(input) }

Expand Down
19 changes: 19 additions & 0 deletions spec/models/dossier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,25 @@
end
end

describe '#nb_days_before_expiration' do
let(:dossier) { create(:dossier) }

it 'counts the number of days until expired_at' do
dossier.update_column(:expired_at, 5.days.from_now.change(hour: 23))
expect(dossier.nb_days_before_expiration).to eq(5)
end
end

describe '#close_to_expiration?' do
context 'when expired_at is nil' do
let(:dossier) { create(:dossier) }

before { dossier.update_column(:expired_at, nil) }

it { expect(dossier.close_to_expiration?).to be(false) }
end
end

describe "en_construction never expires (#13178)" do
let(:procedure) { create(:procedure, :published, duree_conservation_dossiers_dans_ds: 2) }
let(:dossier) { create(:dossier, :en_construction, procedure:, en_construction_at: 50.days.ago) }
Expand Down
25 changes: 25 additions & 0 deletions spec/system/users/list_dossiers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,31 @@
expect(page.body).to match(/#{last_updated_dossier.procedure.libelle}.*#{dossier_en_instruction.procedure.libelle}/m)
end

context 'when a brouillon is close to expiration' do
let!(:dossier_expirant) do
create(:dossier, user:).tap { it.update_column(:expired_at, 5.days.from_now) }
end

before { visit dossiers_path }

it 'displays the expiration badge on the card' do
expect(page).to have_text('Expire dans 5 j.')
end
end

context 'when the user is invited on a shared dossier' do
let(:owner) { create(:user) }
let!(:shared_dossier) { create(:dossier, :en_construction, user: owner) }
let!(:invite) { create(:invite, dossier: shared_dossier, user:) }

before { visit dossiers_path(statut: 'dossiers-invites') }

it 'displays the "Partagé avec moi" badge and the group-line sharing icon' do
expect(page).to have_css('.fr-badge--blue-cumulus', text: 'Partagé avec moi')
expect(page).to have_css('.fr-icon-group-line')
end
end

context 'when there are dossiers from other users' do
let!(:dossier_other_user) { create(:dossier) }

Expand Down
28 changes: 28 additions & 0 deletions spec/views/users/dossiers/_expiration_banner.html.haml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,32 @@
end
end
end

context 'when close to expiration' do
let(:expiration_enabled) { true }

before { allow(dossier).to receive(:close_to_expiration?).and_return(true) }

context 'with a brouillon' do
let(:attributes) { { created_at: 6.months.ago } }
let(:state) { :brouillon }

it 'renders the orange callout with the postpone button' do
expect(subject).to have_selector('.fr-callout.fr-callout--orange-terre-battue')
expect(subject).to have_selector('#test-user-repousser-expiration')
end
end

context 'with a termine dossier' do
let(:attributes) { { processed_at: 6.months.ago } }
let(:state) { :accepte }

it 'renders the orange callout without any action button (download is handled by the header)' do
expect(subject).to have_selector('.fr-callout.fr-callout--orange-terre-battue')
expect(subject).not_to have_selector('#test-user-repousser-expiration')
expect(subject).not_to have_selector('.fr-callout a')
expect(subject).not_to have_selector('.fr-callout button')
end
end
end
end
Loading