From 206704fee7d048e266c7312df520870260ba991d Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Tue, 30 Jun 2020 14:33:42 +0500 Subject: [PATCH] Add check if legal doc mandatory & tests --- app/controllers/epp/domains_controller.rb | 2 +- app/models/api_user.rb | 1 + app/models/concerns/registrar/legal_doc.rb | 11 +++ app/models/registrar.rb | 1 + app/views/registrar/domains/_form.haml | 3 +- .../epp/domain/create/base_test.rb | 67 +++++++++++++++++++ 6 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 app/models/concerns/registrar/legal_doc.rb diff --git a/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb index fa0003756..dbf61ed9d 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) 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/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/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