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

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

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

@ -2,8 +2,6 @@ class ContactVersion < PaperTrail::Version
include VersionSession
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