mirror of
https://github.com/internetee/registry.git
synced 2025-07-13 22:45:06 +02:00
Add custom validation to nameservers uniqueness
This commit is contained in:
parent
44dce714b8
commit
f65cf32991
7 changed files with 45 additions and 17 deletions
|
@ -0,0 +1,3 @@
|
||||||
|
.error-tab > a {
|
||||||
|
color: #a94442 !important;
|
||||||
|
}
|
|
@ -38,6 +38,9 @@ class Domain < ActiveRecord::Base
|
||||||
validates :owner_contact, presence: true
|
validates :owner_contact, presence: true
|
||||||
|
|
||||||
validate :validate_period
|
validate :validate_period
|
||||||
|
validate :validate_nameservers_count
|
||||||
|
validate :validate_nameservers_uniqueness, if: :new_record?
|
||||||
|
# validates_associated :nameservers
|
||||||
|
|
||||||
attr_accessor :adding_admin_contact
|
attr_accessor :adding_admin_contact
|
||||||
validate :validate_admin_contacts_max_count, if: :adding_admin_contact
|
validate :validate_admin_contacts_max_count, if: :adding_admin_contact
|
||||||
|
@ -55,7 +58,7 @@ class Domain < ActiveRecord::Base
|
||||||
validate :validate_tech_contacts_max_count, if: :adding_tech_contact
|
validate :validate_tech_contacts_max_count, if: :adding_tech_contact
|
||||||
|
|
||||||
attr_accessor :deleting_tech_contact
|
attr_accessor :deleting_tech_contact
|
||||||
# validate :validate_tech_contacts_min_count, if: :deleting_tech_contact
|
validate :validate_tech_contacts_min_count, if: :deleting_tech_contact
|
||||||
|
|
||||||
def name=(value)
|
def name=(value)
|
||||||
value.strip!
|
value.strip!
|
||||||
|
@ -111,6 +114,18 @@ class Domain < ActiveRecord::Base
|
||||||
errors.add(:admin_contacts, :out_of_range) if admin_contacts_count.zero?
|
errors.add(:admin_contacts, :out_of_range) if admin_contacts_count.zero?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def validate_nameservers_uniqueness
|
||||||
|
validated = []
|
||||||
|
nameservers.each do |ns|
|
||||||
|
next if ns.hostname.blank?
|
||||||
|
existing = nameservers.select { |x| x.hostname == ns.hostname }
|
||||||
|
next unless existing.length > 1
|
||||||
|
validated << ns.hostname
|
||||||
|
errors.add(:'nameservers.hostname', 'duplicate')
|
||||||
|
ns.errors.add(:hostname, :taken)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def validate_period
|
def validate_period
|
||||||
return unless period.present?
|
return unless period.present?
|
||||||
if period_unit == 'd'
|
if period_unit == 'd'
|
||||||
|
@ -131,6 +146,10 @@ class Domain < ActiveRecord::Base
|
||||||
errors.empty?
|
errors.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def associations_valid?(name)
|
||||||
|
!errors.keys.any? { |x| x.match(/#{name.to_s}/) }
|
||||||
|
end
|
||||||
|
|
||||||
## SHARED
|
## SHARED
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
|
|
@ -1,23 +1,24 @@
|
||||||
= form_for([:admin, @domain]) do |f|
|
= form_for([:admin, @domain]) do |f|
|
||||||
- if @domain.errors.any?
|
.row
|
||||||
- @domain.errors.each do |attr, err|
|
.col-md-12
|
||||||
= err
|
= render 'admin/shared/errors', object: f.object
|
||||||
%br
|
- if f.object.errors.any?
|
||||||
- if @domain.errors.any?
|
%hr
|
||||||
%hr
|
|
||||||
|
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
/ Nav tabs
|
/ Nav tabs
|
||||||
%ul.nav.nav-tabs{:role => "tablist", id: 'tabs'}
|
%ul.nav.nav-tabs{:role => "tablist", id: 'tabs'}
|
||||||
%li.active
|
%li.active
|
||||||
%a{"data-toggle" => "tab", :href => "#general-tab", :role => "tab"} general-tab
|
%a{"data-toggle" => "tab", :href => "#general-tab", :role => "tab"}= t('shared.general')
|
||||||
%li
|
- li_class = @domain.associations_valid?(:nameservers) ? nil : 'error-tab'
|
||||||
%a{"data-toggle" => "tab", :href => "#nameservers-tab", :role => "tab"} nameservers-tab
|
%li{class: li_class}
|
||||||
%li
|
%a{"data-toggle" => "tab", :href => "#nameservers-tab", :role => "tab"}= t('shared.nameservers')
|
||||||
%a{"data-toggle" => "tab", :href => "#contacts-tab", :role => "tab"} contacts-tab
|
- li_class = @domain.associations_valid?(:domain_contacts) ? nil : 'error-tab'
|
||||||
%li
|
%li{class: li_class}
|
||||||
%a{"data-toggle" => "tab", :href => "#statuses-tab", :role => "tab"} statuses-tab
|
%a{"data-toggle" => "tab", :href => "#contacts-tab", :role => "tab"}= t('shared.contacts')
|
||||||
|
- li_class = @domain.associations_valid?(:domain_statuses) ? nil : 'error-tab'
|
||||||
|
%li{class: li_class}
|
||||||
|
%a{"data-toggle" => "tab", :href => "#statuses-tab", :role => "tab"}= t('shared.statuses')
|
||||||
/ Tab panes
|
/ Tab panes
|
||||||
.tab-content{style:'margin-top: 20px;'}
|
.tab-content{style:'margin-top: 20px;'}
|
||||||
#general-tab.tab-pane.active
|
#general-tab.tab-pane.active
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
.panel-body
|
.panel-body
|
||||||
.errors
|
.errors
|
||||||
= render 'admin/shared/errors', object: contact_fields.object
|
= render 'admin/shared/errors', object: contact_fields.object
|
||||||
|
- if contact_fields.object.errors.any?
|
||||||
|
%hr
|
||||||
.row
|
.row
|
||||||
.col-md-6
|
.col-md-6
|
||||||
.form-group
|
.form-group
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
.panel-body
|
.panel-body
|
||||||
.errors
|
.errors
|
||||||
= render 'admin/shared/errors', object: ns_fields.object
|
= render 'admin/shared/errors', object: ns_fields.object
|
||||||
|
- if ns_fields.object.errors.any?
|
||||||
|
%hr
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
.form-group
|
.form-group
|
||||||
|
@ -28,5 +30,3 @@
|
||||||
item.find('.errors').html('');
|
item.find('.errors').html('');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
.panel-body
|
.panel-body
|
||||||
.errors
|
.errors
|
||||||
= render 'admin/shared/errors', object: status_fields.object
|
= render 'admin/shared/errors', object: status_fields.object
|
||||||
|
- if status_fields.object.errors.any?
|
||||||
|
%hr
|
||||||
.row
|
.row
|
||||||
.col-md-6
|
.col-md-6
|
||||||
.form-group
|
.form-group
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
- if object.errors.any?
|
- if object.errors.any?
|
||||||
- object.errors.each do |attr, err|
|
- object.errors.each do |attr, err|
|
||||||
|
- next if attr.match(/\./)
|
||||||
- next if attr == :epp_errors
|
- next if attr == :epp_errors
|
||||||
= err
|
= err
|
||||||
%br
|
%br
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue