mirror of
https://github.com/internetee/registry.git
synced 2025-08-01 07:26:22 +02:00
Fixed codeclimate errors
This commit is contained in:
parent
a5ffce290d
commit
7c570e2916
12 changed files with 114 additions and 103 deletions
|
@ -11,33 +11,60 @@ module Repp
|
|||
if can?(:manage, :poll)
|
||||
user_notifications = user.unread_notifications
|
||||
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
|
||||
|
||||
data = serialize_data(registrar: registrar,
|
||||
notification: notification,
|
||||
notifications_count: notifications_count,
|
||||
object: object)
|
||||
render_success(data: serialize_data(registrar: registrar,
|
||||
notification: notification,
|
||||
notifications_count: user_notifications&.count,
|
||||
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
|
||||
|
||||
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)
|
||||
Object.const_get(object_type)
|
||||
rescue NameError
|
||||
|
@ -83,29 +110,9 @@ module Repp
|
|||
def serialized_object(object, obj_type)
|
||||
return unless object
|
||||
|
||||
case obj_type
|
||||
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
|
||||
try("serialized_#{obj_type.underscore}", object)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue