Let domain to to draft status

This commit is contained in:
Martin Lensment 2014-09-09 17:26:08 +03:00
parent e9e1e057f5
commit 7f26c8c769
6 changed files with 32 additions and 14 deletions

View file

@ -3,8 +3,20 @@ module Epp::DomainsHelper
Domain.transaction do
@domain = Domain.new(domain_create_params)
handle_errors(@domain) and return unless @domain.parse_and_attach_domain_dependencies(@ph, parsed_frame)
handle_errors(@domain) and return unless @domain.save
@domain.attach_owner_contact(@ph[:registrant]) if @ph[:registrant]
@domain.save
@domain.parse_and_attach_domain_dependencies(parsed_frame)
@domain.all_dependencies_valid?
if @domain.errors.any?
handle_errors(@domain)
raise ActiveRecord::Rollback and return
end
unless @domain.save
handle_errors(@domain)
raise ActiveRecord::Rollback and return
end
render '/epp/domains/create'
end
@ -40,7 +52,7 @@ module Epp::DomainsHelper
handle_errors(@domain) and return unless @domain
@domain.parse_and_attach_domain_dependencies(@ph, parsed_frame.css('add'))
@domain.parse_and_attach_domain_dependencies(parsed_frame.css('add'))
@domain.parse_and_detach_domain_dependencies(parsed_frame.css('rem'))
@domain.parse_and_update_domain_dependencies(parsed_frame.css('chg'))

View file

@ -39,11 +39,9 @@ class Domain < ActiveRecord::Base
validates :name_dirty, domain_name: true, uniqueness: true
validates :period, numericality: { only_integer: true }
validates :name, :owner_contact, presence: true
validates :owner_contact, presence: true
validate :validate_period
validate :validate_nameservers_count
validate :validate_admin_contacts_count
def name=(value)
value.strip!
@ -54,8 +52,7 @@ class Domain < ActiveRecord::Base
### CREATE & UPDATE ###
def parse_and_attach_domain_dependencies(ph, parsed_frame)
attach_owner_contact(ph[:registrant]) if ph[:registrant]
def parse_and_attach_domain_dependencies(parsed_frame)
attach_contacts(self.class.parse_contacts_from_frame(parsed_frame))
attach_nameservers(self.class.parse_nameservers_from_frame(parsed_frame))
attach_statuses(self.class.parse_statuses_from_frame(parsed_frame))
@ -300,6 +297,13 @@ class Domain < ActiveRecord::Base
add_epp_error('2306', 'curExpDate', cur_exp_date, I18n.t('errors.messages.epp_exp_dates_do_not_match'))
end
def all_dependencies_valid?
validate_nameservers_count
validate_admin_contacts_count
errors.empty?
end
def epp_code_map # rubocop:disable Metrics/MethodLength
domain_validation_sg = SettingGroup.domain_validation

View file

@ -8,9 +8,9 @@ class DomainNameValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if !self.class.validate_format(value)
record.errors[attribute] << (options[:message] || 'invalid format')
record.errors[attribute] << (options[:message] || record.errors.generate_message(attribute, :invalid))
elsif !self.class.validate_reservation(value)
record.errors.add(attribute, (options[:message] || :reserved))
record.errors.add(attribute, (options[:message] || record.errors.generate_message(attribute, :reserved)))
end
end

View file

@ -1,9 +1,10 @@
%h2= t('shared.new_domain')
%hr
= form_for([:admin, @domain]) do |f|
= @domain.errors.inspect
- if @domain.errors.any?
- @domain.errors.full_messages.each do |x|
= x
- @domain.errors.each do |attr, err|
= err
%br

View file

@ -70,6 +70,7 @@ en:
domain:
attributes:
name_dirty:
invalid: 'Domain name is invalid'
reserved: 'Domain name is reserved or restricted'
taken: 'Domain name already exists'
owner_contact:
@ -80,11 +81,12 @@ en:
admin_contacts:
out_of_range: 'Admin contacts count must be between 1 - infinity'
nameservers:
out_of_range: 'count must be between %{min}-%{max}'
out_of_range: 'Nameservers count must be between %{min}-%{max}'
not_found: 'Nameserver was not found'
taken: 'Nameserver already exists on this domain'
period:
out_of_range: 'Period must add up to 1, 2 or 3 years'
not_a_number: 'Period is not a number'
auth_info:
wrong_pw: 'Authentication error'
domain_statuses:

View file

@ -172,7 +172,6 @@ describe 'EPP Domain', epp: true do
it 'creates a domain' do
response = epp_request(domain_create_xml, :xml)
d = Domain.first
expect(response[:result_code]).to eq('1000')