add message when path is already taken when publishing a procedure

This commit is contained in:
Lisa Durand 2024-03-14 17:17:47 +01:00
parent 5f826cfd88
commit e757eefd37
12 changed files with 70 additions and 15 deletions

View file

@ -387,7 +387,7 @@ class Procedure < ApplicationRecord
slug = libelle&.parameterize&.first(50)
suggestion = slug
counter = 1
while !path_available?(administrateur, suggestion)
while !path_available?(suggestion)
counter = counter + 1
suggestion = "#{slug}-#{counter}"
end
@ -400,10 +400,8 @@ class Procedure < ApplicationRecord
.find_by(path: path)
end
def path_available?(administrateur, path)
procedure = other_procedure_with_path(path)
procedure.blank? || (administrateur.owns?(procedure) && canonical_procedure_child?(procedure))
def path_available?(path)
other_procedure_with_path(path).blank?
end
def canonical_procedure_child?(procedure)