iamelioration(champ.expression_reguliere): empeche le rebase lorsqu'il y a un changement sur un type de champ expression reguliere.

Plus quelques adaptation de style cf: pas besoin d'executer la validation du champs expression reguliere dans controller, le validateur le fait sur le champ au moment de sauver le dossier avec le bon context
This commit is contained in:
Martin 2023-10-13 14:27:03 +02:00 committed by Kara Diaby
parent 30bc4aa5d3
commit 86b44cd0a4
7 changed files with 23 additions and 9 deletions

View file

@ -32,6 +32,10 @@ module DossierRebaseConcern
!champs.filter { _1.stable_id == stable_id }.any? { _1.in?(options) } !champs.filter { _1.stable_id == stable_id }.any? { _1.in?(options) }
end end
def can_rebase_expression_reguliere_change?(stable_id, expression_reguliere)
false
end
private private
def accepted_en_construction_changes? def accepted_en_construction_changes?

View file

@ -60,7 +60,6 @@ class ProcedureRevisionChange
def can_rebase?(dossier = nil) def can_rebase?(dossier = nil)
return true if private? return true if private?
case attribute case attribute
when :drop_down_options when :drop_down_options
(from - to).empty? || dossier&.can_rebase_drop_down_options_change?(stable_id, from - to) (from - to).empty? || dossier&.can_rebase_drop_down_options_change?(stable_id, from - to)
@ -68,7 +67,7 @@ class ProcedureRevisionChange
!from && to !from && to
when :mandatory when :mandatory
(from && !to) || dossier&.can_rebase_mandatory_change?(stable_id) (from && !to) || dossier&.can_rebase_mandatory_change?(stable_id)
when :type_champ, :condition when :type_champ, :condition, :expression_reguliere
false false
else else
true true

View file

@ -2,7 +2,7 @@ class ExpressionReguliereValidator < ActiveModel::Validator
def validate(record) def validate(record)
if record.value.present? if record.value.present?
if !record.value.match?(Regexp.new(record.expression_reguliere, timeout: 5.0)) if !record.value.match?(Regexp.new(record.expression_reguliere, timeout: 5.0))
record.errors.add(:value, I18n.t('errors.messages.invalid_regexp', expression_reguliere_error_message: record.expression_reguliere_error_message)) record.errors.add(:value, :invalid_regexp)
end end
end end
rescue Regexp::TimeoutError rescue Regexp::TimeoutError

View file

@ -687,7 +687,6 @@ en:
evil_regexp: The regular expression you have entered is potentially dangerous and could lead to performance issues. evil_regexp: The regular expression you have entered is potentially dangerous and could lead to performance issues.
mismatch_regexp: The provided example must match the regular expression mismatch_regexp: The provided example must match the regular expression
syntax_error_regexp: The syntax of the regular expression is invalid syntax_error_regexp: The syntax of the regular expression is invalid
invalid_regexp: "%{expression_reguliere_error_message}"
# # procedure_not_draft: "This procedure is not a draft anymore." # # procedure_not_draft: "This procedure is not a draft anymore."
# cadastres_empty: # cadastres_empty:
# one: "Aucune parcelle cadastrale sur la zone sélectionnée" # one: "Aucune parcelle cadastrale sur la zone sélectionnée"

View file

@ -692,7 +692,6 @@ fr:
evil_regexp: L'expression régulière que vous avez entrée est potentiellement dangereuse et pourrait entraîner des problèmes de performance evil_regexp: L'expression régulière que vous avez entrée est potentiellement dangereuse et pourrait entraîner des problèmes de performance
mismatch_regexp: L'exemple doit correspondre à l'expression régulière fournie mismatch_regexp: L'exemple doit correspondre à l'expression régulière fournie
syntax_error_regexp: La syntaxe de l'expression régulière n'est pas valide syntax_error_regexp: La syntaxe de l'expression régulière n'est pas valide
invalid_regexp: "%{expression_reguliere_error_message}"
empty_repetition: '« %{value} » doit comporter au moins un champ répétable' empty_repetition: '« %{value} » doit comporter au moins un champ répétable'
empty_drop_down: '« %{value} » doit comporter au moins un choix sélectionnable' empty_drop_down: '« %{value} » doit comporter au moins un choix sélectionnable'
# procedure_not_draft: "Cette démarche nest maintenant plus en brouillon." # procedure_not_draft: "Cette démarche nest maintenant plus en brouillon."

View file

@ -124,6 +124,21 @@ describe DossierRebaseConcern do
end end
end end
context 'with type de champ regexp and regexp change' do
let(:procedure) { create(:procedure, types_de_champ_public: [{ mandatory: true }, { type: :expression_reguliere }], types_de_champ_private: [{}]) }
before do
procedure.draft_revision.find_and_ensure_exclusive_use(type_de_champ.stable_id).update(expression_reguliere: /\d+/)
procedure.publish_revision!
dossier.reload
end
it 'should be false' do
expect(dossier.pending_changes).not_to be_empty
expect(dossier.can_rebase?).to be_falsey
end
end
context 'with removed type de champ' do context 'with removed type de champ' do
before do before do
procedure.draft_revision.remove_type_de_champ(type_de_champ.stable_id) procedure.draft_revision.remove_type_de_champ(type_de_champ.stable_id)

View file

@ -1604,13 +1604,11 @@ describe Dossier, type: :model do
before do before do
champ = dossier.champs_public.first champ = dossier.champs_public.first
champ.value = expression_reguliere_exemple_text champ.value = expression_reguliere_exemple_text
champ.save! dossier.save
dossier.reload
end end
it 'should not have errors' do it 'should not have errors' do
expect(errors).not_to be_empty expect(dossier.errors).to be_empty
expect(errors.first).to be_nil
end end
end end
end end