Class: AuditEvent

Inherits:
ApplicationRecord show all
Includes:
BulkInsertSafe, CreatedAtFilterable, IgnorableColumns
Defined in:
app/models/audit_event.rb

Constant Summary collapse

PARALLEL_PERSISTENCE_COLUMNS =
[:author_name, :entity_path, :target_details, :target_type].freeze

Constants included from BulkInsertSafe

BulkInsertSafe::ALLOWED_CALLBACKS, BulkInsertSafe::DEFAULT_BATCH_SIZE, BulkInsertSafe::MethodNotAllowedError, BulkInsertSafe::PrimaryKeySetError

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

Class Method Details

.inheritance_columnObject

Note: After loading records, do not attempt to type cast objects it finds. We are in the process of deprecating STI (i.e. SecurityEvent) out of AuditEvent.

gitlab.com/gitlab-org/gitlab/-/issues/216845


36
37
38
# File 'app/models/audit_event.rb', line 36

def self.inheritance_column
  :_type_disabled
end

.order_by(method) ⇒ Object


40
41
42
43
44
45
46
47
# File 'app/models/audit_event.rb', line 40

def self.order_by(method)
  case method.to_s
  when 'created_asc'
    order(id: :asc)
  else
    order(id: :desc)
  end
end

Instance Method Details

#as_json(options = {}) ⇒ Object


69
70
71
72
73
# File 'app/models/audit_event.rb', line 69

def as_json(options = {})
  super(options).tap do |json|
    json['ip_address'] = self.ip_address.to_s
  end
end

#author_nameObject


53
54
55
# File 'app/models/audit_event.rb', line 53

def author_name
  lazy_author.name
end

#formatted_detailsObject


57
58
59
# File 'app/models/audit_event.rb', line 57

def formatted_details
  details.merge(details.slice(:from, :to).transform_values(&:to_s))
end

#initialize_detailsObject


49
50
51
# File 'app/models/audit_event.rb', line 49

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

#lazy_authorObject


61
62
63
64
65
66
67
# File 'app/models/audit_event.rb', line 61

def lazy_author
  BatchLoader.for(author_id).batch(default_value: default_author_value) do |author_ids, loader|
    User.where(id: author_ids).find_each do |user|
      loader.call(user.id, user)
    end
  end
end