mirror of
https://github.com/internetee/registry.git
synced 2025-07-30 14:36:22 +02:00
Fixed codeclimate errors
This commit is contained in:
parent
a5ffce290d
commit
7c570e2916
12 changed files with 114 additions and 103 deletions
|
@ -1,6 +1,6 @@
|
||||||
module Repp
|
module Repp
|
||||||
module V1
|
module V1
|
||||||
class AccountController < BaseController
|
class AccountController < BaseController # rubocop:disable Metrics/ClassLength
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
|
|
||||||
api :get, '/repp/v1/account'
|
api :get, '/repp/v1/account'
|
||||||
|
|
|
@ -9,7 +9,7 @@ module Repp
|
||||||
desc 'Get all existing contacts'
|
desc 'Get all existing contacts'
|
||||||
def index
|
def index
|
||||||
authorize! :check, Epp::Contact
|
authorize! :check, Epp::Contact
|
||||||
records = current_user.registrar.contacts.order(created_at: :desc)
|
records = current_user.registrar.contacts
|
||||||
|
|
||||||
q = records.ransack(search_params)
|
q = records.ransack(search_params)
|
||||||
q.sorts = 'created_at desc' if q.sorts.empty?
|
q.sorts = 'created_at desc' if q.sorts.empty?
|
||||||
|
@ -19,8 +19,7 @@ module Repp
|
||||||
.includes(:domain_contacts, :registrant_domains, :registrar)
|
.includes(:domain_contacts, :registrant_domains, :registrar)
|
||||||
|
|
||||||
render_success(data: { contacts: serialized_contacts(limited_contacts),
|
render_success(data: { contacts: serialized_contacts(limited_contacts),
|
||||||
count: contacts.count,
|
count: contacts.count, statuses: Contact::STATUSES,
|
||||||
statuses: Contact::STATUSES,
|
|
||||||
ident_types: Contact::Ident.types })
|
ident_types: Contact::Ident.types })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -156,7 +155,7 @@ module Repp
|
||||||
end
|
end
|
||||||
|
|
||||||
def serialized_contacts(contacts)
|
def serialized_contacts(contacts)
|
||||||
return contacts.map {|c| c.code } unless index_params[:details] == 'true'
|
return contacts.map(&code) unless index_params[:details] == 'true'
|
||||||
|
|
||||||
address_processing = Contact.address_processing?
|
address_processing = Contact.address_processing?
|
||||||
contacts.map do |c|
|
contacts.map do |c|
|
||||||
|
|
|
@ -51,14 +51,11 @@ module Repp
|
||||||
|
|
||||||
def select_renewable_domains
|
def select_renewable_domains
|
||||||
@epp_errors ||= ActiveModel::Errors.new(self)
|
@epp_errors ||= ActiveModel::Errors.new(self)
|
||||||
|
@domains = bulk_renew_domains
|
||||||
if bulk_renew_params[:domains].instance_of?(Array)
|
if @domains.empty?
|
||||||
@domains = bulk_renew_domains
|
@epp_errors.add(:epp_errors, msg: 'Domains cannot be empty',
|
||||||
@epp_errors.add(:epp_errors, msg: 'Domains cannot be empty', code: '2005') if @domains.empty?
|
code: '2005')
|
||||||
else
|
|
||||||
@epp_errors.add(:epp_errors, msg: 'Domains attribute must be an array', code: '2005')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return handle_errors if @epp_errors.any?
|
return handle_errors if @epp_errors.any?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -77,14 +74,18 @@ module Repp
|
||||||
def bulk_renew_domains
|
def bulk_renew_domains
|
||||||
@epp_errors ||= ActiveModel::Errors.new(self)
|
@epp_errors ||= ActiveModel::Errors.new(self)
|
||||||
domains = []
|
domains = []
|
||||||
bulk_renew_params[:domains].each do |idn|
|
if bulk_renew_params[:domains].instance_of?(Array)
|
||||||
domain = Epp::Domain.find_by(name: idn)
|
bulk_renew_params[:domains].each do |idn|
|
||||||
domains << domain if domain
|
domain = Epp::Domain.find_by(name: idn)
|
||||||
next if domain
|
domains << domain if domain
|
||||||
|
next if domain
|
||||||
|
|
||||||
@epp_errors.add(:epp_errors,
|
@epp_errors.add(:epp_errors,
|
||||||
msg: "Object does not exist: #{idn}",
|
msg: "Object does not exist: #{idn}",
|
||||||
code: '2304')
|
code: '2304')
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@epp_errors.add(:epp_errors, msg: 'Domains attribute must be an array', code: '2005')
|
||||||
end
|
end
|
||||||
|
|
||||||
domains
|
domains
|
||||||
|
|
|
@ -30,7 +30,7 @@ module Repp
|
||||||
api :GET, '/repp/v1/domains/:domain_name'
|
api :GET, '/repp/v1/domains/:domain_name'
|
||||||
desc 'Get a specific domain'
|
desc 'Get a specific domain'
|
||||||
def show
|
def show
|
||||||
@domain = Epp::Domain.find_by_name(params[:id])
|
@domain = Epp::Domain.find_by(name: params[:id])
|
||||||
authorize! :info, @domain
|
authorize! :info, @domain
|
||||||
|
|
||||||
sponsor = @domain.registrar == current_user.registrar
|
sponsor = @domain.registrar == current_user.registrar
|
||||||
|
@ -251,34 +251,33 @@ module Repp
|
||||||
dup_params = domain_params.to_h.dup
|
dup_params = domain_params.to_h.dup
|
||||||
return dup_params unless dup_params[:contacts]
|
return dup_params unless dup_params[:contacts]
|
||||||
|
|
||||||
new_contact_params = dup_params[:contacts].map do |c|
|
modify_contact_params(dup_params)
|
||||||
c.to_h.symbolize_keys
|
end
|
||||||
end
|
|
||||||
|
|
||||||
old_contact_params = @domain.domain_contacts.map do |c|
|
def modify_contact_params(params)
|
||||||
{ code: c.contact_code_cache, type: c.name.downcase }
|
new_contact_params = params[:contacts].map { |c| c.to_h.symbolize_keys }
|
||||||
|
old_contact_params = @domain.domain_contacts.includes(:contact).map do |c|
|
||||||
|
{ code: c.contact.code, type: c.name.downcase }
|
||||||
end
|
end
|
||||||
dup_params[:contacts] = (new_contact_params - old_contact_params).map { |c| c.merge(action: 'add') }
|
params[:contacts] = (new_contact_params - old_contact_params).map do |c|
|
||||||
dup_params[:contacts].concat((old_contact_params - new_contact_params)
|
c.merge(action: 'add')
|
||||||
.map { |c| c.merge(action: 'rem') })
|
end
|
||||||
|
params[:contacts].concat((old_contact_params - new_contact_params)
|
||||||
dup_params
|
.map { |c| c.merge(action: 'rem') })
|
||||||
|
params
|
||||||
end
|
end
|
||||||
|
|
||||||
def domain_params
|
def domain_params
|
||||||
params.require(:domain)
|
params.require(:domain).permit(:name, :period, :period_unit, :registrar, :transfer_code,
|
||||||
.permit(:name, :period, :period_unit, :registrar,
|
:reserved_pw, :legal_document, :registrant,
|
||||||
:transfer_code, :reserved_pw, :legal_document,
|
legal_document: %i[body type], registrant: [%i[code verified]],
|
||||||
:registrant, legal_document: %i[body type],
|
dns_keys: [%i[id flags alg protocol public_key action]],
|
||||||
registrant: [%i[code verified]],
|
nameservers: [[:id, :hostname, :action, { ipv4: [], ipv6: [] }]],
|
||||||
dns_keys: [%i[id flags alg protocol public_key action]],
|
contacts: [%i[code type action]],
|
||||||
nameservers: [[:id, :hostname,
|
nameservers_attributes: [[:hostname, { ipv4: [], ipv6: [] }]],
|
||||||
:action, { ipv4: [], ipv6: [] }]],
|
admin_contacts: [], tech_contacts: [],
|
||||||
contacts: [%i[code type action]],
|
dnskeys_attributes: [%i[flags alg protocol public_key]],
|
||||||
nameservers_attributes: [[:hostname, { ipv4: [], ipv6: [] }]],
|
delete: [:verified])
|
||||||
admin_contacts: [], tech_contacts: [],
|
|
||||||
dnskeys_attributes: [%i[flags alg protocol public_key]],
|
|
||||||
delete: [:verified])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -115,4 +115,4 @@ module Repp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,4 +46,4 @@ module Repp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,33 +11,60 @@ module Repp
|
||||||
if can?(:manage, :poll)
|
if can?(:manage, :poll)
|
||||||
user_notifications = user.unread_notifications
|
user_notifications = user.unread_notifications
|
||||||
notification = user_notifications.order('created_at DESC').take
|
notification = user_notifications.order('created_at DESC').take
|
||||||
notifications_count = user_notifications.count
|
|
||||||
if notification&.attached_obj_type && notification&.attached_obj_id
|
|
||||||
begin
|
|
||||||
object = object_by_type(notification.attached_obj_type)
|
|
||||||
.find(notification.attached_obj_id)
|
|
||||||
rescue => e
|
|
||||||
# the data model might be inconsistent; or ...
|
|
||||||
# this could happen if the registrar does not dequeue messages, and then the domain was deleted
|
|
||||||
# SELECT messages.id, domains.name, messages.body FROM messages LEFT OUTER
|
|
||||||
# JOIN domains ON attached_obj_id::INTEGER = domains.id
|
|
||||||
# WHERE attached_obj_type = 'Epp::Domain' AND name IS NULL;
|
|
||||||
message = 'orphan message, domain deleted, registrar should dequeue: '
|
|
||||||
Rails.logger.error message + e.to_s
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
data = serialize_data(registrar: registrar,
|
render_success(data: serialize_data(registrar: registrar,
|
||||||
notification: notification,
|
notification: notification,
|
||||||
notifications_count: notifications_count,
|
notifications_count: user_notifications&.count,
|
||||||
object: object)
|
object: notification_object(notification)))
|
||||||
|
end
|
||||||
|
|
||||||
render_success(data: data)
|
def serialized_domain_transfer(object)
|
||||||
|
{
|
||||||
|
name: object.domain_name, trStatus: object.status,
|
||||||
|
reID: object.new_registrar.code,
|
||||||
|
reDate: object.transfer_requested_at.try(:iso8601),
|
||||||
|
acID: object.old_registrar.code,
|
||||||
|
acDate: object.transferred_at.try(:iso8601) || object.wait_until.try(:iso8601),
|
||||||
|
exDate: object.domain_valid_to.iso8601
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def serialized_contact_update_action(object)
|
||||||
|
{
|
||||||
|
contacts: object.to_non_available_contact_codes,
|
||||||
|
operation: object.operation,
|
||||||
|
opDate: object.created_at.utc.xmlschema,
|
||||||
|
svTrid: object.id,
|
||||||
|
who: object.user.username,
|
||||||
|
reason: 'Auto-update according to official data',
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
# rubocop:disable Style/RescueStandardError
|
||||||
|
def notification_object(notification)
|
||||||
|
return unless notification
|
||||||
|
|
||||||
|
return unless notification.attached_obj_type || notification.attached_obj_id
|
||||||
|
|
||||||
|
begin
|
||||||
|
object_by_type(notification.attached_obj_type)
|
||||||
|
.find(notification.attached_obj_id)
|
||||||
|
rescue => e
|
||||||
|
# the data model might be inconsistent; or ...
|
||||||
|
# this could happen if the registrar does not dequeue messages,
|
||||||
|
# and then the domain was deleted
|
||||||
|
# SELECT messages.id, domains.name, messages.body FROM messages LEFT OUTER
|
||||||
|
# JOIN domains ON attached_obj_id::INTEGER = domains.id
|
||||||
|
# WHERE attached_obj_type = 'Epp::Domain' AND name IS NULL;
|
||||||
|
message = 'orphan message, domain deleted, registrar should dequeue: '
|
||||||
|
Rails.logger.error message + e.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# rubocop:enable Style/RescueStandardError
|
||||||
|
|
||||||
def object_by_type(object_type)
|
def object_by_type(object_type)
|
||||||
Object.const_get(object_type)
|
Object.const_get(object_type)
|
||||||
rescue NameError
|
rescue NameError
|
||||||
|
@ -83,29 +110,9 @@ module Repp
|
||||||
def serialized_object(object, obj_type)
|
def serialized_object(object, obj_type)
|
||||||
return unless object
|
return unless object
|
||||||
|
|
||||||
case obj_type
|
try("serialized_#{obj_type.underscore}", object)
|
||||||
when 'DomainTransfer'
|
|
||||||
{
|
|
||||||
name: object.domain_name,
|
|
||||||
trStatus: object.status,
|
|
||||||
reID: object.new_registrar.code,
|
|
||||||
reDate: object.transfer_requested_at.try(:iso8601),
|
|
||||||
acID: object.old_registrar.code,
|
|
||||||
acDate: object.transferred_at.try(:iso8601) || object.wait_until.try(:iso8601),
|
|
||||||
exDate: object.domain_valid_to.iso8601,
|
|
||||||
}
|
|
||||||
when 'ContactUpdateAction'
|
|
||||||
{
|
|
||||||
contacts: object.to_non_available_contact_codes,
|
|
||||||
operation: object.operation,
|
|
||||||
opDate: object.created_at.utc.xmlschema,
|
|
||||||
svTrid: object.id,
|
|
||||||
who: object.user.username,
|
|
||||||
reason: 'Auto-update according to official data',
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,7 @@ class AdminDomainContact < DomainContact
|
||||||
skipped_domains = []
|
skipped_domains = []
|
||||||
admin_contacts = where(contact: current_contact)
|
admin_contacts = where(contact: current_contact)
|
||||||
|
|
||||||
admin_contacts.includes(:domain).each do |admin_contact|
|
admin_contacts.includes(:domain).find_each do |admin_contact|
|
||||||
if admin_contact.domain.bulk_update_prohibited?
|
if admin_contact.domain.bulk_update_prohibited?
|
||||||
skipped_domains << admin_contact.domain.name
|
skipped_domains << admin_contact.domain.name
|
||||||
next
|
next
|
||||||
|
|
|
@ -5,7 +5,7 @@ class TechDomainContact < DomainContact
|
||||||
skipped_domains = []
|
skipped_domains = []
|
||||||
tech_contacts = where(contact: current_contact)
|
tech_contacts = where(contact: current_contact)
|
||||||
|
|
||||||
tech_contacts.includes(:domain).each do |tech_contact|
|
tech_contacts.includes(:domain).find_each do |tech_contact|
|
||||||
if irreplaceable?(tech_contact)
|
if irreplaceable?(tech_contact)
|
||||||
skipped_domains << tech_contact.domain.name
|
skipped_domains << tech_contact.domain.name
|
||||||
next
|
next
|
||||||
|
|
|
@ -10,13 +10,15 @@ module Serializers
|
||||||
@simplify = options[:simplify] || false
|
@simplify = options[:simplify] || false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# rubocop:disable Metrics/MethodLength
|
||||||
|
# rubocop:disable Metrics/AbcSize
|
||||||
def to_json(obj = contact)
|
def to_json(obj = contact)
|
||||||
return simple_object if @simplify
|
return simple_object if @simplify
|
||||||
|
|
||||||
json = { id: obj.uuid, code: obj.code, name: obj.name, ident: ident,
|
json = { id: obj.uuid, code: obj.code, name: obj.name, ident: ident, phone: obj.phone,
|
||||||
email: obj.email, phone: obj.phone, created_at: obj.created_at,
|
created_at: obj.created_at, auth_info: obj.auth_info, email: obj.email,
|
||||||
auth_info: obj.auth_info, statuses: statuses,
|
statuses: statuses, disclosed_attributes: obj.disclosed_attributes,
|
||||||
disclosed_attributes: obj.disclosed_attributes, registrar: registrar }
|
registrar: registrar }
|
||||||
json[:address] = address if @show_address
|
json[:address] = address if @show_address
|
||||||
if @domain_params
|
if @domain_params
|
||||||
json[:domains] = domains
|
json[:domains] = domains
|
||||||
|
@ -24,6 +26,8 @@ module Serializers
|
||||||
end
|
end
|
||||||
json
|
json
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Metrics/MethodLength
|
||||||
|
# rubocop:enable Metrics/AbcSize
|
||||||
|
|
||||||
def registrar
|
def registrar
|
||||||
contact.registrar.as_json(only: %i[name website])
|
contact.registrar.as_json(only: %i[name website])
|
||||||
|
|
|
@ -9,6 +9,7 @@ module Serializers
|
||||||
@simplify = simplify
|
@simplify = simplify
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# rubocop:disable Metrics/MethodLength
|
||||||
# rubocop:disable Metrics/AbcSize
|
# rubocop:disable Metrics/AbcSize
|
||||||
def to_json(obj = domain)
|
def to_json(obj = domain)
|
||||||
return simple_object if @simplify
|
return simple_object if @simplify
|
||||||
|
@ -26,6 +27,7 @@ module Serializers
|
||||||
json[:transfer_code] = obj.auth_info if @sponsored
|
json[:transfer_code] = obj.auth_info if @sponsored
|
||||||
json
|
json
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Metrics/MethodLength
|
||||||
# rubocop:enable Metrics/AbcSize
|
# rubocop:enable Metrics/AbcSize
|
||||||
|
|
||||||
def contacts
|
def contacts
|
||||||
|
|
|
@ -8,6 +8,8 @@ module Serializers
|
||||||
@simplify = simplify
|
@simplify = simplify
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# rubocop:disable Metrics/MethodLength
|
||||||
|
# rubocop:disable Metrics/AbcSize
|
||||||
def to_json(obj = invoice)
|
def to_json(obj = invoice)
|
||||||
return simple_object if @simplify
|
return simple_object if @simplify
|
||||||
|
|
||||||
|
@ -29,16 +31,11 @@ module Serializers
|
||||||
|
|
||||||
def seller
|
def seller
|
||||||
{
|
{
|
||||||
name: invoice.seller_name,
|
name: invoice.seller_name, reg_no: invoice.seller_reg_no,
|
||||||
reg_no: invoice.seller_reg_no,
|
iban: invoice.seller_iban, bank: invoice.seller_bank,
|
||||||
iban: invoice.seller_iban,
|
swift: invoice.seller_swift, vat_no: invoice.seller_vat_no,
|
||||||
bank: invoice.seller_bank,
|
address: invoice.seller_address, country: invoice.seller_country.name,
|
||||||
swift: invoice.seller_swift,
|
phone: invoice.seller_phone, url: invoice.seller_url,
|
||||||
vat_no: invoice.seller_vat_no,
|
|
||||||
address: invoice.seller_address,
|
|
||||||
country: invoice.seller_country.name,
|
|
||||||
phone: invoice.seller_phone,
|
|
||||||
url: invoice.seller_url,
|
|
||||||
email: invoice.seller_email,
|
email: invoice.seller_email,
|
||||||
contact_name: invoice.seller_contact_name,
|
contact_name: invoice.seller_contact_name,
|
||||||
}
|
}
|
||||||
|
@ -80,6 +77,8 @@ module Serializers
|
||||||
recipient: invoice.buyer.billing_email,
|
recipient: invoice.buyer.billing_email,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Metrics/MethodLength
|
||||||
|
# rubocop:enable Metrics/AbcSize
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue