summaryrefslogtreecommitdiff
path: root/app/models/audit_event.rb
blob: c2eef500fb08a224446d5822c76844e46347cdca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true

class AuditEvent < ApplicationRecord
  serialize :details, Hash # rubocop:disable Cop/ActiveRecordSerialize

  belongs_to :user, foreign_key: :author_id

  validates :author_id, presence: true
  validates :entity_id, presence: true
  validates :entity_type, presence: true

  after_initialize :initialize_details

  def initialize_details
    self.details = {} if details.nil?
  end

  def author_name
    self.user.name
  end
end

AuditEvent.prepend_if_ee('EE::AuditEvent')