2018-07-25 05:30:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-28 09:17:42 -04:00
|
|
|
class AuditEvent < ApplicationRecord
|
2019-09-26 05:06:04 -04:00
|
|
|
include CreatedAtFilterable
|
|
|
|
|
2017-07-03 10:01:41 -04:00
|
|
|
serialize :details, Hash # rubocop:disable Cop/ActiveRecordSerialize
|
2015-07-03 07:54:50 -04:00
|
|
|
|
|
|
|
belongs_to :user, foreign_key: :author_id
|
|
|
|
|
|
|
|
validates :author_id, presence: true
|
|
|
|
validates :entity_id, presence: true
|
|
|
|
validates :entity_type, presence: true
|
|
|
|
|
2019-09-26 05:06:04 -04:00
|
|
|
scope :by_entity_type, -> (entity_type) { where(entity_type: entity_type) }
|
|
|
|
scope :by_entity_id, -> (entity_id) { where(entity_id: entity_id) }
|
|
|
|
|
2015-07-03 07:54:50 -04:00
|
|
|
after_initialize :initialize_details
|
|
|
|
|
|
|
|
def initialize_details
|
|
|
|
self.details = {} if details.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
def author_name
|
|
|
|
self.user.name
|
|
|
|
end
|
2019-09-26 05:06:04 -04:00
|
|
|
|
|
|
|
def formatted_details
|
|
|
|
details.merge(details.slice(:from, :to).transform_values(&:to_s))
|
|
|
|
end
|
2015-07-03 07:54:50 -04:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
AuditEvent.prepend_if_ee('EE::AuditEvent')
|