From 7caa544c83c50a9421c42a39b40f38b04b61dea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Tue, 29 Dec 2020 13:16:45 +0200 Subject: [PATCH] Fix some CC issues --- app/controllers/epp/domains_controller.rb | 3 +- .../process_update_confirmed.rb | 3 -- app/models/actions/domain_create.rb | 10 +++--- app/models/actions/domain_update.rb | 35 ++++++++++++------- app/models/epp/domain.rb | 20 ----------- lib/deserializers/xml/dnssec.rb | 5 +-- lib/deserializers/xml/domain_update.rb | 25 ++++++++----- lib/deserializers/xml/nameserver.rb | 2 +- 8 files changed, 50 insertions(+), 53 deletions(-) diff --git a/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb index 3432f8953..9cded2f75 100644 --- a/app/controllers/epp/domains_controller.rb +++ b/app/controllers/epp/domains_controller.rb @@ -40,7 +40,8 @@ module Epp authorize!(:update, @domain, @password) registrar_id = current_user.registrar.id - update_params = ::Deserializers::Xml::DomainUpdate.new(params[:parsed_frame], registrar_id).call + update_params = ::Deserializers::Xml::DomainUpdate.new(params[:parsed_frame], + registrar_id).call action = Actions::DomainUpdate.new(@domain, update_params, false) if action.call pending = @domain.epp_pending_update.present? diff --git a/app/interactions/domains/update_confirm/process_update_confirmed.rb b/app/interactions/domains/update_confirm/process_update_confirmed.rb index cf7c82a7a..320f0071f 100644 --- a/app/interactions/domains/update_confirm/process_update_confirmed.rb +++ b/app/interactions/domains/update_confirm/process_update_confirmed.rb @@ -24,13 +24,10 @@ module Domains user = ApiUser.find(domain.pending_json['current_user_id']) frame = domain.pending_json['frame'] ? domain.pending_json['frame'].with_indifferent_access : {} - #self.statuses.delete(DomainStatus::PENDING_UPDATE) domain.upid = user.registrar.id if user.registrar domain.up_date = Time.zone.now Actions::DomainUpdate.new(domain, frame, true).call - - #save! end end end diff --git a/app/models/actions/domain_create.rb b/app/models/actions/domain_create.rb index 9cff3ce17..2d351e470 100644 --- a/app/models/actions/domain_create.rb +++ b/app/models/actions/domain_create.rb @@ -69,7 +69,7 @@ module Actions attrs = [] params[:admin_domain_contacts_attributes].each do |c| contact = Contact.find_by(code: c) - domain.add_epp_error('2303', 'contact', c, %i[domain_contacts not_found]) unless contact.present? + domain.add_epp_error('2303', 'contact', c, %i[domain_contacts not_found]) if contact.blank? attrs << { contact_id: contact.id, contact_code_cache: contact.code } if contact end @@ -80,7 +80,7 @@ module Actions attrs = [] params[:tech_domain_contacts_attributes].each do |c| contact = Contact.find_by(code: c) - domain.add_epp_error('2303', 'contact', c, %i[domain_contacts not_found]) unless contact.present? + domain.add_epp_error('2303', 'contact', c, %i[domain_contacts not_found]) if contact.blank? attrs << { contact_id: contact.id, contact_code_cache: contact.code } if contact end @@ -104,9 +104,9 @@ module Actions return end - domain.registrar.debit!({ sum: @domain_pricelist.price.amount, price: @domain_pricelist, - description: "#{I18n.t('create')} #{domain.name}", - activity_type: AccountActivity::CREATE }) + domain.registrar.debit!(sum: @domain_pricelist.price.amount, price: @domain_pricelist, + description: "#{I18n.t('create')} #{domain.name}", + activity_type: AccountActivity::CREATE) end def process_auction_and_disputes diff --git a/app/models/actions/domain_update.rb b/app/models/actions/domain_update.rb index 63a604335..0c06db6f2 100644 --- a/app/models/actions/domain_update.rb +++ b/app/models/actions/domain_update.rb @@ -33,7 +33,10 @@ module Actions def assign_new_registrant return unless params[:registrant] - domain.add_epp_error('2306', nil, nil, %i[registrant cannot_be_missing]) unless params[:registrant][:code] + unless params[:registrant][:code] + domain.add_epp_error('2306', nil, nil, %i[registrant cannot_be_missing]) + end + regt = Registrant.find_by(code: params[:registrant][:code]) if regt.present? return if domain.registrant == regt @@ -51,7 +54,10 @@ module Actions nameservers = [] params[:nameservers].select { |ns| ns[:action] == 'rem' }.each do |ns_attr| ns = domain.nameservers.find_by_hash_params(ns_attr.except(:action)).first - domain.add_epp_error('2303', 'hostAttr', ns_attr[:hostname], %i[nameservers not_found]) and break unless ns + unless ns + domain.add_epp_error('2303', 'hostAttr', ns_attr[:hostname], %i[nameservers not_found]) + break + end nameservers << { id: ns.id, _destroy: 1 } end @@ -59,7 +65,7 @@ module Actions nameservers << ns_attr.except(:action) end - return unless nameservers.present? + return if nameservers.blank? domain.nameservers_attributes = nameservers end @@ -95,7 +101,8 @@ module Actions contacts = params[:contacts].select { |c| c[:type] == 'admin' } if contacts.present? && domain.admin_change_prohibited? - domain.add_epp_error('2304', 'admin', DomainStatus::SERVER_ADMIN_CHANGE_PROHIBITED, I18n.t(:object_status_prohibits_operation)) + domain.add_epp_error('2304', 'admin', DomainStatus::SERVER_ADMIN_CHANGE_PROHIBITED, + I18n.t(:object_status_prohibits_operation)) return end @@ -109,10 +116,11 @@ module Actions end contacts.select { |c| c[:action] == 'add' }.each do |c| - contact = Epp::Contact.find_by_epp_code(c[:code]) + contact = Epp::Contact.find_by(code: c[:code]) if contact.present? if contact.org? - domain.add_epp_error('2306', 'contact', c[:code], %i[domain_contacts admin_contact_can_be_only_private_person]) + domain.add_epp_error('2306', 'contact', c[:code], + %i[domain_contacts admin_contact_can_be_only_private_person]) else props << { contact_id: contact.id, contact_code_cache: contact.code } end @@ -121,7 +129,7 @@ module Actions end end - return unless props.present? + return if props.blank? domain.admin_domain_contacts_attributes = props end @@ -133,7 +141,8 @@ module Actions contacts = params[:contacts].select { |c| c[:type] == 'tech' } if contacts.present? && domain.tech_change_prohibited? - domain.add_epp_error('2304', 'tech', DomainStatus::SERVER_TECH_CHANGE_PROHIBITED, I18n.t(:object_status_prohibits_operation)) + domain.add_epp_error('2304', 'tech', DomainStatus::SERVER_TECH_CHANGE_PROHIBITED, + I18n.t(:object_status_prohibits_operation)) return end @@ -147,7 +156,7 @@ module Actions end contacts.select { |c| c[:action] == 'add' }.each do |c| - contact = Epp::Contact.find_by_epp_code(c[:code]) + contact = Epp::Contact.find_by(code: c[:code]) if contact.present? props << { contact_id: contact.id, contact_code_cache: contact.code } else @@ -155,7 +164,7 @@ module Actions end end - return unless props.present? + return if props.blank? domain.tech_domain_contacts_attributes = props end @@ -203,10 +212,12 @@ module Actions Dispute.close_by_domain(domain.name) return false else - domain.add_epp_error('2202', nil, nil, 'Invalid authorization information; invalid reserved>pw value') + domain.add_epp_error('2202', nil, nil, + 'Invalid authorization information; invalid reserved>pw value') end else - domain.add_epp_error('2304', nil, nil, 'Required parameter missing; reservedpw element required for dispute domains') + domain.add_epp_error('2304', nil, nil, "Required parameter missing; reservedpw element " \ + 'required for dispute domains') end true diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 8ab53b300..697787183 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -129,26 +129,6 @@ class Epp::Domain < Domain self.legal_document_id = doc.id end - def apply_pending_update! - preclean_pendings - user = ApiUser.find(pending_json['current_user_id']) - frame = pending_json['frame'] ? pending_json['frame'].with_indifferent_access : {} - - self.statuses.delete(DomainStatus::PENDING_UPDATE) - self.upid = user.registrar.id if user.registrar - self.up_date = Time.zone.now - - return unless Actions::DomainUpdate.new(self, frame, true).call - - clean_pendings! - - save! - - WhoisRecord.find_by(domain_id: id).save # need to reload model - - true - end - def apply_pending_delete! preclean_pendings statuses.delete(DomainStatus::PENDING_DELETE_CONFIRMATION) diff --git a/lib/deserializers/xml/dnssec.rb b/lib/deserializers/xml/dnssec.rb index f255716d4..a9c348ea6 100644 --- a/lib/deserializers/xml/dnssec.rb +++ b/lib/deserializers/xml/dnssec.rb @@ -3,9 +3,10 @@ module Deserializers class DnssecKey attr_reader :frame, :dsa - KEY_INTERFACE = { flags: 'flags', protocol: 'protocol', alg: 'alg', public_key: 'pubKey' } + KEY_INTERFACE = { flags: 'flags', protocol: 'protocol', alg: 'alg', + public_key: 'pubKey' }.freeze DS_INTERFACE = { ds_key_tag: 'keyTag', ds_alg: 'alg', ds_digest_type: 'digestType', - ds_digest: 'digest' } + ds_digest: 'digest' }.freeze def initialize(frame, dsa) @frame = frame diff --git a/lib/deserializers/xml/domain_update.rb b/lib/deserializers/xml/domain_update.rb index 15acf8b4b..4a6a5b74b 100644 --- a/lib/deserializers/xml/domain_update.rb +++ b/lib/deserializers/xml/domain_update.rb @@ -14,8 +14,9 @@ module Deserializers def call obj = { domain: frame.css('name')&.text, registrant: registrant, contacts: contacts, - auth_info: if_present('authInfo > pw'), nameservers: nameservers, dns_keys: dns_keys, - registrar_id: registrar, statuses: statuses, reserved_pw: if_present('reserved > pw') } + auth_info: if_present('authInfo > pw'), nameservers: nameservers, + registrar_id: registrar, statuses: statuses, dns_keys: dns_keys, + reserved_pw: if_present('reserved > pw') } obj.reject { |_key, val| val.blank? } end @@ -23,7 +24,8 @@ module Deserializers def registrant return if frame.css('chg > registrant').blank? - { code: frame.css('chg > registrant').text, verified: frame.css('chg > registrant').attr('verified').to_s.downcase == 'yes' } + { code: frame.css('chg > registrant').text, + verified: frame.css('chg > registrant').attr('verified').to_s.downcase == 'yes' } end def contacts @@ -36,7 +38,7 @@ module Deserializers contacts << { code: c.text, type: c['type'], action: 'rem' } end - contacts.present? ? contacts : nil + contacts.presence end def nameservers @@ -53,7 +55,7 @@ module Deserializers nameservers << nsrv end - nameservers.present? ? nameservers : nil + nameservers.presence end def dns_keys @@ -62,18 +64,23 @@ module Deserializers removed = ::Deserializers::Xml::DnssecKeys.new(frame.css('rem')).call removed.each { |k| k[:action] = 'rem' } - return unless (added + removed).present? + return if (added + removed).blank? added + removed end def statuses - return unless frame.css('status').present? + return if frame.css('status').blank? statuses = [] - frame.css('add > status').each { |entry| statuses << { status: entry.attr('s').to_s, action: 'add' } } - frame.css('rem > status').each { |entry| statuses << { status: entry.attr('s').to_s, action: 'rem' } } + frame.css('add > status').each do |e| + statuses << { status: e.attr('s').to_s, action: 'add' } + end + + frame.css('rem > status').each do |e| + statuses << { status: e.attr('s').to_s, action: 'rem' } + end statuses end diff --git a/lib/deserializers/xml/nameserver.rb b/lib/deserializers/xml/nameserver.rb index f43407d68..03b264718 100644 --- a/lib/deserializers/xml/nameserver.rb +++ b/lib/deserializers/xml/nameserver.rb @@ -11,7 +11,7 @@ module Deserializers { hostname: frame.css('hostName').text, ipv4: frame.css('hostAddr[ip="v4"]').map(&:text).compact, - ipv6: frame.css('hostAddr[ip="v6"]').map(&:text).compact + ipv6: frame.css('hostAddr[ip="v6"]').map(&:text).compact, } end end