Module: AuditEvents::CommonModel
- Extended by:
- ActiveSupport::Concern
- Included in:
- GroupAuditEvent, InstanceAuditEvent, ProjectAuditEvent, UserAuditEvent
- Defined in:
- app/models/concerns/audit_events/common_model.rb
Constant Summary collapse
- PARALLEL_PERSISTENCE_COLUMNS =
[ :author_name, :entity_path, :target_details, :target_type, :target_id ].freeze
- TRUNCATED_FIELDS =
{ entity_path: 5_500, target_details: 5_500 }.freeze
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #author ⇒ Object
- #author_name ⇒ Object
- #entity_path ⇒ Object
- #formatted_details ⇒ Object
- #initialize_details ⇒ Object
- #ip_address ⇒ Object
- #lazy_author ⇒ Object
- #target_details ⇒ Object
- #target_id ⇒ Object
- #target_type ⇒ Object
Instance Method Details
#as_json(options = {}) ⇒ Object
108 109 110 111 112 |
# File 'app/models/concerns/audit_events/common_model.rb', line 108 def as_json( = {}) super().tap do |json| json['ip_address'] = ip_address.to_s end end |
#author ⇒ Object
96 97 98 |
# File 'app/models/concerns/audit_events/common_model.rb', line 96 def &.itself.presence || end |
#author_name ⇒ Object
86 87 88 |
# File 'app/models/concerns/audit_events/common_model.rb', line 86 def &.name end |
#entity_path ⇒ Object
126 127 128 |
# File 'app/models/concerns/audit_events/common_model.rb', line 126 def entity_path super || details[:entity_path] end |
#formatted_details ⇒ Object
90 91 92 93 94 |
# File 'app/models/concerns/audit_events/common_model.rb', line 90 def formatted_details details .merge(details.slice(:from, :to).transform_values(&:to_s)) .merge(author_email: .try(:email)) end |
#initialize_details ⇒ Object
80 81 82 83 84 |
# File 'app/models/concerns/audit_events/common_model.rb', line 80 def initialize_details return unless has_attribute?(:details) self.details = {} if details&.nil? end |
#ip_address ⇒ Object
130 131 132 |
# File 'app/models/concerns/audit_events/common_model.rb', line 130 def ip_address super&.to_s || details[:ip_address] end |
#lazy_author ⇒ Object
100 101 102 103 104 105 106 |
# File 'app/models/concerns/audit_events/common_model.rb', line 100 def BatchLoader.for().batch do |, loader| User.select(:id, :name, :username, :email).where(id: ).find_each do |user| loader.call(user.id, user) end end end |
#target_details ⇒ Object
122 123 124 |
# File 'app/models/concerns/audit_events/common_model.rb', line 122 def target_details super || details[:target_details] end |
#target_id ⇒ Object
118 119 120 |
# File 'app/models/concerns/audit_events/common_model.rb', line 118 def target_id details[:target_id] end |
#target_type ⇒ Object
114 115 116 |
# File 'app/models/concerns/audit_events/common_model.rb', line 114 def target_type super || details[:target_type] end |