From d14fa5b701b2b0c3f257bcf128493fc7dcf917e7 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 21 Jun 2019 17:49:47 +0300 Subject: [PATCH 1/3] Rename method --- app/models/contact.rb | 8 +++--- app/presenters/registrant_presenter.rb | 2 +- .../contact_mailer/email_changed.html.erb | 4 +-- .../contact_mailer/email_changed.text.erb | 4 +-- spec/presenters/registrant_presenter_spec.rb | 2 +- test/models/contact/contact_test.rb | 25 ++++++++++++++----- 6 files changed, 29 insertions(+), 16 deletions(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index f6b180a5e1..364a5d39ed 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -188,7 +188,7 @@ def destroy_orphans ver_scope << "(children->'#{type}')::jsonb <@ json_build_array(#{contact.id})::jsonb" end next if DomainVersion.where("created_at > ?", Time.now - Setting.orphans_contacts_in_months.to_i.months).where(ver_scope.join(" OR ")).any? - next if contact.in_use? + next if contact.linked? contact.destroy counter.next @@ -279,7 +279,7 @@ def statuses calculated.delete(Contact::OK) calculated.delete(Contact::LINKED) calculated << Contact::OK if calculated.empty?# && valid? - calculated << Contact::LINKED if in_use? + calculated << Contact::LINKED if linked? calculated.uniq end @@ -345,7 +345,7 @@ def country # no need separate method # should use only in transaction def destroy_and_clean frame - if in_use? + if linked? errors.add(:domains, :exist) return false end @@ -513,7 +513,7 @@ def ident_country Country.new(ident_country_code) end - def in_use? + def linked? registrant_domains.any? || domain_contacts.any? end diff --git a/app/presenters/registrant_presenter.rb b/app/presenters/registrant_presenter.rb index 6a78f86c57..4adf698e6c 100644 --- a/app/presenters/registrant_presenter.rb +++ b/app/presenters/registrant_presenter.rb @@ -8,7 +8,7 @@ class RegistrantPresenter :reg_no, :street, :city, :state, :zip, :country, :ident_country, - :in_use?, + :linked?, to: :registrant def initialize(registrant:, view:) diff --git a/app/views/mailers/contact_mailer/email_changed.html.erb b/app/views/mailers/contact_mailer/email_changed.html.erb index 65801f7568..35aa07cc35 100644 --- a/app/views/mailers/contact_mailer/email_changed.html.erb +++ b/app/views/mailers/contact_mailer/email_changed.html.erb @@ -10,7 +10,7 @@ uus aadress: <%= contact.email %>

E-posti aadressile saadetakse domeeni toimingutega seotud infot, sealhulgas kinnitustaotlused omanikuvahetuse ja domeeni kustutamise korral.

-<% if contact.in_use? %> +<% if contact.linked? %> Muudatusega seotud domeenid:
<%= contact.domain_names_with_roles(locale: :et, line_break: '
') %> <% end %> @@ -31,7 +31,7 @@ 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.

-<% if contact.in_use? %> +<% if contact.linked? %> Domains affected by this update:
<%= contact.domain_names_with_roles(line_break: '
') %> <% end %> diff --git a/app/views/mailers/contact_mailer/email_changed.text.erb b/app/views/mailers/contact_mailer/email_changed.text.erb index 55d92d679d..3b49fed80c 100644 --- a/app/views/mailers/contact_mailer/email_changed.text.erb +++ b/app/views/mailers/contact_mailer/email_changed.text.erb @@ -10,7 +10,7 @@ uus aadress: <%= contact.email %> E-posti aadressile saadetakse domeeni toimingutega seotud infot, sealhulgas kinnitustaotlused omanikuvahetuse ja domeeni kustutamise korral. -<% if contact.in_use? %> +<% if contact.linked? %> Muudatusega seotud domeenid: <%= contact.domain_names_with_roles(locale: :et) %> <% end %> @@ -32,7 +32,7 @@ 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. -<% if contact.in_use? %> +<% if contact.linked? %> Domains affected by this update: <%= contact.domain_names_with_roles %> <% end %> diff --git a/spec/presenters/registrant_presenter_spec.rb b/spec/presenters/registrant_presenter_spec.rb index 8c7c7b6d36..224a0504fc 100644 --- a/spec/presenters/registrant_presenter_spec.rb +++ b/spec/presenters/registrant_presenter_spec.rb @@ -67,7 +67,7 @@ zip id_code reg_no - in_use? + linked? ) registrant_delegatable_attributes.each do |attr_name| diff --git a/test/models/contact/contact_test.rb b/test/models/contact/contact_test.rb index 0c4fc1e4e3..e9301280e0 100644 --- a/test/models/contact/contact_test.rb +++ b/test/models/contact/contact_test.rb @@ -13,18 +13,23 @@ def test_invalid_fixture_is_invalid assert contacts(:invalid).invalid? end - def test_in_use_if_acts_as_a_registrant + def test_linked_when_in_use_as_registrant + Domain.update_all(registrant_id: @contact) DomainContact.delete_all - assert @contact.in_use? + + assert @contact.linked? end - def test_in_use_if_acts_as_a_domain_contact + def test_linked_when_in_use_as_domain_contact Domain.update_all(registrant_id: contacts(:william)) - assert @contact.in_use? + DomainContact.update_all(contact_id: @contact) + + assert @contact.linked? end - def test_not_in_use_if_acts_as_neither_registrant_nor_domain_contact - refute contacts(:not_in_use).in_use? + def test_unlinked_when_not_in_use_as_either_registrant_or_domain_contact + contact = unlinked_contact + assert_not contact.linked? end def test_managed_when_identity_codes_match @@ -38,4 +43,12 @@ def test_unmanaged_when_identity_codes_do_not_match user = RegistrantUser.new(registrant_ident: 'US-12345') assert_not contact.managed_by?(user) end + + private + + def unlinked_contact + Domain.update_all(registrant_id: contacts(:william)) + DomainContact.delete_all + contacts(:john) + end end From 7c768616a2e45c9cb74dc0b3881a73265608b2aa Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 21 Jun 2019 18:01:56 +0300 Subject: [PATCH 2/3] Introduce `Contact#deletable?` --- app/models/contact.rb | 4 +++ test/fixtures/contacts.yml | 8 ----- .../epp/contact/delete/base_test.rb | 29 +++++++++++-------- test/models/contact/contact_test.rb | 10 +++++++ 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index 364a5d39ed..5701cce946 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -552,4 +552,8 @@ def managed_by?(registrant_user) def registrant? registrant_domains.any? end + + def deletable? + !linked? + end end diff --git a/test/fixtures/contacts.yml b/test/fixtures/contacts.yml index 15b82148f1..ddfbfe93f3 100644 --- a/test/fixtures/contacts.yml +++ b/test/fixtures/contacts.yml @@ -78,14 +78,6 @@ identical_to_william: auth_info: 5ab865 uuid: c0a191d5-3793-4f0b-8f85-491612d0293e -not_in_use: - name: Useless - email: useless@inbox.test - registrar: bestnames - code: not-in-use - auth_info: e75a2a - uuid: ca613cc5-a8dc-48c1-8d32-d3c6a0b6c952 - invalid: name: any code: invalid diff --git a/test/integration/epp/contact/delete/base_test.rb b/test/integration/epp/contact/delete/base_test.rb index 9d7b4b861a..05e96d2486 100644 --- a/test/integration/epp/contact/delete/base_test.rb +++ b/test/integration/epp/contact/delete/base_test.rb @@ -1,15 +1,11 @@ require 'test_helper' class EppContactDeleteBaseTest < ActionDispatch::IntegrationTest - def setup - @contact = contacts(:john) - end - - def test_deletes_a_contact_that_is_not_in_use - @contact = contacts(:not_in_use) + def test_deletes_contact + contact = deletable_contact # https://github.com/internetee/registry/issues/415 - @contact.update_columns(code: @contact.code.upcase) + contact.update_columns(code: contact.code.upcase) request_xml = <<-XML @@ -17,7 +13,7 @@ def test_deletes_a_contact_that_is_not_in_use - not-in-use + #{contact.code} @@ -32,11 +28,12 @@ def test_deletes_a_contact_that_is_not_in_use assert_equal 1, response_xml.css('result').size end - def test_contact_that_is_in_use_cannot_be_deleted - assert_equal 'john-001', @contact.code + def test_undeletable_cannot_be_deleted + contact = contacts(:john) + assert_not contact.deletable? # https://github.com/internetee/registry/issues/415 - @contact.update_columns(code: @contact.code.upcase) + contact.update_columns(code: contact.code.upcase) request_xml = <<-XML @@ -44,7 +41,7 @@ def test_contact_that_is_in_use_cannot_be_deleted - john-001 + #{contact.code} @@ -57,4 +54,12 @@ def test_contact_that_is_in_use_cannot_be_deleted response_xml = Nokogiri::XML(response.body) assert_equal '2305', response_xml.at_css('result')[:code] end + + private + + def deletable_contact + Domain.update_all(registrant_id: contacts(:william)) + DomainContact.delete_all + contacts(:john) + end end \ No newline at end of file diff --git a/test/models/contact/contact_test.rb b/test/models/contact/contact_test.rb index e9301280e0..18c854190f 100644 --- a/test/models/contact/contact_test.rb +++ b/test/models/contact/contact_test.rb @@ -44,6 +44,16 @@ def test_unmanaged_when_identity_codes_do_not_match assert_not contact.managed_by?(user) end + def test_deletable_when_not_linked + contact = unlinked_contact + assert contact.deletable? + end + + def test_undeletable_when_linked + assert @contact.linked? + assert_not @contact.deletable? + end + private def unlinked_contact From 67985ff1e98f658b45912df36304d233f066feb5 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 21 Jun 2019 18:04:00 +0300 Subject: [PATCH 3/3] Fix contact deletion --- app/models/contact.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/contact.rb b/app/models/contact.rb index 5701cce946..06407ae699 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -12,6 +12,7 @@ class Contact < ActiveRecord::Base has_many :domains, through: :domain_contacts has_many :legal_documents, as: :documentable has_many :registrant_domains, class_name: 'Domain', foreign_key: 'registrant_id' + has_many :actions, dependent: :destroy has_paper_trail class_name: "ContactVersion", meta: { children: :children_log }