mirror of
https://github.com/internetee/registry.git
synced 2025-05-18 02:09:39 +02:00
Merge pull request #38 from internetee/109367694-epp-id-conventions
109367694 epp id conventions
This commit is contained in:
commit
1e94909c41
11 changed files with 66 additions and 56 deletions
|
@ -67,8 +67,7 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def user_log_str(user)
|
||||
return 'public' if user.nil?
|
||||
"#{user.id}-#{user.class}: #{user.username}"
|
||||
user.nil? ? 'public' : user.id_role_username
|
||||
end
|
||||
|
||||
def comma_support_for(parent_key, key)
|
||||
|
|
|
@ -1,23 +1,30 @@
|
|||
module UserEvents
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
# TODO: remove old
|
||||
# module ClassMethods
|
||||
# def registrar_events(id)
|
||||
# registrar = Registrar.find(id)
|
||||
# return [] unless registrar
|
||||
# @events = []
|
||||
# registrar.users.each { |user| @events << user_events(user.id) }
|
||||
# registrar.epp_users.each { |user| @events << epp_user_events(user.id) }
|
||||
# @events
|
||||
# end
|
||||
included do
|
||||
# EPP requires a server defined creator ID, which should be registrar code if we have one
|
||||
def cr_id
|
||||
# try this, rebuild user for registrar before searching history? really?
|
||||
registrar = self.creator.try(:registrar)
|
||||
if registrar.present? # Did creator return a kind of User that has a registrar?
|
||||
registrar.code
|
||||
else
|
||||
if self.versions.first.try(:object).nil?
|
||||
changes = self.versions.first.try(:object_changes)
|
||||
cr_registrar_id = changes['registrar_id'].second if changes.present?
|
||||
else
|
||||
# untested, expected never to execute
|
||||
cr_registrar_id = self.versions.first.object['registrar_id']
|
||||
end
|
||||
|
||||
# def user_events(id)
|
||||
# where(whodunnit: id.to_s)
|
||||
# end
|
||||
if cr_registrar_id.present?
|
||||
Registrar.find(cr_registrar_id).code
|
||||
else
|
||||
# cr_id optional for domain, but required for contact; but we want something here anyway
|
||||
self.creator_str # Fallback if we failed, maybe we can find a string here
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# def epp_user_events(id)
|
||||
# where(whodunnit: "#{id}-EppUser")
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
|
|
@ -22,32 +22,30 @@ module Versions
|
|||
|
||||
def creator
|
||||
return nil if creator_str.blank?
|
||||
|
||||
if creator_str =~ /^\d+-AdminUser:/
|
||||
creator = AdminUser.find_by(id: creator_str)
|
||||
elsif creator_str =~ /^\d+-ApiUser:/
|
||||
creator = ApiUser.find_by(id: creator_str)
|
||||
elsif creator_str =~ /^\d+-api-/ # depricated
|
||||
creator = ApiUser.find_by(id: creator_str)
|
||||
end
|
||||
|
||||
creator = user_from_id_role_username creator_str
|
||||
creator.present? ? creator : creator_str
|
||||
end
|
||||
|
||||
def updator
|
||||
return nil if updator_str.blank?
|
||||
|
||||
if updator_str =~ /^\d+-AdminUser:/
|
||||
updator = AdminUser.find_by(id: updator_str)
|
||||
elsif updator_str =~ /^\d+-ApiUser:/
|
||||
updator = ApiUser.find_by(id: updator_str)
|
||||
elsif updator_str =~ /^\d+-api-/ # depricated
|
||||
updator = ApiUser.find_by(id: updator_str)
|
||||
end
|
||||
|
||||
updator = user_from_id_role_username updator_str
|
||||
updator.present? ? updator : updator_str
|
||||
end
|
||||
|
||||
def user_from_id_role_username(str)
|
||||
user = ApiUser.find_by(id: $1) if str =~ /^(\d+)-(ApiUser:|api-)/
|
||||
unless user.present?
|
||||
user = AdminUser.find_by(id: $1) if str =~ /^(\d+)-AdminUser:/
|
||||
unless user.present?
|
||||
# on import we copied Registrar name, which may eql code
|
||||
registrar = Registrar.find_by(name: str)
|
||||
# assume each registrar has only one user
|
||||
user = registrar.api_users.first if registrar
|
||||
end
|
||||
end
|
||||
user
|
||||
end
|
||||
|
||||
# callbacks
|
||||
def touch_domain_version
|
||||
domain.try(:touch_with_version)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class Contact < ActiveRecord::Base
|
||||
include Versions # version/contact_version.rb
|
||||
include EppErrors
|
||||
include UserEvents
|
||||
|
||||
belongs_to :registrar
|
||||
has_many :domain_contacts
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# rubocop: disable Metrics/ClassLength
|
||||
class Domain < ActiveRecord::Base
|
||||
include UserEvents
|
||||
include Versions # version/domain_version.rb
|
||||
include Statuses
|
||||
has_paper_trail class_name: "DomainVersion", meta: { children: :children_log }
|
||||
|
|
|
@ -506,7 +506,9 @@ class Epp::Domain < Domain
|
|||
frame = Nokogiri::XML(pending_json['frame'])
|
||||
statuses.delete(DomainStatus::PENDING_UPDATE)
|
||||
yield(self) if block_given? # need to skip statuses check here
|
||||
self.save
|
||||
|
||||
::PaperTrail.whodunnit = user.id_role_username # updator str should be the request originator not the approval user
|
||||
return unless update(frame, user, false)
|
||||
clean_pendings!
|
||||
self.deliver_emails = true # turn on email delivery
|
||||
|
|
|
@ -3,4 +3,9 @@ class User < ActiveRecord::Base
|
|||
devise :trackable, :timeoutable
|
||||
|
||||
attr_accessor :phone
|
||||
|
||||
def id_role_username
|
||||
"#{self.id}-#{self.class}: #{self.username}"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -3,7 +3,5 @@ class ContactVersion < PaperTrail::Version
|
|||
self.table_name = :log_contacts
|
||||
self.sequence_name = :log_contacts_id_seq
|
||||
|
||||
# include UserEvents
|
||||
|
||||
# scope :deleted, -> { where(event: 'destroy') }
|
||||
end
|
||||
|
|
|
@ -4,7 +4,5 @@ class DomainVersion < PaperTrail::Version
|
|||
self.table_name = :log_domains
|
||||
self.sequence_name = :log_domains_id_seq
|
||||
|
||||
include UserEvents
|
||||
|
||||
scope :deleted, -> { where(event: 'destroy') }
|
||||
end
|
||||
|
|
|
@ -46,15 +46,15 @@ xml.epp_head do
|
|||
xml.tag!('contact:email', 'No access')
|
||||
end
|
||||
|
||||
xml.tag!('contact:clID', @contact.registrar.try(:name))
|
||||
if @contact.creator.try(:registrar).blank? && Rails.env.test?
|
||||
xml.tag!('contact:crID', 'TEST-CREATOR')
|
||||
else
|
||||
xml.tag!('contact:crID', @contact.creator.try(:registrar))
|
||||
end
|
||||
xml.tag!('contact:clID', @contact.registrar.try(:code))
|
||||
|
||||
xml.tag!('contact:crID', @contact.cr_id)
|
||||
xml.tag!('contact:crDate', @contact.created_at.try(:iso8601))
|
||||
|
||||
if @contact.updated_at != @contact.created_at
|
||||
xml.tag!('contact:upID', @contact.updator.try(:registrar))
|
||||
upID = @contact.updator.try(:registrar)
|
||||
upID = upID.code if upID.present? # Did updator return a kind of User that has a registrar?
|
||||
xml.tag!('contact:upID', upID) if upID.present? # optional upID
|
||||
xml.tag!('contact:upDate', @contact.updated_at.try(:iso8601))
|
||||
end
|
||||
# xml.tag!('contact:trDate', '123') if false
|
||||
|
|
|
@ -36,19 +36,20 @@ xml.epp_head do
|
|||
|
||||
## TODO Find out what this domain:host is all about
|
||||
|
||||
xml.tag!('domain:clID', @domain.registrar_name)
|
||||
|
||||
xml.tag!('domain:crID', @domain.creator.try(:registrar)) if @domain.creator
|
||||
xml.tag!('domain:clID', @domain.registrar.code)
|
||||
|
||||
xml.tag!('domain:crID', @domain.cr_id)
|
||||
xml.tag!('domain:crDate', @domain.created_at.try(:iso8601))
|
||||
|
||||
xml.tag!('domain:upDate', @domain.updated_at.try(:iso8601)) if @domain.updated_at != @domain.created_at
|
||||
if @domain.updated_at != @domain.created_at
|
||||
upID = @domain.updator.try(:registrar)
|
||||
upID = upID.code if upID.present? # Did updator return a kind of User that has a registrar?
|
||||
xml.tag!('domain:upID', upID) if upID.present? # optional upID
|
||||
xml.tag!('domain:upDate', @domain.updated_at.try(:iso8601))
|
||||
end
|
||||
|
||||
xml.tag!('domain:exDate', @domain.valid_to.try(:iso8601))
|
||||
|
||||
# TODO Make domain stampable
|
||||
#xml.tag!('domain:upID', @domain.updated_by)
|
||||
|
||||
# TODO Make domain transferrable
|
||||
#xml.tag!('domain:trDate', @domain.transferred_at) if @domain.transferred_at
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue