Skip to content

Commit

Permalink
Add a setting to see if legaldocs are mandatory
Browse files Browse the repository at this point in the history
  • Loading branch information
yulgolem committed Jul 1, 2020
1 parent 48ac443 commit 0ef0a3a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
6 changes: 5 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,11 @@ module LegalDoc
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
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
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

0 comments on commit 0ef0a3a

Please sign in to comment.