From cb6601ce1dc688a61a4d69b448b9242828842ee3 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Tue, 12 Jan 2016 14:10:34 +0200 Subject: [PATCH 1/5] Story#111396470 - show special message on contact ident update --- app/models/contact.rb | 5 +++-- app/models/epp/contact.rb | 1 + config/locales/en.yml | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index ccc44851d..573ffe22e 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -238,13 +238,14 @@ class Contact < ActiveRecord::Base def ident_valid_format? case ident_country_code when 'EE'.freeze + err_msg = "invalid_EE_identity_format#{"__update" if id}".to_sym case ident_type when 'priv'.freeze - errors.add(:ident, :invalid_EE_identity_format) unless Isikukood.new(ident).valid? + errors.add(:ident, err_msg) unless Isikukood.new(ident).valid? when 'org'.freeze # !%w(1 7 8 9).freeze.include?(ident.first) || if ident.size != 8 || !(ident =~/\A[0-9]{8}\z/) - errors.add(:ident, :invalid_EE_identity_format) + errors.add(:ident, err_msg) end end end diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index f4773f732..5f0a7b209 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -123,6 +123,7 @@ class Epp::Contact < Contact [:email, :invalid], [:ident, :invalid], [:ident, :invalid_EE_identity_format], + [:ident, :invalid_EE_identity_format_update], [:ident, :invalid_birthday_format], [:ident, :invalid_country_code], [:ident_type, :missing], diff --git a/config/locales/en.yml b/config/locales/en.yml index 893fe5665..61a476ab6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -49,6 +49,7 @@ en: ident: blank: "Required parameter missing - ident" invalid_EE_identity_format: "Ident not in valid Estonian identity format." + invalid_EE_identity_format_update: "Ident not in valid Estonian identity format. Please create new contact" invalid_birthday_format: "Ident not in valid birthady format, should be YYYY-MM-DD" invalid_country_code: "Ident country code is not valid, should be in ISO_3166-1 alpha 2 format" domains: From a20df5243a921a1bc762e02eb4d86d1651addf52 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Tue, 12 Jan 2016 14:24:32 +0200 Subject: [PATCH 2/5] Story#111396470 - show special message on contact ident update (typo fix) --- app/models/contact.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index 573ffe22e..75f03de09 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -238,7 +238,7 @@ class Contact < ActiveRecord::Base def ident_valid_format? case ident_country_code when 'EE'.freeze - err_msg = "invalid_EE_identity_format#{"__update" if id}".to_sym + err_msg = "invalid_EE_identity_format#{"_update" if id}".to_sym case ident_type when 'priv'.freeze errors.add(:ident, err_msg) unless Isikukood.new(ident).valid? From e27cd0c31676675858fd4cd6f455ce99486e2a33 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Tue, 12 Jan 2016 17:11:31 +0200 Subject: [PATCH 3/5] Story#111396470 - better code --- app/models/contact.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index 75f03de09..99a41a6a4 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -29,7 +29,7 @@ class Contact < ActiveRecord::Base uniqueness: { message: :epp_id_taken }, format: { with: /\A[\w\-\:\.\_]*\z/i, message: :invalid }, length: { maximum: 100, message: :too_long_contact_code } - validate :ident_valid_format? + validate :val_ident_valid_format? validate :uniq_statuses? validate :validate_html @@ -235,7 +235,7 @@ class Contact < ActiveRecord::Base name || '[no name]' end - def ident_valid_format? + def val_ident_valid_format? case ident_country_code when 'EE'.freeze err_msg = "invalid_EE_identity_format#{"_update" if id}".to_sym From da2f30f8a9c95c6254798452ff8461d783353d37 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Thu, 28 Jan 2016 13:10:32 +0200 Subject: [PATCH 4/5] Story#109590460 - fix ruby bug in comparing with regexp --- app/models/epp/contact.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index 5f0a7b209..3526cd463 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -165,7 +165,7 @@ class Epp::Contact < Contact org_priv = %w(org priv).freeze if ident_country_code.blank? && org_priv.include?(ident_type) && org_priv.include?(ident_frame.attr('type')) at.merge!(ident_country_code: ident_frame.attr('cc'), ident_type: ident_frame.attr('type')) - elsif ident_type == "birthday" && ident !=~ /\d{4}-\d{2}-\d{2}/ && (Date.parse(ident) rescue false) + elsif ident_type == "birthday" && ident[/\A\d{4}-\d{2}-\d{2}\z/] && (Date.parse(ident) rescue false) at.merge!(ident: ident_frame.text) at.merge!(ident_country_code: ident_frame.attr('cc')) if ident_frame.attr('cc').present? elsif ident_type.blank? && ident_country_code.blank? From f1d4d1f5522d69e2efdfa8059728b05485932d2a Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Thu, 28 Jan 2016 14:39:39 +0200 Subject: [PATCH 5/5] Story#109590460 - fix --- app/models/epp/contact.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index 3526cd463..54806b88d 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -165,7 +165,7 @@ class Epp::Contact < Contact org_priv = %w(org priv).freeze if ident_country_code.blank? && org_priv.include?(ident_type) && org_priv.include?(ident_frame.attr('type')) at.merge!(ident_country_code: ident_frame.attr('cc'), ident_type: ident_frame.attr('type')) - elsif ident_type == "birthday" && ident[/\A\d{4}-\d{2}-\d{2}\z/] && (Date.parse(ident) rescue false) + elsif ident_type == "birthday" && !ident[/\A\d{4}-\d{2}-\d{2}\z/] && (Date.parse(ident) rescue false) at.merge!(ident: ident_frame.text) at.merge!(ident_country_code: ident_frame.attr('cc')) if ident_frame.attr('cc').present? elsif ident_type.blank? && ident_country_code.blank?