From 0f4a67d6961dcd0c93699f1eaae0442955c90040 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 28 Mar 2019 00:17:48 +0200 Subject: [PATCH] Remove delegations --- app/jobs/domain_delete_confirm_email_job.rb | 2 +- app/jobs/registrant_change_confirm_email_job.rb | 2 +- app/mailers/registrant_change_mailer.rb | 2 +- app/models/contact.rb | 1 - app/models/domain.rb | 14 -------------- app/presenters/domain_presenter.rb | 2 +- .../registrar/domain_list_csv_presenter.rb | 4 ++-- app/views/admin/domains/partials/_owner.haml | 8 ++++---- app/views/epp/domains/info.xml.builder | 2 +- .../pending_delete_expired_notification.html.erb | 4 ++-- .../pending_delete_expired_notification.text.erb | 4 ++-- .../pending_delete_rejected_notification.html.erb | 4 ++-- .../pending_delete_rejected_notification.text.erb | 4 ++-- .../registrant/domain_delete_confirms/show.haml | 2 +- .../registrant/domain_update_confirms/show.haml | 2 +- spec/presenters/domain_presenter_spec.rb | 3 +-- .../registrant_change/same_as_current_spec.rb | 8 ++++---- .../update/registrant_change/verified_spec.rb | 8 ++++---- 18 files changed, 30 insertions(+), 46 deletions(-) diff --git a/app/jobs/domain_delete_confirm_email_job.rb b/app/jobs/domain_delete_confirm_email_job.rb index 65cf948f9..d2f2911e3 100644 --- a/app/jobs/domain_delete_confirm_email_job.rb +++ b/app/jobs/domain_delete_confirm_email_job.rb @@ -12,7 +12,7 @@ class DomainDeleteConfirmEmailJob < Que::Job def log(domain) message = "Send DomainDeleteMailer#confirm email for domain #{domain.name} (##{domain.id})" \ - " to #{domain.registrant_email}" + " to #{domain.registrant.email}" logger.info(message) end diff --git a/app/jobs/registrant_change_confirm_email_job.rb b/app/jobs/registrant_change_confirm_email_job.rb index 7d2dd79ad..0fced48d8 100644 --- a/app/jobs/registrant_change_confirm_email_job.rb +++ b/app/jobs/registrant_change_confirm_email_job.rb @@ -13,7 +13,7 @@ class RegistrantChangeConfirmEmailJob < Que::Job private def log(domain) - message = "Send RegistrantChangeMailer#confirm email for domain #{domain.name} (##{domain.id}) to #{domain.registrant_email}" + message = "Send RegistrantChangeMailer#confirm email for domain #{domain.name} (##{domain.id}) to #{domain.registrant.email}" logger.info(message) end diff --git a/app/mailers/registrant_change_mailer.rb b/app/mailers/registrant_change_mailer.rb index 92ee0bd4d..2ba7e497e 100644 --- a/app/mailers/registrant_change_mailer.rb +++ b/app/mailers/registrant_change_mailer.rb @@ -23,7 +23,7 @@ class RegistrantChangeMailer < ApplicationMailer def confirmed(domain:, old_registrant:) @domain = domain - recipients = [domain.registrant_email, old_registrant.email] + recipients = [domain.registrant.email, old_registrant.email] subject = default_i18n_subject(domain_name: domain.name) mail(to: recipients, subject: subject) diff --git a/app/models/contact.rb b/app/models/contact.rb index 1ad338806..f73c0c6fe 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -59,7 +59,6 @@ class Contact < ActiveRecord::Base return nil unless deliver_emails == true emails = [] emails << [email, email_was] - # emails << domains.map(&:registrant_email) if domains.present? emails = emails.flatten.uniq emails.each do |e| ContactMailer.email_updated(email_was, e, id, deliver_emails).deliver diff --git a/app/models/domain.rb b/app/models/domain.rb index 5ae0cbbb6..e767b7a47 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -59,20 +59,6 @@ class Domain < ActiveRecord::Base has_many :legal_documents, as: :documentable accepts_nested_attributes_for :legal_documents, reject_if: proc { |attrs| attrs[:body].blank? } - delegate :name, to: :registrant, prefix: true - delegate :code, to: :registrant, prefix: true - delegate :ident, to: :registrant, prefix: true - delegate :email, to: :registrant, prefix: true - delegate :phone, to: :registrant, prefix: true - delegate :street, to: :registrant, prefix: true - delegate :city, to: :registrant, prefix: true - delegate :zip, to: :registrant, prefix: true - delegate :state, to: :registrant, prefix: true - delegate :country, to: :registrant, prefix: true - - delegate :name, to: :registrar, prefix: true - delegate :street, to: :registrar, prefix: true - after_initialize do self.pending_json = {} if pending_json.blank? self.statuses = [] if statuses.nil? diff --git a/app/presenters/domain_presenter.rb b/app/presenters/domain_presenter.rb index 1a99bf3a1..f65262080 100644 --- a/app/presenters/domain_presenter.rb +++ b/app/presenters/domain_presenter.rb @@ -1,5 +1,5 @@ class DomainPresenter - delegate :name, :transfer_code, :registrant_name, :registrant_id, :registrant_code, to: :domain + delegate :name, :transfer_code, :registrant, :registrant_id, to: :domain def initialize(domain:, view:) @domain = domain diff --git a/app/presenters/registrar/domain_list_csv_presenter.rb b/app/presenters/registrar/domain_list_csv_presenter.rb index 5b47cfdcf..46b11f80b 100644 --- a/app/presenters/registrar/domain_list_csv_presenter.rb +++ b/app/presenters/registrar/domain_list_csv_presenter.rb @@ -34,8 +34,8 @@ class Registrar::DomainListCSVPresenter row = [] row[0] = domain.name row[1] = domain.transfer_code - row[2] = domain.registrant_name - row[3] = domain.registrant_code + row[2] = domain.registrant.name + row[3] = domain.registrant.code row[4] = domain.expire_date row diff --git a/app/views/admin/domains/partials/_owner.haml b/app/views/admin/domains/partials/_owner.haml index c08170650..611cd7dc6 100644 --- a/app/views/admin/domains/partials/_owner.haml +++ b/app/views/admin/domains/partials/_owner.haml @@ -7,13 +7,13 @@ %dd= link_to(@domain.registrant, [:admin, @domain.registrant]) %dt= t(:id) - %dd= @domain.registrant_code + %dd= @domain.registrant.code %dt= t(:identity_code) - %dd= @domain.registrant_ident + %dd= @domain.registrant.ident %dt= t(:email) - %dd= @domain.registrant_email + %dd= @domain.registrant.email %dt= t(:phone) - %dd= @domain.registrant_phone + %dd= @domain.registrant.phone diff --git a/app/views/epp/domains/info.xml.builder b/app/views/epp/domains/info.xml.builder index 5424b73d4..937da30a4 100644 --- a/app/views/epp/domains/info.xml.builder +++ b/app/views/epp/domains/info.xml.builder @@ -12,7 +12,7 @@ xml.epp_head do xml.tag!('domain:status', 's' => s) end - xml.tag!('domain:registrant', @domain.registrant_code) + xml.tag!('domain:registrant', @domain.registrant.code) @domain.tech_contacts.each do |tc| xml.tag!('domain:contact', tc.code, 'type' => 'tech') diff --git a/app/views/mailers/domain_mailer/pending_delete_expired_notification.html.erb b/app/views/mailers/domain_mailer/pending_delete_expired_notification.html.erb index ae3dea358..c753a8913 100644 --- a/app/views/mailers/domain_mailer/pending_delete_expired_notification.html.erb +++ b/app/views/mailers/domain_mailer/pending_delete_expired_notification.html.erb @@ -1,6 +1,6 @@ Tere

-Domeeni <%= @domain.name %> kustutamise taotlust ei kinnitatud tähtaegselt registreerija <%= @domain.registrant_name %> poolt. Domeeni <%= @domain.name %> kustutamine on sellest tulenevalt tühistatud. +Domeeni <%= @domain.name %> kustutamise taotlust ei kinnitatud tähtaegselt registreerija <%= @domain.registrant.name %> poolt. Domeeni <%= @domain.name %> kustutamine on sellest tulenevalt tühistatud.

Lugupidamisega
Eesti Interneti Sihtasutus @@ -9,7 +9,7 @@ Eesti Interneti Sihtasutus

Hi,

-Domain <%= @domain.name %> deletion was not approved in time by the registrant <%= @domain.registrant_name %>. Thus the deletion of domain <%= @domain.name %> is cancelled. +Domain <%= @domain.name %> deletion was not approved in time by the registrant <%= @domain.registrant.name %>. Thus the deletion of domain <%= @domain.name %> is cancelled.

Best Regards,
Estonian Internet Foundation diff --git a/app/views/mailers/domain_mailer/pending_delete_expired_notification.text.erb b/app/views/mailers/domain_mailer/pending_delete_expired_notification.text.erb index efd6eb449..e5eb5393a 100644 --- a/app/views/mailers/domain_mailer/pending_delete_expired_notification.text.erb +++ b/app/views/mailers/domain_mailer/pending_delete_expired_notification.text.erb @@ -1,6 +1,6 @@ Tere -Domeeni <%= @domain.name %> kustutamise taotlust ei kinnitatud tähtaegselt registreerija <%= @domain.registrant_name %> poolt. Domeeni <%= @domain.name %> kustutamine on sellest tulenevalt tühistatud. +Domeeni <%= @domain.name %> kustutamise taotlust ei kinnitatud tähtaegselt registreerija <%= @domain.registrant.name %> poolt. Domeeni <%= @domain.name %> kustutamine on sellest tulenevalt tühistatud. Lugupidamisega Eesti Interneti Sihtasutus @@ -9,7 +9,7 @@ Eesti Interneti Sihtasutus Hi, -Domain <%= @domain.name %> deletion was not approved in time by the registrant <%= @domain.registrant_name %>. Thus the deletion of domain <%= @domain.name %> is cancelled. +Domain <%= @domain.name %> deletion was not approved in time by the registrant <%= @domain.registrant.name %>. Thus the deletion of domain <%= @domain.name %> is cancelled. Best Regards, Estonian Internet Foundation diff --git a/app/views/mailers/domain_mailer/pending_delete_rejected_notification.html.erb b/app/views/mailers/domain_mailer/pending_delete_rejected_notification.html.erb index 9f381b2c5..814e32c7b 100644 --- a/app/views/mailers/domain_mailer/pending_delete_rejected_notification.html.erb +++ b/app/views/mailers/domain_mailer/pending_delete_rejected_notification.html.erb @@ -1,6 +1,6 @@ Tere

-Domeeni <%= @domain.name %> kustutamise taotlus on registreerija <%= @domain.registrant_name %> poolt tagasi lükatud. +Domeeni <%= @domain.name %> kustutamise taotlus on registreerija <%= @domain.registrant.name %> poolt tagasi lükatud.

Lugupidamisega
Eesti Interneti Sihtasutus @@ -9,7 +9,7 @@ Eesti Interneti Sihtasutus

Hi,

-Domain <%= @domain.name %> deletion was rejected by the registrant <%= @domain.registrant_name %>. +Domain <%= @domain.name %> deletion was rejected by the registrant <%= @domain.registrant.name %>.

Best Regards,
Estonian Internet Foundation diff --git a/app/views/mailers/domain_mailer/pending_delete_rejected_notification.text.erb b/app/views/mailers/domain_mailer/pending_delete_rejected_notification.text.erb index 8d49983a1..a24f51fde 100644 --- a/app/views/mailers/domain_mailer/pending_delete_rejected_notification.text.erb +++ b/app/views/mailers/domain_mailer/pending_delete_rejected_notification.text.erb @@ -1,6 +1,6 @@ Tere -Domeeni <%= @domain.name %> kustutamise taotlus on registreerija <%= @domain.registrant_name %> poolt tagasi lükatud. +Domeeni <%= @domain.name %> kustutamise taotlus on registreerija <%= @domain.registrant.name %> poolt tagasi lükatud. Lugupidamisega Eesti Interneti Sihtasutus @@ -9,7 +9,7 @@ Eesti Interneti Sihtasutus Hi, -Domain <%= @domain.name %> deletion was rejected by the registrant <%= @domain.registrant_name %>. +Domain <%= @domain.name %> deletion was rejected by the registrant <%= @domain.registrant.name %>. Best Regards, Estonian Internet Foundation diff --git a/app/views/registrant/domain_delete_confirms/show.haml b/app/views/registrant/domain_delete_confirms/show.haml index e2b42b56d..fffc03219 100644 --- a/app/views/registrant/domain_delete_confirms/show.haml +++ b/app/views/registrant/domain_delete_confirms/show.haml @@ -29,7 +29,7 @@ %p= t('.registrant') + ':' .column-values %p= @domain.name - %p= "#{@domain.registrant_name} (#{@domain.registrant.ident})" + %p= "#{@domain.registrant.name} (#{@domain.registrant.ident})" .row .col-md-12.text-center diff --git a/app/views/registrant/domain_update_confirms/show.haml b/app/views/registrant/domain_update_confirms/show.haml index 796638109..5f7a978ce 100644 --- a/app/views/registrant/domain_update_confirms/show.haml +++ b/app/views/registrant/domain_update_confirms/show.haml @@ -30,7 +30,7 @@ %p= t(:new_pending_registrant) + ':' .column-values %p= @domain.name - %p= "#{@domain.registrant_name} (#{@domain.registrant.ident})" + %p= "#{@domain.registrant.name} (#{@domain.registrant.ident})" %p= "#{@domain.pending_registrant.try(:name)} (#{@domain.pending_registrant.try(:ident)})" .row diff --git a/spec/presenters/domain_presenter_spec.rb b/spec/presenters/domain_presenter_spec.rb index 410c41e2e..06f2e33ec 100644 --- a/spec/presenters/domain_presenter_spec.rb +++ b/spec/presenters/domain_presenter_spec.rb @@ -81,9 +81,8 @@ RSpec.describe DomainPresenter do domain_delegatable_attributes = %i( name transfer_code - registrant_name + registrant registrant_id - registrant_code ) domain_delegatable_attributes.each do |attribute_name| diff --git a/spec/requests/epp/domain/update/registrant_change/same_as_current_spec.rb b/spec/requests/epp/domain/update/registrant_change/same_as_current_spec.rb index 46db358c5..46ea197da 100644 --- a/spec/requests/epp/domain/update/registrant_change/same_as_current_spec.rb +++ b/spec/requests/epp/domain/update/registrant_change/same_as_current_spec.rb @@ -46,7 +46,7 @@ RSpec.describe 'EPP domain:update' do end it 'keeps same registrant' do - expect { request; domain.reload }.to_not change { domain.registrant_code } + expect { request; domain.reload }.to_not change { domain.registrant.code } end it 'does not ask for confirmation' do @@ -91,7 +91,7 @@ RSpec.describe 'EPP domain:update' do end it 'does not change registrant without confirmation' do - expect { request; domain.reload }.to_not change { domain.registrant_code } + expect { request; domain.reload }.to_not change { domain.registrant.code } end it 'asks for confirmation' do @@ -147,7 +147,7 @@ RSpec.describe 'EPP domain:update' do end it 'keeps same registrant' do - expect { request; domain.reload }.to_not change { domain.registrant_code } + expect { request; domain.reload }.to_not change { domain.registrant.code } end it 'does not ask for confirmation' do @@ -192,7 +192,7 @@ RSpec.describe 'EPP domain:update' do end it 'changes registrant without confirmation' do - expect { request; domain.reload }.to change { domain.registrant_code }.from('OLD-CODE').to('NEW-CODE') + expect { request; domain.reload }.to change { domain.registrant.code }.from('OLD-CODE').to('NEW-CODE') end it 'does not ask for confirmation' do diff --git a/spec/requests/epp/domain/update/registrant_change/verified_spec.rb b/spec/requests/epp/domain/update/registrant_change/verified_spec.rb index 0675d5aae..5e0cee39d 100644 --- a/spec/requests/epp/domain/update/registrant_change/verified_spec.rb +++ b/spec/requests/epp/domain/update/registrant_change/verified_spec.rb @@ -47,7 +47,7 @@ RSpec.describe 'EPP domain:update' do end it 'changes registrant' do - expect { request; domain.reload }.to change { domain.registrant_code }.from('old-code').to('new-code') + expect { request; domain.reload }.to change { domain.registrant.code }.from('old-code').to('new-code') end it 'does not send confirmation email' do @@ -90,7 +90,7 @@ RSpec.describe 'EPP domain:update' do end it 'does not change registrant' do - expect { request; domain.reload }.to_not change { domain.registrant_code } + expect { request; domain.reload }.to_not change { domain.registrant.code } end it 'sends confirmation and notice emails' do @@ -139,7 +139,7 @@ RSpec.describe 'EPP domain:update' do end it 'changes registrant' do - expect { request; domain.reload }.to change { domain.registrant_code }.from('old-code').to('new-code') + expect { request; domain.reload }.to change { domain.registrant.code }.from('old-code').to('new-code') end it 'does not send confirmation email' do @@ -182,7 +182,7 @@ RSpec.describe 'EPP domain:update' do end it 'changes registrant' do - expect { request; domain.reload }.to change { domain.registrant_code }.from('old-code').to('new-code') + expect { request; domain.reload }.to change { domain.registrant.code }.from('old-code').to('new-code') end it 'does not send confirmation email' do