Merge pull request #10158 from demarches-simplifiees/fix-closing-reason-form

Correctif : ETQ admin je ne peux pas fermer une démarche en redirigeant sans choisir la nouvelle démarche
This commit is contained in:
Eric Leroy-Terquem 2024-03-20 13:28:40 +00:00 committed by GitHub
commit 73d6609eb3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 52 additions and 12 deletions

View file

@ -226,7 +226,7 @@ class Procedure < ApplicationRecord
enum closing_reason: { enum closing_reason: {
internal_procedure: 'internal_procedure', internal_procedure: 'internal_procedure',
other: 'other' other: 'other'
} }, _prefix: true
scope :for_api_v2, -> { scope :for_api_v2, -> {
includes(:draft_revision, :published_revision, administrateurs: :user) includes(:draft_revision, :published_revision, administrateurs: :user)
@ -265,8 +265,7 @@ class Procedure < ApplicationRecord
validate :check_juridique, on: [:create, :publication] validate :check_juridique, on: [:create, :publication]
# TO DO add validation after data backfill validates :replaced_by_procedure_id, presence: true, if: :closing_reason_internal_procedure?
# validates :replaced_by_id, presence: true, if: -> { closing_reason == self.closing_reasons.fetch(: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 :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, validates :duree_conservation_dossiers_dans_ds, allow_nil: false,

View file

@ -0,0 +1,17 @@
# frozen_string_literal: true
module Maintenance
class UpdateClosingReasonIfNoReplacedByIdTask < MaintenanceTasks::Task
def collection
Procedure
.with_discarded
.closes
.where(closing_reason: Procedure.closing_reasons.fetch(:internal_procedure))
.where(replaced_by_procedure_id: nil)
end
def process(procedure)
procedure.closing_reason_other!
end
end
end

View file

@ -7,7 +7,7 @@
.fr-grid-row .fr-grid-row
.fr-col-12.fr-col-offset-md-2.fr-col-md-8 .fr-col-12.fr-col-offset-md-2.fr-col-md-8
%h1= t('administrateurs.procedures.closing_notification.page_title') %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 %h2.fr-h5= I18n.t('administrateurs.procedures.closing_notification.page_subtitle', closing_path: closing_details_path(@procedure.path)).html_safe
- else - 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 %h2.fr-h5= I18n.t('administrateurs.procedures.closing_notification.page_subtitle_with_redirection', redirection_path: commencer_path(@procedure.replaced_by_procedure.path)).html_safe

View file

@ -58,7 +58,7 @@
- new_procedure = Procedure.find_by(id: @procedure.replaced_by_procedure_id) - new_procedure = Procedure.find_by(id: @procedure.replaced_by_procedure_id)
%p %p
= "Cette démarche est remplacée par une autre démarche dans Démarches simplifiées :" = "Cette démarche est remplacée par une autre démarche dans Démarches simplifiées :"
= link_to(new_procedure&.libelle, admin_procedure_path(new_procedure)) = link_to(new_procedure.libelle, admin_procedure_path(new_procedure))
- if @procedure.closing_reason == 'other' - if @procedure.closing_reason == 'other'
%p %p
= "Plus d'informations dans la #{link_to('page de fermeture', closing_details_path(@procedure.path))}, visible par les usagers." = "Plus d'informations dans la #{link_to('page de fermeture', closing_details_path(@procedure.path))}, visible par les usagers."

View file

@ -54,13 +54,13 @@
= render Dsfr::AlertComponent.new(state: :info, size: :sm, extra_class_names: "fr-mb-2w") do |c| = render Dsfr::AlertComponent.new(state: :info, size: :sm, extra_class_names: "fr-mb-2w") do |c|
- c.with_body do - c.with_body do
%p %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 = 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 = 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') = 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 = 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? - if dossier.pending_correction?

View file

@ -803,9 +803,10 @@ describe Administrateurs::ProceduresController, type: :controller do
procedure.reload procedure.reload
end end
it 'closes the procedure without redirection to the new procedure in DS' do it 'does not close the procedure' do
expect(response).to redirect_to admin_procedure_path(procedure.id) expect(response).to redirect_to admin_procedure_close_path
expect(flash[:notice]).to have_content 'Démarche close' expect(flash[:alert]).to have_content 'Le champ « Nouvelle démarche » doit être rempli'
expect(procedure.close?).to be_falsey
expect(procedure.replaced_by_procedure).to eq(nil) expect(procedure.replaced_by_procedure).to eq(nil)
end end
end end

View file

@ -0,0 +1,23 @@
# frozen_string_literal: true
require "rails_helper"
module Maintenance
RSpec.describe UpdateClosingReasonIfNoReplacedByIdTask do
describe "#process" do
subject(:process) { described_class.process(procedure) }
let(:procedure) { create(:procedure, :closed) }
before do
procedure.update_column(:closing_reason, Procedure.closing_reasons.fetch(:internal_procedure))
procedure.update_column(:replaced_by_procedure_id, nil)
end
it 'updates closing_reason to other' do
subject
expect(procedure.closing_reason).to eq(Procedure.closing_reasons.fetch(:other))
end
end
end
end