diff --git a/app/controllers/admin/registrars_controller.rb b/app/controllers/admin/registrars_controller.rb
index b925a8156..27116d871 100644
--- a/app/controllers/admin/registrars_controller.rb
+++ b/app/controllers/admin/registrars_controller.rb
@@ -74,6 +74,8 @@ module Admin
:vat_rate,
:accounting_customer_code,
:billing_email,
+ :legaldoc_optout,
+ :legaldoc_optout_comment,
:iban,
:language)
end
diff --git a/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb
index fa0003756..4249c1db6 100644
--- a/app/controllers/epp/domains_controller.rb
+++ b/app/controllers/epp/domains_controller.rb
@@ -237,7 +237,7 @@ module Epp
mutually_exclusive 'keyData', 'dsData'
@prefix = nil
- requires 'extension > extdata > legalDocument'
+ requires 'extension > extdata > legalDocument' if current_user.legaldoc_mandatory?
optional_attribute 'period', 'unit', values: %w(d m y)
@@ -246,7 +246,7 @@ module Epp
def validate_update
if element_count('update > chg > registrant') > 0
- requires 'extension > extdata > legalDocument'
+ requires 'extension > extdata > legalDocument' if current_user.legaldoc_mandatory?
end
@prefix = 'update > update >'
@@ -256,7 +256,8 @@ module Epp
end
def validate_delete
- requires 'extension > extdata > legalDocument'
+ # binding.pry
+ requires 'extension > extdata > legalDocument' if current_user.legaldoc_mandatory?
@prefix = 'delete > delete >'
requires 'name'
diff --git a/app/models/api_user.rb b/app/models/api_user.rb
index b5efa7235..d7b264495 100644
--- a/app/models/api_user.rb
+++ b/app/models/api_user.rb
@@ -26,6 +26,7 @@ class ApiUser < User
validates :username, uniqueness: true
delegate :code, :name, to: :registrar, prefix: true
+ delegate :legaldoc_mandatory?, to: :registrar
alias_attribute :login, :username
diff --git a/app/models/concerns/registrar/legal_doc.rb b/app/models/concerns/registrar/legal_doc.rb
new file mode 100644
index 000000000..e5d7b8941
--- /dev/null
+++ b/app/models/concerns/registrar/legal_doc.rb
@@ -0,0 +1,11 @@
+module Concerns
+ module Registrar
+ module LegalDoc
+ extend ActiveSupport::Concern
+
+ def legaldoc_mandatory?
+ !legaldoc_optout
+ end
+ end
+ end
+end
diff --git a/app/models/registrar.rb b/app/models/registrar.rb
index c3522859e..dbdd7e8d3 100644
--- a/app/models/registrar.rb
+++ b/app/models/registrar.rb
@@ -1,6 +1,7 @@
class Registrar < ApplicationRecord
include Versions # version/registrar_version.rb
include Concerns::Registrar::BookKeeping
+ include Concerns::Registrar::LegalDoc
has_many :domains, dependent: :restrict_with_error
has_many :contacts, dependent: :restrict_with_error
diff --git a/app/views/admin/registrars/_form.html.erb b/app/views/admin/registrars/_form.html.erb
index 5545adef1..19866a31f 100644
--- a/app/views/admin/registrars/_form.html.erb
+++ b/app/views/admin/registrars/_form.html.erb
@@ -91,6 +91,24 @@
<%= f.check_box :test_registrar, class: 'form-control' %>
+
+
+
+
diff --git a/app/views/registrar/domains/_form.haml b/app/views/registrar/domains/_form.haml
index d6428233b..690d0ee06 100644
--- a/app/views/registrar/domains/_form.haml
+++ b/app/views/registrar/domains/_form.haml
@@ -1,4 +1,5 @@
- path = (params[:domain_name]) ? update_registrar_domains_path : registrar_domains_path
+- legaldoc_mandatory = params[:domain_name].blank? && current_registrar_user.legaldoc_mandatory?
= form_tag(path, class: 'form-horizontal', multipart: true) do
.row
.col-md-8
@@ -14,7 +15,7 @@
.panel-body
.form-group
.col-md-3.control-label
- - c, fr = 'required', true if params[:domain_name].blank?
+ - c, fr = 'required', true if legaldoc_mandatory
= label_tag 'domain[legal_document]', t(:legal_document), class: c
%p.help-block= t(:legal_document_max_size)
.col-md-7
diff --git a/app/views/registrar/domains/delete.haml b/app/views/registrar/domains/delete.haml
index ab1bdfa31..34b5af1f7 100644
--- a/app/views/registrar/domains/delete.haml
+++ b/app/views/registrar/domains/delete.haml
@@ -10,14 +10,14 @@
.col-md-4.control-label
= label_tag 'domain[verified]', t(:verified)
.col-md-6
- = check_box_tag 'domain[verified]', '1', params[:verified].eql?('1'), onclick: "return (confirm('#{t(:verified_confirm)}') ? true : false);"
+ = check_box_tag 'domain[verified]', '1', params[:verified].eql?('1'), onclick: ("return (confirm('#{t(:verified_confirm)}') ? true : false);" if current_registrar_user.legaldoc_mandatory?)
.form-group
.col-md-4.control-label
- = label_tag 'domain[legal_document]', t(:legal_document), class: 'required'
+ = label_tag 'domain[legal_document]', t(:legal_document), class: ('required' if current_registrar_user.legaldoc_mandatory?)
%p.help-block= t(:legal_document_max_size)
.col-md-6
- = file_field_tag 'domain[legal_document]', required: true
+ = file_field_tag 'domain[legal_document]', required: current_registrar_user.legaldoc_mandatory?
= hidden_field_tag 'domain[name]', params[:domain_name]
%hr
.row
diff --git a/config/locales/admin/registrars.en.yml b/config/locales/admin/registrars.en.yml
index 98aabbd95..59a999bd2 100644
--- a/config/locales/admin/registrars.en.yml
+++ b/config/locales/admin/registrars.en.yml
@@ -49,6 +49,8 @@ en:
misc: Miscellaneous
create_btn: Create registrar
update_btn: Update registrar
+ legaldoc_optout: Opt-out from legal document requirement
+ legaldoc_optout_comment: Commentary on opt-out
address:
header: Address
diff --git a/db/migrate/20200630081231_add_legal_doc_optout_to_registrar.rb b/db/migrate/20200630081231_add_legal_doc_optout_to_registrar.rb
new file mode 100644
index 000000000..e5bc5a7f1
--- /dev/null
+++ b/db/migrate/20200630081231_add_legal_doc_optout_to_registrar.rb
@@ -0,0 +1,6 @@
+class AddLegalDocOptoutToRegistrar < ActiveRecord::Migration[6.0]
+ def change
+ add_column :registrars, :legaldoc_optout, :boolean, null: false, default: false
+ add_column :registrars, :legaldoc_optout_comment, :text
+ end
+end
diff --git a/db/structure.sql b/db/structure.sql
index 7e3cad412..960481c44 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -560,7 +560,16 @@ ALTER SEQUENCE public.contacts_id_seq OWNED BY public.contacts.id;
--
--- Name: directos; Type: TABLE; Schema: public; Owner: -; Tablespace:
+-- Name: data_migrations; Type: TABLE; Schema: public; Owner: -
+--
+
+CREATE TABLE public.data_migrations (
+ version character varying NOT NULL
+);
+
+
+--
+-- Name: directos; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.directos (
@@ -2078,7 +2087,9 @@ CREATE TABLE public.registrars (
language character varying NOT NULL,
vat_rate numeric(4,3),
iban character varying,
- settings jsonb DEFAULT '{}'::jsonb NOT NULL
+ settings jsonb DEFAULT '{}'::jsonb NOT NULL,
+ legaldoc_optout boolean DEFAULT false NOT NULL,
+ legaldoc_optout_comment text
);
@@ -4523,6 +4534,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20200505103316'),
('20200505150413'),
('20200518104105'),
-('20200529115011');
+('20200529115011'),
+('20200630081231');
diff --git a/test/integration/epp/domain/create/base_test.rb b/test/integration/epp/domain/create/base_test.rb
index ffd56ffc5..c45693981 100644
--- a/test/integration/epp/domain/create/base_test.rb
+++ b/test/integration/epp/domain/create/base_test.rb
@@ -1,6 +1,36 @@
require 'test_helper'
class EppDomainCreateBaseTest < EppTestCase
+
+ def test_not_registers_domain_without_legaldoc
+ now = Time.zone.parse('2010-07-05')
+ travel_to now
+ name = "new.#{dns_zones(:one).origin}"
+ contact = contacts(:john)
+ registrant = contact.becomes(Registrant)
+
+ request_xml = <<-XML
+
+
+
+
+
+ #{name}
+ #{registrant.code}
+
+
+
+
+ XML
+
+ assert_no_difference 'Domain.count' do
+ post epp_create_path, params: { frame: request_xml },
+ headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
+ end
+
+ assert_epp_response :required_parameter_missing
+ end
+
def test_registers_new_domain_with_required_attributes
now = Time.zone.parse('2010-07-05')
travel_to now
@@ -45,6 +75,43 @@ class EppDomainCreateBaseTest < EppTestCase
assert_equal now + default_registration_period, domain.expire_time
end
+ def test_registers_domain_without_legaldoc_if_optout
+ now = Time.zone.parse('2010-07-05')
+ travel_to now
+ name = "new.#{dns_zones(:one).origin}"
+ contact = contacts(:john)
+ registrant = contact.becomes(Registrant)
+ registrar = registrant.registrar
+
+ registrar.legaldoc_optout = true
+ registrar.save(validate: false)
+
+ request_xml = <<-XML
+
+
+
+
+
+ #{name}
+ #{registrant.code}
+
+
+
+
+ XML
+
+ assert_difference 'Domain.count' do
+ post epp_create_path, params: { frame: request_xml },
+ headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
+ end
+
+ assert_epp_response :completed_successfully
+
+ domain = Domain.find_by(name: name)
+ assert_equal name, domain.name
+ assert_equal registrant, domain.registrant
+ 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/delete/base_test.rb b/test/integration/epp/domain/delete/base_test.rb
index 59dfa4edb..d71e9890f 100644
--- a/test/integration/epp/domain/delete/base_test.rb
+++ b/test/integration/epp/domain/delete/base_test.rb
@@ -160,7 +160,7 @@ class EppDomainDeleteBaseTest < EppTestCase
assert_epp_response :completed_successfully
end
- def test_legal_document_is_required
+ def test_legal_document_is_required_if_mandatory
assert_equal 'shop.test', @domain.name
request_xml = <<-XML
@@ -181,6 +181,35 @@ class EppDomainDeleteBaseTest < EppTestCase
assert_epp_response :required_parameter_missing
end
+ def test_legal_document_is_not_required_if_not_mandatory
+ assert_equal 'shop.test', @domain.name
+ Setting.request_confirmation_on_domain_deletion_enabled = true
+ @domain.registrar.legaldoc_optout = true
+ @domain.registrar.save(validate: false)
+ @domain.registrar.reload
+
+ request_xml = <<-XML
+
+
+
+
+
+ shop.test
+
+
+
+
+ XML
+
+ post epp_delete_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
+ @domain.reload
+
+ assert_not @domain.registrant_verification_asked?
+ assert_not @domain.pending_delete_confirmation?
+ assert_no_emails
+ assert_epp_response :completed_successfully
+ end
+
def test_domain_cannot_be_deleted_when_explicitly_prohibited_by_registrar
assert_equal 'shop.test', @domain.name
@domain.update!(statuses: [DomainStatus::CLIENT_DELETE_PROHIBITED])
@@ -207,4 +236,4 @@ class EppDomainDeleteBaseTest < EppTestCase
assert_epp_response :object_status_prohibits_operation
end
-end
\ No newline at end of file
+end
diff --git a/test/integration/epp/domain/update/base_test.rb b/test/integration/epp/domain/update/base_test.rb
index 0e435030a..593d7951c 100644
--- a/test/integration/epp/domain/update/base_test.rb
+++ b/test/integration/epp/domain/update/base_test.rb
@@ -160,6 +160,68 @@ class EppDomainUpdateBaseTest < EppTestCase
assert_verification_and_notification_emails
end
+ def test_updates_registrant_when_legaldoc_is_not_mandatory
+ Setting.request_confrimation_on_registrant_change_enabled = true
+ new_registrant = contacts(:william)
+ assert_not_equal new_registrant, @domain.registrant
+
+ @domain.registrar.legaldoc_optout = true
+ @domain.registrar.save(validate: false)
+ @domain.registrar.reload
+
+ request_xml = <<-XML
+
+
+
+
+
+ #{@domain.name}
+
+ #{new_registrant.code}
+
+
+
+
+
+ XML
+
+ post epp_update_path, params: { frame: request_xml },
+ headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
+ @domain.reload
+
+ assert_epp_response :completed_successfully_action_pending
+ assert_not_equal new_registrant, @domain.registrant
+ assert @domain.registrant_verification_asked?
+ assert_includes @domain.statuses, DomainStatus::PENDING_UPDATE
+ assert_verification_and_notification_emails
+ end
+
+ def test_dows_not_update_registrant_when_legaldoc_is_mandatory
+ Setting.request_confrimation_on_registrant_change_enabled = true
+ new_registrant = contacts(:william)
+ assert_not_equal new_registrant, @domain.registrant
+
+ request_xml = <<-XML
+
+
+
+
+
+ #{@domain.name}
+
+ #{new_registrant.code}
+
+
+
+
+
+ XML
+
+ post epp_update_path, params: { frame: request_xml },
+ headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
+ assert_epp_response :required_parameter_missing
+ end
+
def test_skips_verification_when_provided_registrant_is_the_same_as_current_one
Setting.request_confrimation_on_registrant_change_enabled = true