Do not require name servers in registrar area

#267
This commit is contained in:
Artur Beljajev 2016-12-29 16:27:07 +02:00
parent ffd29f6a67
commit b9df5aa92d
11 changed files with 411 additions and 281 deletions

View file

@ -0,0 +1,20 @@
module Concerns::Domain::Activatable
extend ActiveSupport::Concern
def active?
!inactive?
end
def inactive?
statuses.include?(DomainStatus::INACTIVE)
end
def activate
statuses.delete(DomainStatus::INACTIVE)
end
def deactivate
return if inactive?
statuses << DomainStatus::INACTIVE
end
end

View file

@ -40,13 +40,22 @@ module Depp
keys = Domain.create_dnskeys_hash(domain_params)
dns_hash[:_anonymus] = keys if keys.any?
xml = epp_xml.create({
name: { value: domain_params[:name] },
period: { value: domain_params[:period].to_s[0], attrs: { unit: domain_params[:period].to_s[1] } },
ns: Domain.create_nameservers_hash(domain_params),
registrant: { value: domain_params[:registrant] },
_anonymus: Domain.create_contacts_hash(domain_params)
}, dns_hash, Domain.construct_custom_params_hash(domain_params))
if domain_params[:nameservers_attributes].select { |key, value| value['hostname'].present? }.any?
xml = epp_xml.create({
name: { value: domain_params[:name] },
period: { value: domain_params[:period].to_s[0], attrs: { unit: domain_params[:period].to_s[1] } },
ns: Domain.create_nameservers_hash(domain_params),
registrant: { value: domain_params[:registrant] },
_anonymus: Domain.create_contacts_hash(domain_params)
}, dns_hash, Domain.construct_custom_params_hash(domain_params))
else
xml = epp_xml.create({
name: { value: domain_params[:name] },
period: { value: domain_params[:period].to_s[0], attrs: { unit: domain_params[:period].to_s[1] } },
registrant: { value: domain_params[:registrant] },
_anonymus: Domain.create_contacts_hash(domain_params)
}, dns_hash, Domain.construct_custom_params_hash(domain_params))
end
current_user.request(xml)
end

View file

@ -4,6 +4,7 @@ class Domain < ActiveRecord::Base
include Versions # version/domain_version.rb
include Statuses
include Concerns::Domain::Expirable
include Concerns::Domain::Activatable
has_paper_trail class_name: "DomainVersion", meta: { children: :children_log }
@ -694,8 +695,8 @@ class Domain < ActiveRecord::Base
statuses << DomainStatus::SERVER_HOLD if p_d && s_h
if !self.class.nameserver_required?
statuses << DomainStatus::INACTIVE if nameservers.empty?
statuses.delete(DomainStatus::INACTIVE) if nameservers.size >= Setting.ns_min_count
deactivate if nameservers.reject(&:marked_for_destruction?).empty?
activate if nameservers.reject(&:marked_for_destruction?).size >= Setting.ns_min_count
end
end
# rubocop: enable Metrics/CyclomaticComplexity

View file

@ -1,10 +1,10 @@
class DomainNameserverValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return true if !Domain.nameserver_required? && value.empty?
min, max = options[:min].call, options[:max].call
values = value.reject(&:marked_for_destruction?)
return true if !Domain.nameserver_required? && values.empty?
return if values.size.between?(min, max)
association = options[:association] || attribute
record.errors.add(association, :out_of_range, { min: min, max: max })

View file

@ -9,10 +9,11 @@
.panel-body
.form-group
.col-md-3.control-label
= label_tag "domain_nameservers_attributes_#{k}_hostname", t(:hostname), class: 'required'
= label_tag "domain_nameservers_attributes_#{k}_hostname", t(:hostname),
class: Domain.nameserver_required? ? 'required' : nil
.col-md-7
= text_field_tag "domain[nameservers_attributes][#{k}][hostname]", v['hostname'],
class: 'form-control', required: true
class: 'form-control', required: Domain.nameserver_required?
.form-group
.col-md-3.control-label
= label_tag "domain_nameservers_attributes_#{k}_ipv4", t(:ipv4)