Merge pull request #38 from internetee/109367694-epp-id-conventions

109367694 epp id conventions
This commit is contained in:
Timo Võhmar 2015-12-15 15:10:39 +02:00
commit 1e94909c41
11 changed files with 66 additions and 56 deletions

View file

@ -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)

View file

@ -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

View file

@ -22,30 +22,28 @@ 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)
updator = user_from_id_role_username updator_str
updator.present? ? updator : updator_str
end
updator.present? ? updator : updator_str
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

View file

@ -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

View file

@ -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 }

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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