mirror of
https://github.com/internetee/registry.git
synced 2025-08-04 17:01:44 +02:00
Better contact validation
This commit is contained in:
parent
c78e40a65a
commit
5003a3ff20
5 changed files with 53 additions and 5 deletions
|
@ -7,7 +7,9 @@ module Epp::DomainsHelper
|
|||
render '/epp/domains/create'
|
||||
else
|
||||
handle_domain_name_errors
|
||||
handle_contact_errors
|
||||
render '/epp/error'
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -56,4 +58,10 @@ module Epp::DomainsHelper
|
|||
end
|
||||
end
|
||||
|
||||
def handle_contact_errors
|
||||
if @domain.errors.added?(:admin_contacts, :blank)
|
||||
epp_errors << {code: '2306', msg: @domain.errors[:admin_contacts].first}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -24,7 +24,7 @@ class Domain < ActiveRecord::Base
|
|||
validates :period, numericality: { only_integer: true, greater_than: 0, less_than: 100 }
|
||||
validates :owner_contact, presence: true
|
||||
# validates :tech_contacts_count
|
||||
# validates :admin_contacts_count
|
||||
#validate :admin_contacts_count, on: :update
|
||||
|
||||
def name=(value)
|
||||
value.strip!
|
||||
|
@ -46,7 +46,9 @@ class Domain < ActiveRecord::Base
|
|||
attach_contact(Contact::CONTACT_TYPE_ADMIN, owner_contact) if admin_contacts.empty?
|
||||
end
|
||||
|
||||
true
|
||||
validate_admin_contacts_count
|
||||
|
||||
errors.empty?
|
||||
end
|
||||
|
||||
def attach_contact(type, contact)
|
||||
|
@ -56,6 +58,10 @@ class Domain < ActiveRecord::Base
|
|||
)
|
||||
end
|
||||
|
||||
def validate_admin_contacts_count
|
||||
errors.add(:admin_contacts, :blank) if admin_contacts.empty?
|
||||
end
|
||||
|
||||
class << self
|
||||
def check_availability(domains)
|
||||
domains = [domains] if domains.is_a?(String)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue