Merge pull request #11050 from demarches-simplifiees/fix-9513-part-1
(1/X) ETQ administrateur, je veux pouvoir modifier le lien URL de ma démarche sans avoir à la cloturer
This commit is contained in:
commit
460bd48d08
4 changed files with 49 additions and 39 deletions
|
@ -286,7 +286,7 @@ module Administrateurs
|
|||
flash.alert = "La date limite de dépôt des dossiers doit être postérieure à la date du jour pour réactiver la procédure. #{view_context.link_to('Veuillez la modifier', edit_admin_procedure_path(@procedure))}"
|
||||
redirect_to admin_procedure_path(@procedure)
|
||||
else
|
||||
@procedure.path = @procedure.suggested_path(current_administrateur)
|
||||
@procedure.path = @procedure.suggested_path
|
||||
@current_administrateur = current_administrateur
|
||||
@closed_procedures = current_administrateur.procedures.with_discarded.closes.map { |p| ["#{p.libelle} (#{p.id})", p.id] }.to_h
|
||||
end
|
||||
|
|
46
app/models/concerns/procedure_path_concern.rb
Normal file
46
app/models/concerns/procedure_path_concern.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ProcedurePathConcern
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
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 }
|
||||
|
||||
after_initialize :ensure_path_exists
|
||||
before_save :ensure_path_exists
|
||||
|
||||
def ensure_path_exists
|
||||
if self.path.blank?
|
||||
self.path = SecureRandom.uuid
|
||||
end
|
||||
end
|
||||
|
||||
def other_procedure_with_path(path)
|
||||
Procedure.publiees
|
||||
.where.not(id: self.id)
|
||||
.find_by(path: path)
|
||||
end
|
||||
|
||||
def path_available?(path)
|
||||
other_procedure_with_path(path).blank?
|
||||
end
|
||||
|
||||
def path_customized?
|
||||
!path.match?(/[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}/)
|
||||
end
|
||||
|
||||
def suggested_path
|
||||
if path_customized?
|
||||
return path
|
||||
end
|
||||
slug = libelle&.parameterize&.first(50)
|
||||
suggestion = slug
|
||||
counter = 1
|
||||
while !path_available?(suggestion)
|
||||
counter = counter + 1
|
||||
suggestion = "#{slug}-#{counter}"
|
||||
end
|
||||
suggestion
|
||||
end
|
||||
end
|
||||
end
|
|
@ -9,6 +9,7 @@ class Procedure < ApplicationRecord
|
|||
include ProcedureSVASVRConcern
|
||||
include ProcedureChorusConcern
|
||||
include ProcedurePublishConcern
|
||||
include ProcedurePathConcern
|
||||
include PiecesJointesListConcern
|
||||
include ColumnsConcern
|
||||
|
||||
|
@ -232,7 +233,6 @@ class Procedure < ApplicationRecord
|
|||
|
||||
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,
|
||||
numericality: {
|
||||
only_integer: true,
|
||||
|
@ -294,8 +294,6 @@ class Procedure < ApplicationRecord
|
|||
before_save :update_juridique_required
|
||||
after_save :extend_conservation_for_dossiers
|
||||
|
||||
after_initialize :ensure_path_exists
|
||||
before_save :ensure_path_exists
|
||||
after_create :ensure_defaut_groupe_instructeur
|
||||
|
||||
include AASM
|
||||
|
@ -331,30 +329,6 @@ class Procedure < ApplicationRecord
|
|||
dossiers.close_to_expiration.count
|
||||
end
|
||||
|
||||
def suggested_path(administrateur)
|
||||
if path_customized?
|
||||
return path
|
||||
end
|
||||
slug = libelle&.parameterize&.first(50)
|
||||
suggestion = slug
|
||||
counter = 1
|
||||
while !path_available?(suggestion)
|
||||
counter = counter + 1
|
||||
suggestion = "#{slug}-#{counter}"
|
||||
end
|
||||
suggestion
|
||||
end
|
||||
|
||||
def other_procedure_with_path(path)
|
||||
Procedure.publiees
|
||||
.where.not(id: self.id)
|
||||
.find_by(path: path)
|
||||
end
|
||||
|
||||
def path_available?(path)
|
||||
other_procedure_with_path(path).blank?
|
||||
end
|
||||
|
||||
def canonical_procedure_child?(procedure)
|
||||
!canonical_procedure || canonical_procedure == procedure || canonical_procedure == procedure.canonical_procedure
|
||||
end
|
||||
|
@ -425,10 +399,6 @@ class Procedure < ApplicationRecord
|
|||
Flipper.enabled?(feature, self)
|
||||
end
|
||||
|
||||
def path_customized?
|
||||
!path.match?(/[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}/)
|
||||
end
|
||||
|
||||
def organisation_name
|
||||
service&.nom || organisation
|
||||
end
|
||||
|
@ -802,12 +772,6 @@ class Procedure < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def ensure_path_exists
|
||||
if self.path.blank?
|
||||
self.path = SecureRandom.uuid
|
||||
end
|
||||
end
|
||||
|
||||
def extend_conservation_for_dossiers
|
||||
return if !previous_changes.include?(:duree_conservation_dossiers_dans_ds)
|
||||
before, after = duree_conservation_dossiers_dans_ds_previous_change
|
||||
|
|
|
@ -1364,7 +1364,7 @@ describe Procedure do
|
|||
describe 'suggested_path' do
|
||||
let(:procedure) { create(:procedure, aasm_state: :publiee, libelle: 'Inscription au Collège', zones: [create(:zone)]) }
|
||||
|
||||
subject { procedure.suggested_path(procedure.administrateurs.first) }
|
||||
subject { procedure.suggested_path }
|
||||
|
||||
context 'when the path has been customized' do
|
||||
before { procedure.path = 'custom_path' }
|
||||
|
|
Loading…
Reference in a new issue