From 41feb7c601986ea2c12a971949e8455b92b0e239 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Tue, 2 Nov 2021 14:21:05 +0200 Subject: [PATCH 1/3] added trumail validator after update and implement simple email validator interaction --- app/interactions/actions/contact_update.rb | 18 ++++++++++++++++++ .../actions/simple_mail_validator.rb | 9 +++++++++ 2 files changed, 27 insertions(+) create mode 100644 app/interactions/actions/simple_mail_validator.rb diff --git a/app/interactions/actions/contact_update.rb b/app/interactions/actions/contact_update.rb index f66aae805..b34069a89 100644 --- a/app/interactions/actions/contact_update.rb +++ b/app/interactions/actions/contact_update.rb @@ -15,9 +15,27 @@ module Actions maybe_update_statuses maybe_update_ident if ident.present? maybe_attach_legal_doc + maybe_change_email commit end + def maybe_change_email + return if Rails.env.test? + + [:regex, :mx].each do |m| + # r = Truemail.validate(@new_attributes[:email], with: m) + r = Actions::SimpleMailValidator.run(email: @new_attributes[:email], level: m) + + unless r.success + contact.add_epp_error('2306', nil, r.errors, I18n.t(:client_side_status_editing_error)) + @error = true + return + end + end + + true + end + def maybe_remove_address return if Contact.address_processing? diff --git a/app/interactions/actions/simple_mail_validator.rb b/app/interactions/actions/simple_mail_validator.rb new file mode 100644 index 000000000..b96c3db46 --- /dev/null +++ b/app/interactions/actions/simple_mail_validator.rb @@ -0,0 +1,9 @@ +module Actions + module SimpleMailValidator + extend self + + def run(email:, level:) + Truemail.validate(email, with: level).result + end + end +end From 38e823b0dd8d8b4c9786733e2335cfb2c2b6e190 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Tue, 9 Nov 2021 13:45:41 +0200 Subject: [PATCH 2/3] changed error message --- app/interactions/actions/contact_update.rb | 3 +-- config/locales/en.yml | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/interactions/actions/contact_update.rb b/app/interactions/actions/contact_update.rb index b34069a89..3f8cfe61e 100644 --- a/app/interactions/actions/contact_update.rb +++ b/app/interactions/actions/contact_update.rb @@ -23,11 +23,10 @@ module Actions return if Rails.env.test? [:regex, :mx].each do |m| - # r = Truemail.validate(@new_attributes[:email], with: m) r = Actions::SimpleMailValidator.run(email: @new_attributes[:email], level: m) unless r.success - contact.add_epp_error('2306', nil, r.errors, I18n.t(:client_side_status_editing_error)) + contact.add_epp_error('2005', nil, r.errors, I18n.t(:parameter_value_syntax_error)) @error = true return end diff --git a/config/locales/en.yml b/config/locales/en.yml index 2ef9a5b81..f80b14533 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -371,6 +371,7 @@ en: sim_error: 'SIM application error' internal_error: 'Internal error' client_side_status_editing_error: 'Parameter value policy error. Client-side object status management not supported' + parameter_value_syntax_error: 'Parameter value syntax error: ' # DEPP activemodel: From 8dd7cd4b9c017bc0377ee5cecdee1498cc60f977 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Fri, 12 Nov 2021 11:32:01 +0200 Subject: [PATCH 3/3] added validation checker before create --- app/interactions/actions/contact_create.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/interactions/actions/contact_create.rb b/app/interactions/actions/contact_create.rb index 8c6cb2282..ad5612322 100644 --- a/app/interactions/actions/contact_create.rb +++ b/app/interactions/actions/contact_create.rb @@ -12,9 +12,26 @@ module Actions maybe_remove_address maybe_attach_legal_doc validate_ident + maybe_change_email commit end + def maybe_change_email + return if Rails.env.test? + + [:regex, :mx].each do |m| + r = Actions::SimpleMailValidator.run(email: contact.email, level: m) + + unless r.success + contact.add_epp_error('2005', nil, r.errors, I18n.t(:parameter_value_syntax_error)) + @error = true + return + end + end + + true + end + def maybe_remove_address return if Contact.address_processing?