diff --git a/.gitignore b/.gitignore index f09a003dcc..3f23f1277b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ /config/application.yml /config/environments/development.rb /config/deploy.rb +/.idea # Do not commit one. Instead, download the latest from https://github.com/internetee/style-guide. .rubocop.yml diff --git a/app/controllers/api/v1/registrant/registry_locks_controller.rb b/app/controllers/api/v1/registrant/registry_locks_controller.rb index 1efffeb751..5c5b8c803f 100644 --- a/app/controllers/api/v1/registrant/registry_locks_controller.rb +++ b/app/controllers/api/v1/registrant/registry_locks_controller.rb @@ -8,9 +8,9 @@ class RegistryLocksController < ::Api::V1::Registrant::BaseController before_action :authorized_to_manage_locks? def create - extensionsProhibited = params[:extensionsProhibited] + extensions_prohibited = params[:extensionsProhibited] - if @domain.apply_registry_lock(extensionsProhibited: extensionsProhibited.to_s.downcase == "true") + if @domain.apply_registry_lock(extensions_prohibited: extensions_prohibited.to_s.downcase == 'true') render json: serialized_domain(@domain) else render json: { errors: [{ base: ['Domain cannot be locked'] }] }, diff --git a/app/models/concerns/domain/registry_lockable.rb b/app/models/concerns/domain/registry_lockable.rb index 98f1c89176..24c53b7be9 100644 --- a/app/models/concerns/domain/registry_lockable.rb +++ b/app/models/concerns/domain/registry_lockable.rb @@ -12,22 +12,25 @@ module Domain::RegistryLockable end EXTENSIONS_STATUS = [DomainStatus::SERVER_EXTENSION_UPDATE_PROHIBITED].freeze - - def apply_registry_lock(extensionsProhibited:) + def apply_registry_lock(extensions_prohibited:) return unless registry_lockable? return if locked_by_registrant? transaction do - self.statuses |= LOCK_STATUSES - self.statuses |= EXTENSIONS_STATUS if Feature.obj_and_extensions_statuses_enabled? and extensionsProhibited - self.locked_by_registrant_at = Time.zone.now - alert_registrar_lock_changes!(lock: true) - - save! + apply_statuses_locked_statuses(extensions_prohibited: extensions_prohibited) end end + def apply_statuses_locked_statuses(extensions_prohibited:) + self.statuses |= LOCK_STATUSES + self.statuses |= EXTENSIONS_STATUS if Feature.obj_and_extensions_statuses_enabled? && extensions_prohibited + self.locked_by_registrant_at = Time.zone.now + alert_registrar_lock_changes!(lock: true) + + save! + end + def registry_lockable? (statuses & [DomainStatus::PENDING_DELETE_CONFIRMATION, DomainStatus::PENDING_CREATE, DomainStatus::PENDING_UPDATE, @@ -45,18 +48,21 @@ def remove_registry_lock return unless locked_by_registrant? transaction do - LOCK_STATUSES.each do |domain_status| - statuses.delete([domain_status]) - end - - statuses.delete([EXTENSIONS_STATUS]) if statuses.include? EXTENSIONS_STATUS - - self.locked_by_registrant_at = nil - self.statuses = admin_store_statuses_history || [] - alert_registrar_lock_changes!(lock: false) + remove_statuses_from_locked_domain + end + end - save! + def remove_statuses_from_locked_domain + LOCK_STATUSES.each do |domain_status| + statuses.delete([domain_status]) end + + statuses.delete([EXTENSIONS_STATUS]) if statuses.include? EXTENSIONS_STATUS + self.locked_by_registrant_at = nil + self.statuses = admin_store_statuses_history || [] + alert_registrar_lock_changes!(lock: false) + + save! end def alert_registrar_lock_changes!(lock: true) diff --git a/app/models/registrant_user.rb b/app/models/registrant_user.rb index 57a2f58ab9..f7e85c5af5 100644 --- a/app/models/registrant_user.rb +++ b/app/models/registrant_user.rb @@ -23,7 +23,7 @@ def companies(company_register = CompanyRegister::Client.new) company_register.representation_rights(citizen_personal_code: ident, citizen_country_code: country.alpha3) end - + def contacts(representable: true) Contact.registrant_user_contacts(self, representable: representable) end diff --git a/test/integration/api/registrant/registrant_api_registry_locks_test.rb b/test/integration/api/registrant/registrant_api_registry_locks_test.rb index e3c25ee254..3499711a7c 100644 --- a/test/integration/api/registrant/registrant_api_registry_locks_test.rb +++ b/test/integration/api/registrant/registrant_api_registry_locks_test.rb @@ -47,7 +47,7 @@ def test_cannot_lock_a_domain_in_pending_state end def test_cannot_lock_an_already_locked_domain - @domain.apply_registry_lock(extensionsProhibited: false) + @domain.apply_registry_lock(extensions_prohibited: false) assert(@domain.locked_by_registrant?) post '/api/v1/registrant/domains/2df2c1a1-8f6a-490a-81be-8bdf29866880/registry_lock', @@ -59,7 +59,7 @@ def test_cannot_lock_an_already_locked_domain end def test_can_unlock_a_locked_domain - @domain.apply_registry_lock(extensionsProhibited: false) + @domain.apply_registry_lock(extensions_prohibited: false) delete '/api/v1/registrant/domains/2df2c1a1-8f6a-490a-81be-8bdf29866880/registry_lock', headers: @auth_headers diff --git a/test/jobs/domain_update_confirm_job_test.rb b/test/jobs/domain_update_confirm_job_test.rb index 54a144424c..158729ae3c 100644 --- a/test/jobs/domain_update_confirm_job_test.rb +++ b/test/jobs/domain_update_confirm_job_test.rb @@ -22,14 +22,14 @@ def teardown def test_registrant_locked_domain refute @domain.locked_by_registrant? - @domain.apply_registry_lock(extensionsProhibited: false) + @domain.apply_registry_lock(extensions_prohibited: false) assert @domain.locked_by_registrant? assert_equal(@domain.registrar.notifications.last.text, "Domain #{@domain.name} has been locked by registrant") end def test_registrant_unlocked_domain refute @domain.locked_by_registrant? - @domain.apply_registry_lock(extensionsProhibited: false) + @domain.apply_registry_lock(extensions_prohibited: false) assert @domain.locked_by_registrant? @domain.remove_registry_lock refute @domain.locked_by_registrant? diff --git a/test/lib/serializers/registrant_api/domain_test.rb b/test/lib/serializers/registrant_api/domain_test.rb index a207b649f6..535aefc3d4 100644 --- a/test/lib/serializers/registrant_api/domain_test.rb +++ b/test/lib/serializers/registrant_api/domain_test.rb @@ -16,7 +16,7 @@ def test_returns_domain_locked_by_registrant_time_or_nil assert_not(@json[:locked_by_registrant_at]) travel_to Time.zone.parse('2010-07-05 10:30') - @domain.apply_registry_lock(extensionsProhibited: false) + @domain.apply_registry_lock(extensions_prohibited: false) serializer_for_locked_domain = Serializers::RegistrantApi::Domain.new(@domain.reload) new_json = serializer_for_locked_domain.to_json diff --git a/test/models/domain/domain_version_test.rb b/test/models/domain/domain_version_test.rb index 109785fcba..4b937e274d 100644 --- a/test/models/domain/domain_version_test.rb +++ b/test/models/domain/domain_version_test.rb @@ -31,7 +31,7 @@ def test_assigns_updator_to_paper_trail_whodunnit PaperTrail.request.whodunnit = @user.id_role_username assert_difference '@domain.versions.count', 1 do - @domain.apply_registry_lock(extensionsProhibited: false) + @domain.apply_registry_lock(extensions_prohibited: false) end assert_equal(@domain.updator, @user) diff --git a/test/models/domain/registry_lockable_test.rb b/test/models/domain/registry_lockable_test.rb index 8925ad6004..136c05fbac 100644 --- a/test/models/domain/registry_lockable_test.rb +++ b/test/models/domain/registry_lockable_test.rb @@ -11,14 +11,14 @@ def test_user_can_set_lock_for_domain_if_it_has_any_prohibited_status refute(@domain.locked_by_registrant?) @domain.update(statuses: [DomainStatus::SERVER_TRANSFER_PROHIBITED]) - @domain.apply_registry_lock(extensionsProhibited: false) # Raise validation error + @domain.apply_registry_lock(extensions_prohibited: false) # Raise validation error check_statuses_lockable_domain assert(@domain.locked_by_registrant?) end def test_remove_lockalable_statuses_after_admin_intervention - @domain.apply_registry_lock(extensionsProhibited: false) + @domain.apply_registry_lock(extensions_prohibited: false) assert @domain.locked_by_registrant? assert_equal @domain.statuses.sort, Domain::RegistryLockable::LOCK_STATUSES.sort @@ -26,7 +26,7 @@ def test_remove_lockalable_statuses_after_admin_intervention @domain.update(statuses: deleted_status) assert_not @domain.locked_by_registrant? - @domain.apply_registry_lock(extensionsProhibited: false) + @domain.apply_registry_lock(extensions_prohibited: false) assert @domain.locked_by_registrant? @domain.remove_registry_lock @@ -41,7 +41,7 @@ def test_restore_domain_statuses_after_unlock @domain.save assert @domain.admin_store_statuses_history.include? DomainStatus::SERVER_UPDATE_PROHIBITED - @domain.apply_registry_lock(extensionsProhibited: false) + @domain.apply_registry_lock(extensions_prohibited: false) assert @domain.locked_by_registrant? assert_equal @domain.statuses.sort, Domain::RegistryLockable::LOCK_STATUSES.sort @@ -52,7 +52,7 @@ def test_restore_domain_statuses_after_unlock end def test_add_additinal_status_for_locked_domain - @domain.apply_registry_lock(extensionsProhibited: false) + @domain.apply_registry_lock(extensions_prohibited: false) assert @domain.locked_by_registrant? assert_equal @domain.statuses.sort, Domain::RegistryLockable::LOCK_STATUSES.sort @@ -69,7 +69,7 @@ def test_add_additinal_status_for_locked_domain def test_lockable_domain_if_remove_some_prohibited_status refute(@domain.locked_by_registrant?) - @domain.apply_registry_lock(extensionsProhibited: false) + @domain.apply_registry_lock(extensions_prohibited: false) check_statuses_lockable_domain assert(@domain.locked_by_registrant?) @@ -85,7 +85,7 @@ def test_lockable_domain_if_remove_some_prohibited_status def test_registry_lock_on_lockable_domain refute(@domain.locked_by_registrant?) - @domain.apply_registry_lock(extensionsProhibited: false) + @domain.apply_registry_lock(extensions_prohibited: false) assert_equal( [DomainStatus::SERVER_UPDATE_PROHIBITED, @@ -99,21 +99,21 @@ def test_registry_lock_on_lockable_domain end def test_registry_lock_cannot_be_applied_twice - @domain.apply_registry_lock(extensionsProhibited: false) - refute(@domain.apply_registry_lock(extensionsProhibited: false)) + @domain.apply_registry_lock(extensions_prohibited: false) + refute(@domain.apply_registry_lock(extensions_prohibited: false)) assert(@domain.locked_by_registrant?) assert(@domain.locked_by_registrant_at) end def test_registry_lock_cannot_be_applied_on_pending_statuses @domain.statuses << DomainStatus::PENDING_RENEW - refute(@domain.apply_registry_lock(extensionsProhibited: false)) + refute(@domain.apply_registry_lock(extensions_prohibited: false)) refute(@domain.locked_by_registrant?) refute(@domain.locked_by_registrant_at) end def test_remove_registry_lock_on_locked_domain - @domain.apply_registry_lock(extensionsProhibited: false) + @domain.apply_registry_lock(extensions_prohibited: false) assert_equal( [DomainStatus::SERVER_UPDATE_PROHIBITED, diff --git a/test/system/admin_area/domains/registry_lock_test.rb b/test/system/admin_area/domains/registry_lock_test.rb index 3d002a077f..659e1fc7dc 100644 --- a/test/system/admin_area/domains/registry_lock_test.rb +++ b/test/system/admin_area/domains/registry_lock_test.rb @@ -17,7 +17,7 @@ def test_does_not_have_link_when_domain_is_not_locked end def test_can_remove_registry_lock_from_a_domain - @domain.apply_registry_lock(extensionsProhibited: false) + @domain.apply_registry_lock(extensions_prohibited: false) visit edit_admin_domain_path(@domain) click_link_or_button('Actions') @@ -34,7 +34,7 @@ def test_can_remove_registry_lock_from_a_domain end def test_cannot_remove_registry_lock_from_not_locked_domain - @domain.apply_registry_lock(extensionsProhibited: false) + @domain.apply_registry_lock(extensions_prohibited: false) visit edit_admin_domain_path(@domain) @domain.remove_registry_lock diff --git a/test/system/admin_area/domains_test.rb b/test/system/admin_area/domains_test.rb index 52babd99c1..0fabb0e773 100644 --- a/test/system/admin_area/domains_test.rb +++ b/test/system/admin_area/domains_test.rb @@ -20,7 +20,7 @@ def test_admin_registry_lock_date refute_text 'Registry lock time 2010-07-05 00:30' lockable_domain = domains(:airport) - lockable_domain.apply_registry_lock(extensionsProhibited: false) + lockable_domain.apply_registry_lock(extensions_prohibited: false) visit admin_domain_path(lockable_domain) assert_text 'Registry lock time 2010-07-05 00:30'