Add check if legal doc mandatory & tests

This commit is contained in:
Alex Sherman 2020-06-30 14:33:42 +05:00
parent 3f9727dc55
commit 206704fee7
6 changed files with 83 additions and 2 deletions

View file

@ -237,7 +237,7 @@ module Epp
mutually_exclusive 'keyData', 'dsData' mutually_exclusive 'keyData', 'dsData'
@prefix = nil @prefix = nil
requires 'extension > extdata > legalDocument' requires 'extension > extdata > legalDocument' if current_user.legaldoc_mandatory?
optional_attribute 'period', 'unit', values: %w(d m y) optional_attribute 'period', 'unit', values: %w(d m y)

View file

@ -26,6 +26,7 @@ class ApiUser < User
validates :username, uniqueness: true validates :username, uniqueness: true
delegate :code, :name, to: :registrar, prefix: true delegate :code, :name, to: :registrar, prefix: true
delegate :legaldoc_mandatory?, to: :registrar
alias_attribute :login, :username 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 class Registrar < ApplicationRecord
include Versions # version/registrar_version.rb include Versions # version/registrar_version.rb
include Concerns::Registrar::BookKeeping include Concerns::Registrar::BookKeeping
include Concerns::Registrar::LegalDoc
has_many :domains, dependent: :restrict_with_error has_many :domains, dependent: :restrict_with_error
has_many :contacts, dependent: :restrict_with_error has_many :contacts, dependent: :restrict_with_error

View file

@ -1,4 +1,5 @@
- path = (params[:domain_name]) ? update_registrar_domains_path : registrar_domains_path - 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 = form_tag(path, class: 'form-horizontal', multipart: true) do
.row .row
.col-md-8 .col-md-8
@ -14,7 +15,7 @@
.panel-body .panel-body
.form-group .form-group
.col-md-3.control-label .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 = label_tag 'domain[legal_document]', t(:legal_document), class: c
%p.help-block= t(:legal_document_max_size) %p.help-block= t(:legal_document_max_size)
.col-md-7 .col-md-7

View file

@ -1,6 +1,36 @@
require 'test_helper' require 'test_helper'
class EppDomainCreateBaseTest < EppTestCase 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 def test_registers_new_domain_with_required_attributes
now = Time.zone.parse('2010-07-05') now = Time.zone.parse('2010-07-05')
travel_to now travel_to now
@ -45,6 +75,43 @@ class EppDomainCreateBaseTest < EppTestCase
assert_equal now + default_registration_period, domain.expire_time assert_equal now + default_registration_period, domain.expire_time
end 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 def test_registers_reserved_domain_with_registration_code
reserved_domain = reserved_domains(:one) reserved_domain = reserved_domains(:one)
registration_code = reserved_domain.registration_code registration_code = reserved_domain.registration_code