summaryrefslogtreecommitdiff
path: root/app/models/audit_event.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/audit_event.rb')
-rw-r--r--app/models/audit_event.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/app/models/audit_event.rb b/app/models/audit_event.rb
index c2eef500fb0..06a607b75a4 100644
--- a/app/models/audit_event.rb
+++ b/app/models/audit_event.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true
class AuditEvent < ApplicationRecord
+ include CreatedAtFilterable
+
serialize :details, Hash # rubocop:disable Cop/ActiveRecordSerialize
belongs_to :user, foreign_key: :author_id
@@ -9,6 +11,9 @@ class AuditEvent < ApplicationRecord
validates :entity_id, presence: true
validates :entity_type, presence: true
+ scope :by_entity_type, -> (entity_type) { where(entity_type: entity_type) }
+ scope :by_entity_id, -> (entity_id) { where(entity_id: entity_id) }
+
after_initialize :initialize_details
def initialize_details
@@ -18,6 +23,10 @@ class AuditEvent < ApplicationRecord
def author_name
self.user.name
end
+
+ def formatted_details
+ details.merge(details.slice(:from, :to).transform_values(&:to_s))
+ end
end
AuditEvent.prepend_if_ee('EE::AuditEvent')