From 5de0645d41fbd1d6ee19705d61d2bda72e00546d Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Fri, 29 Jan 2021 18:00:51 +0200 Subject: [PATCH 1/4] added tests for domain locked notifications --- test/jobs/domain_update_confirm_job_test.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/jobs/domain_update_confirm_job_test.rb b/test/jobs/domain_update_confirm_job_test.rb index ded0d3d8a..51c42aa4f 100644 --- a/test/jobs/domain_update_confirm_job_test.rb +++ b/test/jobs/domain_update_confirm_job_test.rb @@ -1,5 +1,4 @@ require "test_helper" - class DomainUpdateConfirmJobTest < ActiveSupport::TestCase def setup super @@ -19,6 +18,22 @@ class DomainUpdateConfirmJobTest < ActiveSupport::TestCase super end + def test_registrant_locked_domain + refute @domain.locked_by_registrant? + @domain.apply_registry_lock + assert @domain.locked_by_registrant? + assert_equal(@domain.registrar.notifications.last.text, 'Domain has been locked by registrant') + end + + def test_registrant_unlocked_domain + refute @domain.locked_by_registrant? + @domain.apply_registry_lock + assert @domain.locked_by_registrant? + @domain.remove_registry_lock + refute @domain.locked_by_registrant? + assert_equal(@domain.registrar.notifications.last.text, 'Domain has been unlocked by registrant') + end + def test_rejected_registrant_verification_notifies_registrar DomainUpdateConfirmJob.perform_now(@domain.id, RegistrantVerification::REJECTED) From aefb7e42aea9611db582d9f892cb574f46c1d31a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Tue, 9 Feb 2021 16:27:15 +0200 Subject: [PATCH 2/4] Registry lock: Notify Registrar by EPP notification --- app/models/concerns/domain/registry_lockable.rb | 12 ++++++++++++ config/locales/notifications.en.yml | 2 ++ test/jobs/domain_update_confirm_job_test.rb | 6 +++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/models/concerns/domain/registry_lockable.rb b/app/models/concerns/domain/registry_lockable.rb index 4a759296d..4190722f3 100644 --- a/app/models/concerns/domain/registry_lockable.rb +++ b/app/models/concerns/domain/registry_lockable.rb @@ -12,6 +12,7 @@ module Concerns statuses << DomainStatus::SERVER_DELETE_PROHIBITED statuses << DomainStatus::SERVER_TRANSFER_PROHIBITED self.locked_by_registrant_at = Time.zone.now + alert_registrar_lock_changes! save! end @@ -42,10 +43,21 @@ module Concerns statuses.delete(DomainStatus::SERVER_DELETE_PROHIBITED) statuses.delete(DomainStatus::SERVER_TRANSFER_PROHIBITED) self.locked_by_registrant_at = nil + alert_registrar_lock_changes! save! end end + + def alert_registrar_lock_changes! + translation = locked_by_registrant? ? 'locked' : 'unlocked' + registrar.notifications.create!( + text: I18n.t("notifications.texts.registrar_#{translation}", + domain_name: domain.name), + attached_obj_id: name, + attached_obj_type: self.class.name + ) + end end end end diff --git a/config/locales/notifications.en.yml b/config/locales/notifications.en.yml index 1dff4a97c..d67fb5a5b 100644 --- a/config/locales/notifications.en.yml +++ b/config/locales/notifications.en.yml @@ -6,3 +6,5 @@ en: It was associated with registrant %{old_registrant_code} and contacts %{old_contacts_codes}. contact_update: Contact %{contact} has been updated by registrant + registrar_locked: Domain %{domain_name} has been locked by registrant + registrar_unlocked: Domain %{domain_name} has been unlocked by registrant diff --git a/test/jobs/domain_update_confirm_job_test.rb b/test/jobs/domain_update_confirm_job_test.rb index 51c42aa4f..dc6e14bf9 100644 --- a/test/jobs/domain_update_confirm_job_test.rb +++ b/test/jobs/domain_update_confirm_job_test.rb @@ -18,11 +18,11 @@ class DomainUpdateConfirmJobTest < ActiveSupport::TestCase super end - def test_registrant_locked_domain + def test_registrant_locked_domain refute @domain.locked_by_registrant? @domain.apply_registry_lock assert @domain.locked_by_registrant? - assert_equal(@domain.registrar.notifications.last.text, 'Domain has been locked by registrant') + assert_equal(@domain.registrar.notifications.last.text, "Domain #{@domain.name} has been unlocked by registrant") end def test_registrant_unlocked_domain @@ -31,7 +31,7 @@ class DomainUpdateConfirmJobTest < ActiveSupport::TestCase assert @domain.locked_by_registrant? @domain.remove_registry_lock refute @domain.locked_by_registrant? - assert_equal(@domain.registrar.notifications.last.text, 'Domain has been unlocked by registrant') + assert_equal(@domain.registrar.notifications.last.text, "Domain #{@domain.name} has been unlocked by registrant") end def test_rejected_registrant_verification_notifies_registrar From 66dfa730ec1c8f3a00d94c51b37d3088f71a5ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Tue, 9 Feb 2021 16:27:15 +0200 Subject: [PATCH 3/4] Registry lock: Notify Registrar by EPP notification --- app/models/concerns/domain/registry_lockable.rb | 12 ++++++++++++ config/locales/notifications.en.yml | 2 ++ test/jobs/domain_update_confirm_job_test.rb | 6 +++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/models/concerns/domain/registry_lockable.rb b/app/models/concerns/domain/registry_lockable.rb index 4a759296d..ccb0f305e 100644 --- a/app/models/concerns/domain/registry_lockable.rb +++ b/app/models/concerns/domain/registry_lockable.rb @@ -12,6 +12,7 @@ module Concerns statuses << DomainStatus::SERVER_DELETE_PROHIBITED statuses << DomainStatus::SERVER_TRANSFER_PROHIBITED self.locked_by_registrant_at = Time.zone.now + alert_registrar_lock_changes! save! end @@ -42,10 +43,21 @@ module Concerns statuses.delete(DomainStatus::SERVER_DELETE_PROHIBITED) statuses.delete(DomainStatus::SERVER_TRANSFER_PROHIBITED) self.locked_by_registrant_at = nil + alert_registrar_lock_changes! save! end end + + def alert_registrar_lock_changes! + translation = locked_by_registrant? ? 'locked' : 'unlocked' + registrar.notifications.create!( + text: I18n.t("notifications.texts.registrar_#{translation}", + domain_name: name), + attached_obj_id: name, + attached_obj_type: self.class.name + ) + end end end end diff --git a/config/locales/notifications.en.yml b/config/locales/notifications.en.yml index 1dff4a97c..d67fb5a5b 100644 --- a/config/locales/notifications.en.yml +++ b/config/locales/notifications.en.yml @@ -6,3 +6,5 @@ en: It was associated with registrant %{old_registrant_code} and contacts %{old_contacts_codes}. contact_update: Contact %{contact} has been updated by registrant + registrar_locked: Domain %{domain_name} has been locked by registrant + registrar_unlocked: Domain %{domain_name} has been unlocked by registrant diff --git a/test/jobs/domain_update_confirm_job_test.rb b/test/jobs/domain_update_confirm_job_test.rb index 51c42aa4f..dc6e14bf9 100644 --- a/test/jobs/domain_update_confirm_job_test.rb +++ b/test/jobs/domain_update_confirm_job_test.rb @@ -18,11 +18,11 @@ class DomainUpdateConfirmJobTest < ActiveSupport::TestCase super end - def test_registrant_locked_domain + def test_registrant_locked_domain refute @domain.locked_by_registrant? @domain.apply_registry_lock assert @domain.locked_by_registrant? - assert_equal(@domain.registrar.notifications.last.text, 'Domain has been locked by registrant') + assert_equal(@domain.registrar.notifications.last.text, "Domain #{@domain.name} has been unlocked by registrant") end def test_registrant_unlocked_domain @@ -31,7 +31,7 @@ class DomainUpdateConfirmJobTest < ActiveSupport::TestCase assert @domain.locked_by_registrant? @domain.remove_registry_lock refute @domain.locked_by_registrant? - assert_equal(@domain.registrar.notifications.last.text, 'Domain has been unlocked by registrant') + assert_equal(@domain.registrar.notifications.last.text, "Domain #{@domain.name} has been unlocked by registrant") end def test_rejected_registrant_verification_notifies_registrar From 7638bff5466fd74f5fc80f48493c82fc96b67230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Wed, 10 Feb 2021 16:36:57 +0200 Subject: [PATCH 4/4] Add registry lock operation to epp notification --- app/models/notification.rb | 4 ++++ app/views/epp/poll/poll_req.xml.builder | 22 ++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index e83b2c9da..07e824367 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -25,6 +25,10 @@ class Notification < ApplicationRecord '' end + def registry_lock? + text.include?('has been locked') || text.include?('has been unlocked') + end + private def set_defaults diff --git a/app/views/epp/poll/poll_req.xml.builder b/app/views/epp/poll/poll_req.xml.builder index 664327dae..a58b082c5 100644 --- a/app/views/epp/poll/poll_req.xml.builder +++ b/app/views/epp/poll/poll_req.xml.builder @@ -15,12 +15,22 @@ xml.epp_head do end if @object end - if @notification.action&.contact - render(partial: 'epp/poll/action', - locals: { - builder: xml, - action: @notification.action - }) + if @notification.action&.contact || @notification.registry_lock? + if @notification.registry_lock? + state = @notification.text.include?('unlocked') ? 'unlock' : 'lock' + xml.extension do + xml.tag!('changePoll:changeData', + 'xmlns:changePoll': 'https://epp.tld.ee/schema/changePoll-1.0.xsd') do + xml.tag!('changePoll:operation', state) + end + end + else + render(partial: 'epp/poll/action', + locals: { + builder: xml, + action: @notification.action, + }) + end end render('epp/shared/trID', builder: xml)