From a80e8136322147ae4a69d02cea4864c3016bc288 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 1 Jul 2020 16:59:17 +0500 Subject: [PATCH 1/2] Add a setting to see if legaldocs are mandatory --- app/models/concerns/registrar/legal_doc.rb | 6 ++++- app/models/setting.rb | 3 ++- app/views/admin/settings/index.haml | 1 + config/app.yml | 1 + test/models/registrar_test.rb | 29 +++++++++++++++++++++- 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/app/models/concerns/registrar/legal_doc.rb b/app/models/concerns/registrar/legal_doc.rb index e5d7b8941..103d778f2 100644 --- a/app/models/concerns/registrar/legal_doc.rb +++ b/app/models/concerns/registrar/legal_doc.rb @@ -4,7 +4,11 @@ module Concerns extend ActiveSupport::Concern def legaldoc_mandatory? - !legaldoc_optout + !legaldoc_not_mandatory? + end + + def legaldoc_not_mandatory? + legaldoc_optout || !Setting.legal_document_is_mandatory end end end diff --git a/app/models/setting.rb b/app/models/setting.rb index 9f00055a3..86d3dff35 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -3,7 +3,7 @@ class Setting < RailsSettings::Base source Rails.root.join('config', 'app.yml') # When config/app.yml has changed, you need change this prefix to v2, v3 ... to expires caches - # cache_prefix { "v1" } + cache_prefix { 'v2' } def self.reload_settings! STDOUT << "#{Time.zone.now.utc} - Clearing settings cache\n" @@ -68,6 +68,7 @@ class Setting < RailsSettings::Base request_confirmation_on_domain_deletion_enabled nameserver_required address_processing + legal_document_is_mandatory ] end end diff --git a/app/views/admin/settings/index.haml b/app/views/admin/settings/index.haml index 977f81202..9eb236b65 100644 --- a/app/views/admin/settings/index.haml +++ b/app/views/admin/settings/index.haml @@ -22,6 +22,7 @@ = render 'setting_row', var: :ns_min_count = render 'setting_row', var: :ns_max_count = render 'setting_row', var: :expire_pending_confirmation + = render 'setting_row', var: :legal_document_is_mandatory .panel.panel-default .panel-heading diff --git a/config/app.yml b/config/app.yml index f11189111..87f99f4ad 100644 --- a/config/app.yml +++ b/config/app.yml @@ -6,6 +6,7 @@ defaults: &defaults tech_contacts_max_count: 10 orphans_contacts_in_months: 6 expire_pending_confirmation: 48 + legal_document_is_mandatory: true ds_digest_type: 2 ds_data_allowed: false diff --git a/test/models/registrar_test.rb b/test/models/registrar_test.rb index eaed654ec..c5d832922 100644 --- a/test/models/registrar_test.rb +++ b/test/models/registrar_test.rb @@ -238,6 +238,33 @@ class RegistrarTest < ActiveSupport::TestCase assert_equal iban, registrar.e_invoice_iban end + def test_legal_doc_is_mandatory + old_value = Setting.legal_document_is_mandatory + Setting.legal_document_is_mandatory = true + assert @registrar.legaldoc_mandatory? + + Setting.legal_document_is_mandatory = old_value + end + + def test_legal_doc_is_not_mandatory_if_opted_out + old_value = Setting.legal_document_is_mandatory + Setting.legal_document_is_mandatory = true + @registrar.legaldoc_optout = true + @registrar.save(validate: false) + @registrar.reload + assert_not @registrar.legaldoc_mandatory? + + Setting.legal_document_is_mandatory = old_value + end + + def test_legal_doc_is_not_mandatory_globally + old_value = Setting.legal_document_is_mandatory + Setting.legal_document_is_mandatory = false + assert_not @registrar.legaldoc_mandatory? + + Setting.legal_document_is_mandatory = old_value + end + private def valid_registrar @@ -257,4 +284,4 @@ class RegistrarTest < ActiveSupport::TestCase Registry.current.vat_country = Country.new(:us) registrar end -end \ No newline at end of file +end From 4a2176d5d7f66a67c36d0b391bf93f4cce40f431 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Thu, 2 Jul 2020 14:27:06 +0500 Subject: [PATCH 2/2] Flush settings cache on legal doc mandatority check --- .travis.yml | 1 + app/models/concerns/registrar/legal_doc.rb | 3 +- ...34_add_legal_document_mandatory_setting.rb | 9 ++++ db/data_schema.rb | 2 +- .../epp/domain/create/base_test.rb | 47 +++++++++++++++++++ .../epp/domain/update/base_test.rb | 3 ++ 6 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 db/data/20200702104334_add_legal_document_mandatory_setting.rb diff --git a/.travis.yml b/.travis.yml index 29fe14dab..01373f29d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,7 @@ before_script: - "echo \"ca_key_password: 'password'\" >> config/application.yml" - "cp config/database_travis.yml config/database.yml" - "bundle exec rake db:setup:all" + - "bundle exec rake data:migrate" - "curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter" - "chmod +x ./cc-test-reporter" - "./cc-test-reporter before-build" diff --git a/app/models/concerns/registrar/legal_doc.rb b/app/models/concerns/registrar/legal_doc.rb index 103d778f2..e2ed9f83e 100644 --- a/app/models/concerns/registrar/legal_doc.rb +++ b/app/models/concerns/registrar/legal_doc.rb @@ -8,7 +8,8 @@ module Concerns end def legaldoc_not_mandatory? - legaldoc_optout || !Setting.legal_document_is_mandatory + setting = Setting.find_by(var: 'legal_document_is_mandatory')&.value + legaldoc_optout || !setting end end end diff --git a/db/data/20200702104334_add_legal_document_mandatory_setting.rb b/db/data/20200702104334_add_legal_document_mandatory_setting.rb new file mode 100644 index 000000000..2e0a298f7 --- /dev/null +++ b/db/data/20200702104334_add_legal_document_mandatory_setting.rb @@ -0,0 +1,9 @@ +class AddLegalDocumentMandatorySetting < ActiveRecord::Migration[6.0] + def up + Setting.legal_document_is_mandatory = true + end + + def down + Setting.find_by(var: 'legal_document_is_mandatory').delete + end +end diff --git a/db/data_schema.rb b/db/data_schema.rb index f4a3f5d8a..7b35d4e7b 100644 --- a/db/data_schema.rb +++ b/db/data_schema.rb @@ -1,2 +1,2 @@ # encoding: UTF-8 -DataMigrate::Data.define(version: 20150707103801) +DataMigrate::Data.define(version: 20200702104334) diff --git a/test/integration/epp/domain/create/base_test.rb b/test/integration/epp/domain/create/base_test.rb index c45693981..b75ef8909 100644 --- a/test/integration/epp/domain/create/base_test.rb +++ b/test/integration/epp/domain/create/base_test.rb @@ -3,6 +3,8 @@ require 'test_helper' class EppDomainCreateBaseTest < EppTestCase def test_not_registers_domain_without_legaldoc + old_value = Setting.legal_document_is_mandatory + Setting.legal_document_is_mandatory = true now = Time.zone.parse('2010-07-05') travel_to now name = "new.#{dns_zones(:one).origin}" @@ -29,6 +31,7 @@ class EppDomainCreateBaseTest < EppTestCase end assert_epp_response :required_parameter_missing + Setting.legal_document_is_mandatory = old_value end def test_registers_new_domain_with_required_attributes @@ -112,6 +115,50 @@ class EppDomainCreateBaseTest < EppTestCase assert_equal registrant, domain.registrant end + def test_does_not_registers_domain_without_legaldoc_if_mandatory + now = Time.zone.parse('2010-07-05') + travel_to now + name = "new.#{dns_zones(:one).origin}" + contact = contacts(:john) + registrant = contact.becomes(Registrant) + old_value = Setting.legal_document_is_mandatory + Setting.legal_document_is_mandatory = true + registrar = registrant.registrar + + assert registrar.legaldoc_mandatory? + + request_xml = <<-XML + + + + + + #{name} + #{registrant.code} + + + + + XML + + + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + assert_epp_response :required_parameter_missing + Setting.legal_document_is_mandatory = false + + assert_not registrar.legaldoc_mandatory? + assert_not Setting.legal_document_is_mandatory + + assert_difference 'Domain.count' do + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + end + + Setting.legal_document_is_mandatory = old_value + end + def test_registers_reserved_domain_with_registration_code reserved_domain = reserved_domains(:one) registration_code = reserved_domain.registration_code diff --git a/test/integration/epp/domain/update/base_test.rb b/test/integration/epp/domain/update/base_test.rb index 593d7951c..de1ba84d8 100644 --- a/test/integration/epp/domain/update/base_test.rb +++ b/test/integration/epp/domain/update/base_test.rb @@ -198,6 +198,8 @@ class EppDomainUpdateBaseTest < EppTestCase def test_dows_not_update_registrant_when_legaldoc_is_mandatory Setting.request_confrimation_on_registrant_change_enabled = true + old_value = Setting.legal_document_is_mandatory + Setting.legal_document_is_mandatory = true new_registrant = contacts(:william) assert_not_equal new_registrant, @domain.registrant @@ -220,6 +222,7 @@ class EppDomainUpdateBaseTest < EppTestCase post epp_update_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } assert_epp_response :required_parameter_missing + Setting.legal_document_is_mandatory = old_value end def test_skips_verification_when_provided_registrant_is_the_same_as_current_one