From 1b4779de0eb9cfc7f36806a0192401ae044d3cb6 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Wed, 27 Aug 2014 12:28:59 +0300 Subject: [PATCH] Show status error in domain update request --- app/helpers/epp/domains_helper.rb | 20 +++++++++++++++----- app/models/domain.rb | 8 ++++++++ config/locales/en.yml | 1 + 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/helpers/epp/domains_helper.rb b/app/helpers/epp/domains_helper.rb index 8874acf3a..fff6fc4e0 100644 --- a/app/helpers/epp/domains_helper.rb +++ b/app/helpers/epp/domains_helper.rb @@ -39,11 +39,21 @@ module Epp::DomainsHelper @domain = find_domain handle_errors(@domain) and return unless @domain - handle_errors(@domain) and return unless @domain.parse_and_attach_domain_dependencies(@ph, parsed_frame.css('add')) - handle_errors(@domain) and return unless @domain.parse_and_detach_domain_dependencies(parsed_frame.css('rem')) - handle_errors(@domain) and return unless @domain.parse_and_update_domain_dependencies(parsed_frame.css('chg')) - handle_errors(@domain) and return unless @domain.parse_and_update_domain_attributes(parsed_frame.css('chg')) - handle_errors(@domain) and return unless @domain.save + + @domain.parse_and_attach_domain_dependencies(@ph, parsed_frame.css('add')) + @domain.parse_and_detach_domain_dependencies(parsed_frame.css('rem')) + @domain.parse_and_update_domain_dependencies(parsed_frame.css('chg')) + @domain.parse_and_update_domain_attributes(parsed_frame.css('chg')) + + 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/success' end diff --git a/app/models/domain.rb b/app/models/domain.rb index a394c840f..fc40188ed 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -127,7 +127,15 @@ class Domain < ActiveRecord::Base def attach_statuses(status_list) status_list.each do |x| + existing = domain_statuses.select { |o| o.value == x[:value] } + + if existing.any? + add_epp_error('2302', 'status', x[:value], [:domain_statuses, :taken]) + next + end + setting = SettingGroup.domain_statuses.settings.find_by(value: x[:value]) + domain_statuses.build( setting: setting, description: x[:description] diff --git a/config/locales/en.yml b/config/locales/en.yml index e3192e92c..69c8c1a21 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -61,6 +61,7 @@ en: wrong_pw: 'Authentication error' domain_statuses: not_found: 'Status was not found' + taken: 'Status already exists on this domain' nameserver: attributes: hostname: