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
|
||||
|
||||
validate :validate_period
|
||||
validate :validate_nameservers_count
|
||||
validate :validate_nameservers_uniqueness, if: :new_record?
|
||||
# validates_associated :nameservers
|
||||
|
||||
attr_accessor :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
|
||||
|
||||
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)
|
||||
value.strip!
|
||||
|
@ -111,6 +114,18 @@ class Domain < ActiveRecord::Base
|
|||
errors.add(:admin_contacts, :out_of_range) if admin_contacts_count.zero?
|
||||
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
|
||||
return unless period.present?
|
||||
if period_unit == 'd'
|
||||
|
@ -131,6 +146,10 @@ class Domain < ActiveRecord::Base
|
|||
errors.empty?
|
||||
end
|
||||
|
||||
def associations_valid?(name)
|
||||
!errors.keys.any? { |x| x.match(/#{name.to_s}/) }
|
||||
end
|
||||
|
||||
## SHARED
|
||||
|
||||
def to_s
|
||||
|
|
|
@ -1,23 +1,24 @@
|
|||
= form_for([:admin, @domain]) do |f|
|
||||
- if @domain.errors.any?
|
||||
- @domain.errors.each do |attr, err|
|
||||
= err
|
||||
%br
|
||||
- if @domain.errors.any?
|
||||
%hr
|
||||
|
||||
.row
|
||||
.col-md-12
|
||||
= render 'admin/shared/errors', object: f.object
|
||||
- if f.object.errors.any?
|
||||
%hr
|
||||
.row
|
||||
.col-md-12
|
||||
/ Nav tabs
|
||||
%ul.nav.nav-tabs{:role => "tablist", id: 'tabs'}
|
||||
%li.active
|
||||
%a{"data-toggle" => "tab", :href => "#general-tab", :role => "tab"} general-tab
|
||||
%li
|
||||
%a{"data-toggle" => "tab", :href => "#nameservers-tab", :role => "tab"} nameservers-tab
|
||||
%li
|
||||
%a{"data-toggle" => "tab", :href => "#contacts-tab", :role => "tab"} contacts-tab
|
||||
%li
|
||||
%a{"data-toggle" => "tab", :href => "#statuses-tab", :role => "tab"} statuses-tab
|
||||
%a{"data-toggle" => "tab", :href => "#general-tab", :role => "tab"}= t('shared.general')
|
||||
- li_class = @domain.associations_valid?(:nameservers) ? nil : 'error-tab'
|
||||
%li{class: li_class}
|
||||
%a{"data-toggle" => "tab", :href => "#nameservers-tab", :role => "tab"}= t('shared.nameservers')
|
||||
- li_class = @domain.associations_valid?(:domain_contacts) ? nil : 'error-tab'
|
||||
%li{class: li_class}
|
||||
%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-content{style:'margin-top: 20px;'}
|
||||
#general-tab.tab-pane.active
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
.panel-body
|
||||
.errors
|
||||
= render 'admin/shared/errors', object: contact_fields.object
|
||||
- if contact_fields.object.errors.any?
|
||||
%hr
|
||||
.row
|
||||
.col-md-6
|
||||
.form-group
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
.panel-body
|
||||
.errors
|
||||
= render 'admin/shared/errors', object: ns_fields.object
|
||||
- if ns_fields.object.errors.any?
|
||||
%hr
|
||||
.row
|
||||
.col-md-12
|
||||
.form-group
|
||||
|
@ -28,5 +30,3 @@
|
|||
item.find('.errors').html('');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
.panel-body
|
||||
.errors
|
||||
= render 'admin/shared/errors', object: status_fields.object
|
||||
- if status_fields.object.errors.any?
|
||||
%hr
|
||||
.row
|
||||
.col-md-6
|
||||
.form-group
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
- if object.errors.any?
|
||||
- object.errors.each do |attr, err|
|
||||
- next if attr.match(/\./)
|
||||
- next if attr == :epp_errors
|
||||
= err
|
||||
%br
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue