Unified contact and domain versions under client

This commit is contained in:
Andres Keskküla 2014-10-03 16:23:18 +03:00
parent 582fd59090
commit 871e289973
4 changed files with 6 additions and 29 deletions

View file

@ -2,7 +2,7 @@ class Client::ContactVersionsController < ClientController
before_action :set_version, only: [:show] before_action :set_version, only: [:show]
def index def index
@versions = ContactVersion.registrar_events(current_user.registrar.id) @versions = ContactVersion.registrar_events(current_registrar.id)
@versions.flatten! @versions.flatten!
end end

View file

@ -2,7 +2,7 @@ class Client::DomainVersionsController < ClientController
before_action :set_version, only: [:show] before_action :set_version, only: [:show]
def index def index
@versions = DomainVersion.registrar_events(current_user.registrar.id) @versions = DomainVersion.registrar_events(current_registrar.id)
@versions.flatten! @versions.flatten!
end end

View file

@ -4,10 +4,10 @@ module UserEvents
module ClassMethods module ClassMethods
def registrar_events(id) def registrar_events(id)
registrar = Registrar.find(id) registrar = Registrar.find(id)
return nil unless registrar return [] unless registrar
@events = [] @events = []
registrar.users.each { |user| @events << user_events(user.id) } registrar.users.each { |user| @events << user_events(user.id) }
registrar.epp_users.each { |user| @events << user_events(user.id) } registrar.epp_users.each { |user| @events << epp_user_events(user.id) }
@events @events
end end

View file

@ -1,32 +1,9 @@
class ContactVersion < PaperTrail::Version class ContactVersion < PaperTrail::Version
include UserEvents
scope :deleted, -> { where(event: 'destroy') } scope :deleted, -> { where(event: 'destroy') }
self.table_name = :contact_versions self.table_name = :contact_versions
self.sequence_name = :contact_version_id_seq self.sequence_name = :contact_version_id_seq
class << self
def registrar_events(id)
registrar = Registrar.find(id)
@events = []
registrar.users.each { |user| @events << user_contacts(user.id) }
registrar.epp_users.each { |user| @events << user_contacts(user.id) }
@events
end
def user_events(id, epp_user_id=nil)
contacts = []
contacts << user_contacts(id)
contacts << epp_user_contacts(epp_user_id) if epp_user_id
contacts
end
def user_contacts(id)
where(whodunnit: id.to_s)
end
def epp_user_contacts(id)
where(whodunnit: "#{id}-EppUser")
end
end
end end