Merge pull request #1621 from internetee/1620-per-registrar-legaldoc-optout

Add legaldoc_optout field to registrar
This commit is contained in:
Timo Võhmar 2020-07-01 12:57:15 +03:00 committed by GitHub
commit 01c4a975e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 225 additions and 12 deletions

View file

@ -74,6 +74,8 @@ module Admin
:vat_rate,
:accounting_customer_code,
:billing_email,
:legaldoc_optout,
:legaldoc_optout_comment,
:iban,
:language)
end

View file

@ -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'

View file

@ -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

View file

@ -0,0 +1,11 @@
module Concerns
module Registrar
module LegalDoc
extend ActiveSupport::Concern
def legaldoc_mandatory?
!legaldoc_optout
end
end
end
end

View file

@ -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

View file

@ -91,6 +91,24 @@
<%= f.check_box :test_registrar, class: 'form-control' %>
</div>
</div>
<div class="form-group">
<div class="col-md-4 control-label">
<%= f.label t('.legaldoc_optout') %>
</div>
<div class="col-md-7">
<%= f.check_box :legaldoc_optout, class: 'form-control' %>
</div>
</div>
<div class="form-group">
<div class="col-md-4 control-label">
<%= f.label t('.legaldoc_optout_comment') %>
</div>
<div class="col-md-7">
<%= f.text_area :legaldoc_optout_comment, class: 'form-control', rows: 3 %>
</div>
</div>
</div>
</div>
</div>

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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');

View file

@ -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
<?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
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
<?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
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

View file

@ -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
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<delete>
<domain:delete verified="yes" xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>shop.test</domain:name>
</domain:delete>
</delete>
</command>
</epp>
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
end

View file

@ -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
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<update>
<domain:update xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>#{@domain.name}</domain:name>
<domain:chg>
<domain:registrant verified="no">#{new_registrant.code}</domain:registrant>
</domain:chg>
</domain:update>
</update>
</command>
</epp>
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
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<update>
<domain:update xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>#{@domain.name}</domain:name>
<domain:chg>
<domain:registrant verified="no">#{new_registrant.code}</domain:registrant>
</domain:chg>
</domain:update>
</update>
</command>
</epp>
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