Cache contact code for epp eager errors

This commit is contained in:
Martin Lensment 2014-12-10 11:35:48 +02:00
parent 8aac684df7
commit ddd91d464a
9 changed files with 42 additions and 14 deletions

View file

@ -43,7 +43,7 @@ class Domain < ActiveRecord::Base
before_create :generate_auth_info before_create :generate_auth_info
before_create :set_validity_dates before_create :set_validity_dates
after_create :attach_default_contacts before_create :attach_default_contacts
after_save :manage_automatic_statuses after_save :manage_automatic_statuses
validates :name_dirty, domain_name: true, uniqueness: true validates :name_dirty, domain_name: true, uniqueness: true
@ -186,7 +186,7 @@ class Domain < ActiveRecord::Base
next unless existing.length > 1 next unless existing.length > 1
validated << dc validated << dc
errors.add(:domain_contacts, :invalid) if errors[:domain_contacts].blank? errors.add(:domain_contacts, :invalid) if errors[:domain_contacts].blank?
dc.errors.add(:contact, :taken) dc.errors.add(:contact_code_cache, :taken)
end end
end end
@ -280,8 +280,22 @@ class Domain < ActiveRecord::Base
# rubocop:enable Lint/Loop # rubocop:enable Lint/Loop
def attach_default_contacts def attach_default_contacts
tech_contacts << owner_contact if tech_contacts_count.zero? if tech_contacts_count.zero?
admin_contacts << owner_contact if admin_contacts_count.zero? && owner_contact.citizen? attach_contact(DomainContact::TECH, owner_contact)
end
return unless admin_contacts_count.zero? && owner_contact.citizen?
attach_contact(DomainContact::ADMIN, owner_contact)
end
def attach_contact(type, contact)
domain_contacts.build(
contact: contact, contact_type: DomainContact::TECH, contact_code_cache: contact.code
) if type.to_sym == :tech
domain_contacts.build(
contact: contact, contact_type: DomainContact::ADMIN, contact_code_cache: contact.code
) if type.to_sym == :admin
end end
def set_validity_dates def set_validity_dates

View file

@ -12,7 +12,7 @@ class DomainContact < ActiveRecord::Base
def epp_code_map def epp_code_map
{ {
'2302' => [ '2302' => [
[:contact, :taken, { value: { obj: 'contact', val: contact.code } }] [:contact_code_cache, :taken, { value: { obj: 'contact', val: contact_code_cache } }]
] ]
} }
end end

View file

@ -121,11 +121,6 @@ class Epp::EppDomain < Domain
attach_contact(DomainContact::ADMIN, owner_contact) if admin_contacts_count.zero? && owner_contact.citizen? attach_contact(DomainContact::ADMIN, owner_contact) if admin_contacts_count.zero? && owner_contact.citizen?
end end
def attach_contact(type, contact)
domain_contacts.build(contact: contact, contact_type: DomainContact::TECH) if type.to_sym == :tech
domain_contacts.build(contact: contact, contact_type: DomainContact::ADMIN) if type.to_sym == :admin
end
def attach_nameservers(ns_list) def attach_nameservers(ns_list)
ns_list.each do |ns_attrs| ns_list.each do |ns_attrs|
nameservers.build(ns_attrs) nameservers.build(ns_attrs)
@ -302,7 +297,6 @@ class Epp::EppDomain < Domain
end end
return pt if pt return pt if pt
if Setting.transfer_wait_time > 0 if Setting.transfer_wait_time > 0
dt = domain_transfers.create( dt = domain_transfers.create(
status: DomainTransfer::PENDING, status: DomainTransfer::PENDING,

View file

@ -139,6 +139,8 @@ en:
contact: contact:
blank: 'Contact was not found' blank: 'Contact was not found'
taken: 'Contact already exists on this domain!' taken: 'Contact already exists on this domain!'
contact_code_cache:
taken: 'Contact already exists on this domain!'
domain_status: domain_status:
attributes: attributes:

View file

@ -0,0 +1,10 @@
class AddCodeCacheForDomainContact < ActiveRecord::Migration
def change
add_column :domain_contacts, :contact_code_cache, :string
DomainContact.all.each do |x|
x.contact_code_cache = x.contact.code
x.save
end
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20141203090115) do ActiveRecord::Schema.define(version: 20141210085432) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -139,6 +139,7 @@ ActiveRecord::Schema.define(version: 20141203090115) do
t.string "contact_type" t.string "contact_type"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "contact_code_cache"
end end
create_table "domain_status_versions", force: true do |t| create_table "domain_status_versions", force: true do |t|

View file

@ -892,7 +892,7 @@ describe 'EPP Domain', epp: true do
expect(response[:results][0][:msg]).to eq('Domain not found') expect(response[:results][0][:msg]).to eq('Domain not found')
end end
it 'updates domain and adds objects', pending: true do it 'updates domain and adds objects' do
xml = domain_update_xml({ xml = domain_update_xml({
add: [ add: [
{ {

View file

@ -0,0 +1,7 @@
Fabricator(:domain_contact) do
contact { Fabricate(:contact) }
contact_type 'admin'
after_build do |x|
x.contact_code_cache = x.contact.code
end
end

View file

@ -5,7 +5,7 @@ Fabricator(:domain) do
period_unit 'y' period_unit 'y'
owner_contact(fabricator: :contact) owner_contact(fabricator: :contact)
nameservers(count: 3) nameservers(count: 3)
admin_contacts(count: 1) { Fabricate(:contact) } domain_contacts(count: 1) { Fabricate(:domain_contact, contact_type: 'admin') }
registrar registrar
auth_info '98oiewslkfkd' auth_info '98oiewslkfkd'
dnskeys(count: 1) dnskeys(count: 1)