mirror of
https://github.com/internetee/registry.git
synced 2025-07-30 14:36:22 +02:00
Updated REPP API for new registrar portal
This commit is contained in:
parent
e17b21436d
commit
a5ffce290d
61 changed files with 1269 additions and 408 deletions
111
app/controllers/repp/v1/registrar/summary_controller.rb
Normal file
111
app/controllers/repp/v1/registrar/summary_controller.rb
Normal file
|
@ -0,0 +1,111 @@
|
|||
module Repp
|
||||
module V1
|
||||
module Registrar
|
||||
class SummaryController < BaseController
|
||||
api :GET, 'repp/v1/registrar/summary'
|
||||
desc 'check user summary info and return data'
|
||||
|
||||
def index
|
||||
user = current_user
|
||||
registrar = user.registrar
|
||||
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: data)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def object_by_type(object_type)
|
||||
Object.const_get(object_type)
|
||||
rescue NameError
|
||||
Object.const_get("Version::#{object_type}")
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def serialize_data(registrar:, notification:, notifications_count:, object: nil)
|
||||
data = current_user.as_json(only: %i[id username])
|
||||
data[:registrar_name] = registrar.name
|
||||
data[:registrar_reg_no] = registrar.reg_no
|
||||
data[:last_login_date] = last_login_date
|
||||
data[:domains] = registrar.domains.count if can? :view, Depp::Domain
|
||||
data[:contacts] = registrar.contacts.count if can? :view, Depp::Contact
|
||||
data[:phone] = registrar.phone
|
||||
data[:email] = registrar.email
|
||||
data[:billing_email] = registrar.billing_email
|
||||
data[:billing_address] = registrar.address
|
||||
data[:notification] = serialized_notification(notification, object)
|
||||
data[:notifications_count] = notifications_count
|
||||
data
|
||||
end
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
|
||||
def last_login_date
|
||||
q = ApiLog::ReppLog.ransack({ request_path_eq: '/repp/v1/registrar/auth',
|
||||
response_code_eq: '200',
|
||||
api_user_name_cont: current_user.username,
|
||||
request_method_eq: 'GET' })
|
||||
q.sorts = 'id desc'
|
||||
q.result.offset(1).first&.created_at
|
||||
end
|
||||
|
||||
def serialized_notification(notification, object)
|
||||
return unless notification
|
||||
|
||||
notification.created_at = notification.created_at.utc.xmlschema
|
||||
obj_data = serialized_object(object, notification.attached_obj_type)
|
||||
notification.as_json(only: %i[id text created_at attached_obj_id attached_obj_type])
|
||||
.merge({ attached_obj_data: obj_data })
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue