2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
class AuditEvent < ApplicationRecord
|
2019-12-21 20:55:43 +05:30
|
|
|
include CreatedAtFilterable
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
serialize :details, Hash # rubocop:disable Cop/ActiveRecordSerialize
|
2015-09-11 14:41:01 +05:30
|
|
|
|
|
|
|
belongs_to :user, foreign_key: :author_id
|
|
|
|
|
|
|
|
validates :author_id, presence: true
|
|
|
|
validates :entity_id, presence: true
|
|
|
|
validates :entity_type, presence: true
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
scope :by_entity_type, -> (entity_type) { where(entity_type: entity_type) }
|
|
|
|
scope :by_entity_id, -> (entity_id) { where(entity_id: entity_id) }
|
2020-03-09 13:42:32 +05:30
|
|
|
scope :order_by_id_desc, -> { order(id: :desc) }
|
|
|
|
scope :order_by_id_asc, -> { order(id: :asc) }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
after_initialize :initialize_details
|
|
|
|
|
|
|
|
def initialize_details
|
|
|
|
self.details = {} if details.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
def author_name
|
|
|
|
self.user.name
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
def formatted_details
|
|
|
|
details.merge(details.slice(:from, :to).transform_values(&:to_s))
|
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
AuditEvent.prepend_if_ee('EE::AuditEvent')
|