Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a setting to see if legaldocs are mandatory #1626

Merged
merged 2 commits into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 6 additions & 1 deletion app/models/concerns/registrar/legal_doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ module LegalDoc
extend ActiveSupport::Concern

def legaldoc_mandatory?
!legaldoc_optout
!legaldoc_not_mandatory?
end

def legaldoc_not_mandatory?
setting = Setting.find_by(var: 'legal_document_is_mandatory')&.value
legaldoc_optout || !setting
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion app/models/setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -68,6 +68,7 @@ def self.boolean_settings
request_confirmation_on_domain_deletion_enabled
nameserver_required
address_processing
legal_document_is_mandatory
]
end
end
1 change: 1 addition & 0 deletions app/views/admin/settings/index.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion db/data_schema.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# encoding: UTF-8
DataMigrate::Data.define(version: 20150707103801)
DataMigrate::Data.define(version: 20200702104334)
47 changes: 47 additions & 0 deletions test/integration/epp/domain/create/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
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}"
Expand All @@ -29,6 +31,7 @@ def test_not_registers_domain_without_legaldoc
end

assert_epp_response :required_parameter_missing
Setting.legal_document_is_mandatory = old_value
end

def test_registers_new_domain_with_required_attributes
Expand Down Expand Up @@ -112,6 +115,50 @@ def test_registers_domain_without_legaldoc_if_optout
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
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<create>
<domain:create xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>#{name}</domain:name>
<domain:registrant>#{registrant.code}</domain:registrant>
</domain:create>
</create>
</command>
</epp>
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
Expand Down
3 changes: 3 additions & 0 deletions test/integration/epp/domain/update/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ def test_updates_registrant_when_legaldoc_is_not_mandatory

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

Expand All @@ -220,6 +222,7 @@ def test_dows_not_update_registrant_when_legaldoc_is_mandatory
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
Expand Down
29 changes: 28 additions & 1 deletion test/models/registrar_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,33 @@ def test_returns_iban_for_e_invoice_delivery_channel
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
Expand All @@ -257,4 +284,4 @@ def registrar_with_foreign_vat_liability
Registry.current.vat_country = Country.new(:us)
registrar
end
end
end