From f9b2d2a20280f6cf41e99be9090f2a1c007b534c Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Mon, 30 Nov 2015 13:12:51 +0200 Subject: [PATCH 01/10] Story#107821878 - manage old registrar --- app/mailers/domain_mailer.rb | 5 ++--- app/models/domain.rb | 2 +- spec/mailers/domain_mailer_spec.rb | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index a149ff2ed..11789f1d3 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -1,8 +1,9 @@ class DomainMailer < ApplicationMailer include Que::Mailer - def pending_update_request_for_old_registrant(domain_id, should_deliver) + def pending_update_request_for_old_registrant(domain_id, old_registrant_id, should_deliver) @domain = Domain.find_by(id: domain_id) + @old_registrant = Registrant.find(old_registrant_id) return unless @domain return if delivery_off?(@domain, should_deliver) @@ -16,8 +17,6 @@ class DomainMailer < ApplicationMailer return end - @old_registrant = Registrant.find(@domain.registrant_id_was) - confirm_path = "#{ENV['registrant_url']}/registrant/domain_update_confirms" @verification_url = "#{confirm_path}/#{@domain.id}?token=#{@domain.registrant_verification_token}" diff --git a/app/models/domain.rb b/app/models/domain.rb index 6730497e9..def2926cf 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -428,7 +428,7 @@ class Domain < ActiveRecord::Base new_registrant_email = registrant.email new_registrant_name = registrant.name - DomainMailer.pending_update_request_for_old_registrant(id, deliver_emails).deliver + DomainMailer.pending_update_request_for_old_registrant(id, registrant_id_was, deliver_emails).deliver DomainMailer.pending_update_notification_for_new_registrant(id, deliver_emails).deliver reload # revert back to original diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb index 37605a668..3615fff29 100644 --- a/spec/mailers/domain_mailer_spec.rb +++ b/spec/mailers/domain_mailer_spec.rb @@ -9,7 +9,7 @@ describe DomainMailer do before :all do @registrant = Fabricate(:registrant, email: 'test@example.com') @domain = Fabricate(:domain, registrant: @registrant) - @mail = DomainMailer.pending_update_request_for_old_registrant(@domain.id, deliver_emails) + @mail = DomainMailer.pending_update_request_for_old_registrant(@domain.id, @registrant.id,deliver_emails) end it 'should not render email subject' do @@ -38,7 +38,7 @@ describe DomainMailer do @domain.registrant_verification_token = '123' @domain.registrant_verification_asked_at = Time.zone.now @domain.registrant = @new_registrant - @mail = DomainMailer.pending_update_request_for_old_registrant(@domain.id, deliver_emails) + @mail = DomainMailer.pending_update_request_for_old_registrant(@domain.id, @registrant.id, deliver_emails) end it 'should render email subject' do From 2141ac2183e548898d7d37e476598efdf5aee942 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Mon, 30 Nov 2015 13:14:08 +0200 Subject: [PATCH 02/10] Story#107821878 - manage old registrar --- app/models/domain.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index def2926cf..a8e86fb59 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -417,6 +417,7 @@ class Domain < ActiveRecord::Base end def pending_update! + old_registrar_id = registrar_id return true if pending_update? self.epp_pending_update = true # for epp @@ -428,7 +429,7 @@ class Domain < ActiveRecord::Base new_registrant_email = registrant.email new_registrant_name = registrant.name - DomainMailer.pending_update_request_for_old_registrant(id, registrant_id_was, deliver_emails).deliver + DomainMailer.pending_update_request_for_old_registrant(id, old_registrar_id, deliver_emails).deliver DomainMailer.pending_update_notification_for_new_registrant(id, deliver_emails).deliver reload # revert back to original From b389f8282f635f62bfd23ce2fb5d32a745c066f0 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Mon, 30 Nov 2015 13:30:43 +0200 Subject: [PATCH 03/10] Story#107821878 - manage old registrar (typo -> registrant_id) --- app/models/domain.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index a8e86fb59..ca1dc762e 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -417,7 +417,7 @@ class Domain < ActiveRecord::Base end def pending_update! - old_registrar_id = registrar_id + old_registrant_id = registrant_id return true if pending_update? self.epp_pending_update = true # for epp @@ -429,7 +429,7 @@ class Domain < ActiveRecord::Base new_registrant_email = registrant.email new_registrant_name = registrant.name - DomainMailer.pending_update_request_for_old_registrant(id, old_registrar_id, deliver_emails).deliver + DomainMailer.pending_update_request_for_old_registrant(id, old_registrant_id, deliver_emails).deliver DomainMailer.pending_update_notification_for_new_registrant(id, deliver_emails).deliver reload # revert back to original From 08b0633ed4028c4f03474117fe394723dedce1a4 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Mon, 30 Nov 2015 14:49:26 +0200 Subject: [PATCH 04/10] Story#109014746 - ident_country_code should be only on create for now --- 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 20c11ae80..9521cbb9b 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -23,7 +23,7 @@ class Contact < ActiveRecord::Base validates :ident, format: { with: /\d{4}-\d{2}-\d{2}/, message: :invalid_birthday_format }, if: proc { |c| c.ident_type == 'birthday' } - validates :ident_country_code, presence: true, if: proc { |c| %w(org priv).include? c.ident_type } + validates :ident_country_code, presence: true, if: proc { |c| %w(org priv).include? c.ident_type }, on: :create validates :code, uniqueness: { message: :epp_id_taken }, format: { with: /\A[\w\-\:]*\Z/i, message: :invalid }, From 94cf904469446ee80428398d08669a6cb7ebe95b Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Mon, 30 Nov 2015 14:55:40 +0200 Subject: [PATCH 05/10] Story#109014746 - delegate ident_attr_valid? to class --- app/models/epp/contact.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index 435a63dee..ec5673b06 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -104,6 +104,7 @@ class Epp::Contact < Contact res end end + delegate :ident_attr_valid?, to: :class def epp_code_map # rubocop:disable Metrics/MethodLength { From 7ae2adbb5ebefb5fb21c41fc060dab21f9742a37 Mon Sep 17 00:00:00 2001 From: Stas Date: Mon, 30 Nov 2015 15:13:46 +0200 Subject: [PATCH 06/10] 108624154-func_modification --- db/migrate/20151124200353_add_ident_autofill.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/db/migrate/20151124200353_add_ident_autofill.rb b/db/migrate/20151124200353_add_ident_autofill.rb index d4efb1449..8065bbc0a 100644 --- a/db/migrate/20151124200353_add_ident_autofill.rb +++ b/db/migrate/20151124200353_add_ident_autofill.rb @@ -45,12 +45,15 @@ class AddIdentAutofill < ActiveRecord::Migration END LOOP; mod := (total % 11); END IF; - - IF (mod < 10 AND substring(r.ident, 11, 1) = to_char(mod, 'FM999MI')) + IF (mod = 10) + THEN + mod := 0; + END IF; + IF (substring(r.ident, 11, 1) = to_char(mod, 'FM999MI')) THEN UPDATE contacts SET ident_country_code = 'EE' WHERE id = r.id; END IF; - total = 0; + total := 0; END IF; END LOOP; @@ -66,7 +69,7 @@ class AddIdentAutofill < ActiveRecord::Migration counter := (counter + 1); END LOOP; mod := total % 11; - total = 0; + total := 0; counter := 1; IF (mod >= 10) THEN @@ -78,7 +81,11 @@ class AddIdentAutofill < ActiveRecord::Migration END LOOP; mod := (total % 11); END IF; - IF (mod < 10 AND (substring(r.ident, 8, 1) = to_char(mod, 'FM999MI'))) + IF (mod = 10) + THEN + mod := 0; + END IF; + IF (substring(r.ident, 8, 1) = to_char(mod, 'FM999MI')) THEN UPDATE contacts SET ident_country_code = 'EE' WHERE id = r.id; END IF; From 44ae8fd350b9f8aebae97170f89077d4b1eb55e4 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Mon, 30 Nov 2015 15:32:55 +0200 Subject: [PATCH 07/10] Story#107821878 - pending_update_notification gets new registrant_id too --- app/mailers/domain_mailer.rb | 4 ++-- app/models/domain.rb | 2 +- spec/mailers/domain_mailer_spec.rb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index 11789f1d3..e7ecb9b17 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -26,8 +26,9 @@ class DomainMailer < ApplicationMailer name: @domain.name)} [#{@domain.name}]") end - def pending_update_notification_for_new_registrant(domain_id, should_deliver) + def pending_update_notification_for_new_registrant(domain_id, old_registrant_id, should_deliver) @domain = Domain.find_by(id: domain_id) + @old_registrant = Registrant.find(old_registrant_id) return unless @domain return if delivery_off?(@domain, should_deliver) @@ -42,7 +43,6 @@ class DomainMailer < ApplicationMailer end @new_registrant = @domain.registrant # NB! new registrant at this point - @old_registrant = Registrant.find(@domain.registrant_id_was) return if whitelist_blocked?(@new_registrant.email) mail(to: format(@new_registrant.email), diff --git a/app/models/domain.rb b/app/models/domain.rb index ca1dc762e..6a8544b63 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -430,7 +430,7 @@ class Domain < ActiveRecord::Base new_registrant_name = registrant.name DomainMailer.pending_update_request_for_old_registrant(id, old_registrant_id, deliver_emails).deliver - DomainMailer.pending_update_notification_for_new_registrant(id, deliver_emails).deliver + DomainMailer.pending_update_notification_for_new_registrant(id, old_registrant_id, deliver_emails).deliver reload # revert back to original diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb index 3615fff29..050cc344a 100644 --- a/spec/mailers/domain_mailer_spec.rb +++ b/spec/mailers/domain_mailer_spec.rb @@ -71,7 +71,7 @@ describe DomainMailer do @domain.registrant_verification_token = '123' @domain.registrant_verification_asked_at = Time.zone.now @domain.registrant = @new_registrant - @mail = DomainMailer.pending_update_notification_for_new_registrant(@domain.id, deliver_emails) + @mail = DomainMailer.pending_update_notification_for_new_registrant(@domain.id, @registrant.id, deliver_emails) end it 'should render email subject' do @@ -100,7 +100,7 @@ describe DomainMailer do @domain.registrant_verification_token = '123' @domain.registrant_verification_asked_at = Time.zone.now @domain.registrant = @new_registrant - @mail = DomainMailer.pending_update_notification_for_new_registrant(@domain.id, deliver_emails) + @mail = DomainMailer.pending_update_notification_for_new_registrant(@domain.id, @registrant.id, deliver_emails) end it 'should render email subject' do From 4fa286d0b0c744a52b36f2b601553d993c8413db Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Mon, 30 Nov 2015 15:37:17 +0200 Subject: [PATCH 08/10] Story#107821878 - pending_deleted gets new registrant_id too --- app/mailers/domain_mailer.rb | 5 ++--- app/models/domain.rb | 2 +- spec/mailers/domain_mailer_spec.rb | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index e7ecb9b17..7fe92130b 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -106,8 +106,9 @@ class DomainMailer < ApplicationMailer name: @domain.name)} [#{@domain.name}]") end - def pending_deleted(domain_id, should_deliver) + def pending_deleted(domain_id, old_registrant_id, should_deliver) @domain = Domain.find_by(id: domain_id) + @old_registrant = Registrant.find(old_registrant_id) return unless @domain return if delivery_off?(@domain, should_deliver) @@ -121,8 +122,6 @@ class DomainMailer < ApplicationMailer return end - @old_registrant = Registrant.find(@domain.registrant_id_was) - confirm_path = "#{ENV['registrant_url']}/registrant/domain_delete_confirms" @verification_url = "#{confirm_path}/#{@domain.id}?token=#{@domain.registrant_verification_token}" diff --git a/app/models/domain.rb b/app/models/domain.rb index 6a8544b63..074934a1d 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -490,7 +490,7 @@ class Domain < ActiveRecord::Base pending_delete_confirmation! save(validate: false) # should check if this did succeed - DomainMailer.pending_deleted(id, deliver_emails).deliver + DomainMailer.pending_deleted(id, registrant_id_was, deliver_emails).deliver end def pricelist(operation, period_i = nil, unit = nil) diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb index 050cc344a..3f645f7e0 100644 --- a/spec/mailers/domain_mailer_spec.rb +++ b/spec/mailers/domain_mailer_spec.rb @@ -202,7 +202,7 @@ describe DomainMailer do before :all do @registrant = Fabricate(:registrant, email: 'test@example.com') @domain = Fabricate(:domain, registrant: @registrant) - @mail = DomainMailer.pending_deleted(@domain.id, deliver_emails) + @mail = DomainMailer.pending_deleted(@domain.id, @registrant.id, deliver_emails) end it 'should not render email subject' do @@ -229,7 +229,7 @@ describe DomainMailer do @domain.deliver_emails = true @domain.registrant_verification_token = '123' @domain.registrant_verification_asked_at = Time.zone.now - @mail = DomainMailer.pending_deleted(@domain.id, deliver_emails) + @mail = DomainMailer.pending_deleted(@domain.id, @registrant.id, deliver_emails) end it 'should render email subject' do From 7b02f98af8d08e0c9757b3925c0f16ebfc01e179 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Mon, 30 Nov 2015 15:43:02 +0200 Subject: [PATCH 09/10] Story#107821878 - ContactsMailer#email_updated gets new attribute old_email --- app/mailers/contact_mailer.rb | 6 ++++-- app/models/contact.rb | 2 +- app/views/mailers/contact_mailer/email_updated.html.erb | 4 ++-- app/views/mailers/contact_mailer/email_updated.text.erb | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/mailers/contact_mailer.rb b/app/mailers/contact_mailer.rb index 110ce6a71..08beae05d 100644 --- a/app/mailers/contact_mailer.rb +++ b/app/mailers/contact_mailer.rb @@ -1,8 +1,10 @@ class ContactMailer < ApplicationMailer include Que::Mailer - def email_updated(email, contact_id, should_deliver) - @contact = Contact.find_by(id: contact_id) + def email_updated(old_email, email, contact_id, should_deliver) + @contact = Contact.find_by(id: contact_id) + @old_email = old_email + return unless email || @contact return if delivery_off?(@contact, should_deliver) return if whitelist_blocked?(email) diff --git a/app/models/contact.rb b/app/models/contact.rb index 20c11ae80..154a2e636 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -50,7 +50,7 @@ class Contact < ActiveRecord::Base emails << domains.map(&:registrant_email) if domains.present? emails = emails.flatten.uniq emails.each do |e| - ContactMailer.email_updated(e, id, deliver_emails).deliver + ContactMailer.email_updated(email_was, e, id, deliver_emails).deliver end end diff --git a/app/views/mailers/contact_mailer/email_updated.html.erb b/app/views/mailers/contact_mailer/email_updated.html.erb index 552e97cdf..cd5a75682 100644 --- a/app/views/mailers/contact_mailer/email_updated.html.erb +++ b/app/views/mailers/contact_mailer/email_updated.html.erb @@ -1,7 +1,7 @@ Tere <%= @contact.name %>

Kontakti <%= @contact.name %> eposti aadress on muudetud
-endine aadress: <%= @contact.email_was %>
+endine aadress: <%= @old_email %>
uus aadress: <%= @contact.email %>

Eposti aadressile saadetakse domeenidega seotud infot seal hulgas kinnitustaotluseid omaniku vahetuse ja domeeni kustutamise korral. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduga oma registripidaja poole. Teie registripidaja on <%= @contact.registrar.name %> @@ -30,7 +30,7 @@ Eesti Interneti SA Hi <%= @contact.name %>

E-mail address of <%= @contact.name %> has been changed
-previous address: <%= @contact.email_was %>
+previous address: <%= @old_email %>
new address: <%= @contact.email %>

E-mail addresses are used to send important information regarding your registered domains including applications for approval of registrant change and domain deletion. Please make sure that the update and contact information are correct. Incase of problems please turn to your registrar. Your registrar is <%= @contact.registrar.name %> diff --git a/app/views/mailers/contact_mailer/email_updated.text.erb b/app/views/mailers/contact_mailer/email_updated.text.erb index ce43b5401..a899c04c2 100644 --- a/app/views/mailers/contact_mailer/email_updated.text.erb +++ b/app/views/mailers/contact_mailer/email_updated.text.erb @@ -1,7 +1,7 @@ Tere <%= @contact.name %> Kontakti <%= @contact.name %> eposti aadress on muudetud -endine aadress: <%= @contact.email_was %> +endine aadress: <%= @old_email %> uus aadress: <%= @contact.email %> Eposti aadressile saadetakse domeenidega seotud infot seal hulgas kinnitustaotluseid omaniku vahetuse ja domeeni kustutamise korral. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduga oma registripidaja poole. Teie registripidaja on <%= @contact.registrar.name %> @@ -30,7 +30,7 @@ Eesti Interneti SA Hi <%= @contact.name %> E-mail address of <%= @contact.name %> has been changed -previous address: <%= @contact.email_was %> +previous address: <%= @old_email %> new address: <%= @contact.email %> E-mail addresses are used to send important information regarding your registered domains including applications for approval of registrant change and domain deletion. Please make sure that the update and contact information are correct. Incase of problems please turn to your registrar. Your registrar is <%= @contact.registrar.name %> From eddf3234fb7d6a99e515ffaea2f45e6937d1c584 Mon Sep 17 00:00:00 2001 From: Stas Date: Mon, 30 Nov 2015 18:06:24 +0200 Subject: [PATCH 10/10] 109119896-name_org_exception --- lib/tasks/import.rake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index 64aa9688c..1573848f1 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -250,7 +250,12 @@ namespace :import do next if existing_contact_ids.include?(x.id) count += 1 - name = x.name.try(:strip).presence || x.organization.try(:strip).presence + if 4 == x.ssntype + name = x.organization.try(:strip).presence || x.name.try(:strip).presence + else + name = x.name.try(:strip).presence || x.organization.try(:strip).presence + end + begin contacts << [ x.object_registry.name.try(:strip), @@ -262,7 +267,7 @@ namespace :import do x.ssn.try(:strip), ident_type_map[x.ssntype], x.object.authinfopw.try(:strip), - x.organization.try(:strip)? x.organization.try(:strip): name, + name, Registrar.find_by(legacy_id: x.object.try(:clid)).try(:id), x.object_registry.try(:registrar).try(:name), x.object.try(:registrar).try(:name) ? x.object.try(:registrar).try(:name) : x.object_registry.try(:registrar).try(:name),