From 280f1ac3c7af802c7a3dd5950b514d93e5237960 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Wed, 20 Mar 2024 13:53:15 +0100 Subject: [PATCH] refactor(procedure): add a prefix to closing_reason enum --- app/models/procedure.rb | 4 ++-- .../update_closing_reason_if_no_replaced_by_id_task.rb | 2 +- .../procedures/closing_notification.html.haml | 2 +- app/views/users/dossiers/_dossiers_list.html.haml | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 3ad38e516..fb3275bc8 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -226,7 +226,7 @@ class Procedure < ApplicationRecord enum closing_reason: { internal_procedure: 'internal_procedure', other: 'other' - } + }, _prefix: true scope :for_api_v2, -> { includes(:draft_revision, :published_revision, administrateurs: :user) @@ -265,7 +265,7 @@ class Procedure < ApplicationRecord validate :check_juridique, on: [:create, :publication] - validates :replaced_by_procedure_id, presence: true, if: -> { closing_reason == Procedure.closing_reasons.fetch(:internal_procedure) } + validates :replaced_by_procedure_id, presence: true, if: :closing_reason_internal_procedure? validates :path, presence: true, format: { with: /\A[a-z0-9_\-]{3,200}\z/ }, uniqueness: { scope: [:path, :closed_at, :hidden_at, :unpublished_at], case_sensitive: false } validates :duree_conservation_dossiers_dans_ds, allow_nil: false, diff --git a/app/tasks/maintenance/update_closing_reason_if_no_replaced_by_id_task.rb b/app/tasks/maintenance/update_closing_reason_if_no_replaced_by_id_task.rb index f7beb3bea..daf013ca0 100644 --- a/app/tasks/maintenance/update_closing_reason_if_no_replaced_by_id_task.rb +++ b/app/tasks/maintenance/update_closing_reason_if_no_replaced_by_id_task.rb @@ -11,7 +11,7 @@ module Maintenance end def process(procedure) - procedure.update!(closing_reason: Procedure.closing_reasons.fetch(:other)) + procedure.closing_reason_other! end end end diff --git a/app/views/administrateurs/procedures/closing_notification.html.haml b/app/views/administrateurs/procedures/closing_notification.html.haml index 36c9f0e77..acd58b10e 100644 --- a/app/views/administrateurs/procedures/closing_notification.html.haml +++ b/app/views/administrateurs/procedures/closing_notification.html.haml @@ -7,7 +7,7 @@ .fr-grid-row .fr-col-12.fr-col-offset-md-2.fr-col-md-8 %h1= t('administrateurs.procedures.closing_notification.page_title') - - if @procedure.closing_reason == Procedure.closing_reasons.fetch(:other) + - if @procedure.closing_reason_other? %h2.fr-h5= I18n.t('administrateurs.procedures.closing_notification.page_subtitle', closing_path: closing_details_path(@procedure.path)).html_safe - else %h2.fr-h5= I18n.t('administrateurs.procedures.closing_notification.page_subtitle_with_redirection', redirection_path: commencer_path(@procedure.replaced_by_procedure.path)).html_safe diff --git a/app/views/users/dossiers/_dossiers_list.html.haml b/app/views/users/dossiers/_dossiers_list.html.haml index ea6e62933..432dc5239 100644 --- a/app/views/users/dossiers/_dossiers_list.html.haml +++ b/app/views/users/dossiers/_dossiers_list.html.haml @@ -54,13 +54,13 @@ = render Dsfr::AlertComponent.new(state: :info, size: :sm, extra_class_names: "fr-mb-2w") do |c| - c.with_body do %p - - if dossier.brouillon? && dossier.procedure.closing_reason == Procedure.closing_reasons.fetch(:internal_procedure) + - if dossier.brouillon? && dossier.procedure.closing_reason_internal_procedure? = I18n.t('views.users.dossiers.dossiers_list.procedure_closed.brouillon.internal_procedure', link: commencer_path(dossier.procedure.replaced_by_procedure.path)).html_safe - - elsif dossier.brouillon? && dossier.procedure.closing_reason == Procedure.closing_reasons.fetch(:other) + - elsif dossier.brouillon? && dossier.procedure.closing_reason_other? = I18n.t('views.users.dossiers.dossiers_list.procedure_closed.brouillon.other', link: closing_details_path(dossier.procedure.path)).html_safe - - elsif (dossier.en_construction? || dossier.en_instruction?) && dossier.procedure.closing_reason == Procedure.closing_reasons.fetch(:internal_procedure) + - elsif (dossier.en_construction? || dossier.en_instruction?) && dossier.procedure.closing_reason_internal_procedure? = I18n.t('views.users.dossiers.dossiers_list.procedure_closed.en_cours.internal_procedure') - - elsif (dossier.en_construction? || dossier.en_instruction?) && dossier.procedure.closing_reason == Procedure.closing_reasons.fetch(:other) + - elsif (dossier.en_construction? || dossier.en_instruction?) && dossier.procedure.closing_reason_other? = I18n.t('views.users.dossiers.dossiers_list.procedure_closed.en_cours.other', link: closing_details_path(dossier.procedure.path)).html_safe - if dossier.pending_correction?