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:
parent
30bc4aa5d3
commit
86b44cd0a4
7 changed files with 23 additions and 9 deletions
|
@ -32,6 +32,10 @@ module DossierRebaseConcern
|
|||
!champs.filter { _1.stable_id == stable_id }.any? { _1.in?(options) }
|
||||
end
|
||||
|
||||
def can_rebase_expression_reguliere_change?(stable_id, expression_reguliere)
|
||||
false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def accepted_en_construction_changes?
|
||||
|
|
|
@ -60,7 +60,6 @@ class ProcedureRevisionChange
|
|||
|
||||
def can_rebase?(dossier = nil)
|
||||
return true if private?
|
||||
|
||||
case attribute
|
||||
when :drop_down_options
|
||||
(from - to).empty? || dossier&.can_rebase_drop_down_options_change?(stable_id, from - to)
|
||||
|
@ -68,7 +67,7 @@ class ProcedureRevisionChange
|
|||
!from && to
|
||||
when :mandatory
|
||||
(from && !to) || dossier&.can_rebase_mandatory_change?(stable_id)
|
||||
when :type_champ, :condition
|
||||
when :type_champ, :condition, :expression_reguliere
|
||||
false
|
||||
else
|
||||
true
|
||||
|
|
|
@ -2,7 +2,7 @@ class ExpressionReguliereValidator < ActiveModel::Validator
|
|||
def validate(record)
|
||||
if record.value.present?
|
||||
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
|
||||
rescue Regexp::TimeoutError
|
||||
|
|
|
@ -687,7 +687,6 @@ en:
|
|||
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
|
||||
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."
|
||||
# cadastres_empty:
|
||||
# one: "Aucune parcelle cadastrale sur la zone sélectionnée"
|
||||
|
|
|
@ -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
|
||||
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
|
||||
invalid_regexp: "%{expression_reguliere_error_message}"
|
||||
empty_repetition: '« %{value} » doit comporter au moins un champ répétable'
|
||||
empty_drop_down: '« %{value} » doit comporter au moins un choix sélectionnable'
|
||||
# procedure_not_draft: "Cette démarche n’est maintenant plus en brouillon."
|
||||
|
|
|
@ -124,6 +124,21 @@ describe DossierRebaseConcern do
|
|||
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
|
||||
before do
|
||||
procedure.draft_revision.remove_type_de_champ(type_de_champ.stable_id)
|
||||
|
|
|
@ -1604,13 +1604,11 @@ describe Dossier, type: :model do
|
|||
before do
|
||||
champ = dossier.champs_public.first
|
||||
champ.value = expression_reguliere_exemple_text
|
||||
champ.save!
|
||||
dossier.reload
|
||||
dossier.save
|
||||
end
|
||||
|
||||
it 'should not have errors' do
|
||||
expect(errors).not_to be_empty
|
||||
expect(errors.first).to be_nil
|
||||
expect(dossier.errors).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue