Remove contact code cache from domain contacts table

This commit is contained in:
Thiago Youssef 2022-05-04 14:38:14 +03:00
parent 3852620180
commit 750bf0821c
11 changed files with 42 additions and 50 deletions

View file

@ -14,8 +14,8 @@ module Repp
api :GET, '/repp/v1/domains/:domain_name/contacts'
desc "View domain's admin and tech contacts"
def index
admin_contacts = @domain.admin_domain_contacts.pluck(:contact_code_cache)
tech_contacts = @domain.tech_domain_contacts.pluck(:contact_code_cache)
admin_contacts = @domain.admin_domain_contacts.map(&:contact).pluck(:code)
tech_contacts = @domain.tech_domain_contacts.map(&:contact).pluck(:code)
data = { admin_contacts: admin_contacts, tech_contacts: tech_contacts }
render_success(data: data)
@ -38,7 +38,6 @@ module Repp
def cta(action = 'add')
params[:contacts].each { |c| c[:action] = action }
action = Actions::DomainUpdate.new(@domain, contact_create_params, false)
# rubocop:disable Style/AndOr
handle_errors(@domain) and return unless action.call
# rubocop:enable Style/AndOr

View file

@ -120,7 +120,7 @@ module Actions
contact = Contact.find_by(code: contact_code)
arr = admin ? @admin_contacts : @tech_contacts
if contact
arr << { contact_id: contact.id, contact_code_cache: contact.code }
arr << { contact_id: contact.id }
else
domain.add_epp_error('2303', 'contact', contact_code, %i[domain_contacts not_found])
end

View file

@ -125,8 +125,7 @@ module Actions
end
def start_validate_email(props)
contact_code = props[0][:contact_code_cache]
contact = Contact.find_by(code: contact_code)
contact = Contact.find(props[0][:contact_id])
return if contact.nil?
@ -206,7 +205,7 @@ module Actions
domain.add_epp_error('2306', 'contact', code,
%i[domain_contacts admin_contact_can_be_only_private_person])
else
add ? { contact_id: obj.id, contact_code_cache: obj.code } : { id: obj.id, _destroy: 1 }
add ? { contact_id: obj.id } : { id: obj.id, _destroy: 1 }
end
end

View file

@ -161,14 +161,6 @@ class Domain < ApplicationRecord
attribute: 'hostname'
}
validates :tech_domain_contacts, uniqueness_multi: {
attribute: 'contact_code_cache'
}
validates :admin_domain_contacts, uniqueness_multi: {
attribute: 'contact_code_cache'
}
validates :dnskeys, uniqueness_multi: {
attribute: 'public_key'
}

View file

@ -6,32 +6,20 @@ class DomainContact < ApplicationRecord
belongs_to :contact
belongs_to :domain
validates :contact, presence: true
after_destroy :update_contact
attr_accessor :value_typeahead
self.ignored_columns = %w[legacy_domain_id legacy_contact_id]
def epp_code_map
{
'2302' => [
[:contact_code_cache, :taken, { value: { obj: 'contact', val: contact_code_cache } }]
]
}
end
def name
return 'Tech' if type == 'TechDomainContact'
return 'Admin' if type == 'AdminDomainContact'
''
end
validates :contact, presence: true
before_save :update_contact_code_cache
def update_contact_code_cache
self.contact_code_cache = contact.code
end
after_destroy :update_contact
def update_contact
Contact.find(contact_id).save
end

View file

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

View file

@ -1,10 +1,10 @@
class AddCodeCacheForDomainContact < ActiveRecord::Migration[6.0]
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
# 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

@ -0,0 +1,5 @@
class RemoveContactCodeCacheFromDomainContacts < ActiveRecord::Migration[6.1]
def change
# remove_column :domain_contacts, :contact_code_cache
end
end

View file

@ -51,6 +51,20 @@ CREATE EXTENSION IF NOT EXISTS hstore WITH SCHEMA public;
COMMENT ON EXTENSION hstore IS 'data type for storing sets of (key, value) pairs';
--
-- Name: pg_stat_statements; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS pg_stat_statements WITH SCHEMA public;
--
-- Name: EXTENSION pg_stat_statements; Type: COMMENT; Schema: -; Owner: -
--
COMMENT ON EXTENSION pg_stat_statements IS 'track execution statistics of all SQL statements executed';
--
-- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner: -
--
@ -848,7 +862,6 @@ CREATE TABLE public.domain_contacts (
domain_id integer,
created_at timestamp without time zone,
updated_at timestamp without time zone,
contact_code_cache character varying,
creator_str character varying,
updator_str character varying,
type character varying,
@ -1091,7 +1104,6 @@ CREATE TABLE public.invoices (
buyer_vat_no character varying,
issue_date date NOT NULL,
e_invoice_sent_at timestamp without time zone,
payment_link character varying,
CONSTRAINT invoices_due_date_is_not_before_issue_date CHECK ((due_date >= issue_date))
);
@ -5083,13 +5095,13 @@ INSERT INTO "schema_migrations" (version) VALUES
('20220106123143'),
('20220113201642'),
('20220113220809'),
('20220228093211'),
('20220316140727'),
('20220406085500'),
('20220412130856'),
('20220413073315'),
('20220413084536'),
('20220413084748'),
('20220124105717'),
('20220216113112'),
('20220228093211'),
('20220412130856');
('20220504090512');

View file

@ -9980,7 +9980,7 @@ RESPONSE:
</value>
</result>
<result code="2302">
<msg lang="en">Contact already exists on this domain [contact_code_cache]</msg>
<msg lang="en">Contact already exists on this domain [contact_code]</msg>
<value xmlns:obj="urn:ietf:params:xml:ns:obj">
<obj:contact>FIXED:MAK21</obj:contact>
</value>
@ -10505,7 +10505,7 @@ RESPONSE:
</value>
</result>
<result code="2302">
<msg lang="en">Contact already exists on this domain [contact_code_cache]</msg>
<msg lang="en">Contact already exists on this domain [contact_code]</msg>
<value xmlns:obj="urn:ietf:params:xml:ns:obj">
<obj:contact>FIXED:SH6021836789</obj:contact>
</value>
@ -14058,4 +14058,3 @@ RESPONSE:
</response>
</epp>
```

View file

@ -23,7 +23,7 @@ module Serializers
# rubocop:enable Metrics/AbcSize
def contacts
domain.domain_contacts.map { |c| { code: c.contact_code_cache, type: c.type } }
domain.domain_contacts.map { |c| { code: c.contact.code, type: c.type } }
end
def nameservers