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
97 98 99 100 101 |
# File 'app/models/concerns/audit_events/common_model.rb', line 97 def as_json( = {}) super().tap do |json| json['ip_address'] = ip_address.to_s end end |
#author ⇒ Object
85 86 87 |
# File 'app/models/concerns/audit_events/common_model.rb', line 85 def &.itself.presence || end |
#author_name ⇒ Object
75 76 77 |
# File 'app/models/concerns/audit_events/common_model.rb', line 75 def &.name end |
#entity_path ⇒ Object
115 116 117 |
# File 'app/models/concerns/audit_events/common_model.rb', line 115 def entity_path super || details[:entity_path] end |
#formatted_details ⇒ Object
79 80 81 82 83 |
# File 'app/models/concerns/audit_events/common_model.rb', line 79 def formatted_details details .merge(details.slice(:from, :to).transform_values(&:to_s)) .merge(author_email: .try(:email)) end |
#initialize_details ⇒ Object
69 70 71 72 73 |
# File 'app/models/concerns/audit_events/common_model.rb', line 69 def initialize_details return unless has_attribute?(:details) self.details = {} if details&.nil? end |
#ip_address ⇒ Object
119 120 121 |
# File 'app/models/concerns/audit_events/common_model.rb', line 119 def ip_address super&.to_s || details[:ip_address] end |
#lazy_author ⇒ Object
89 90 91 92 93 94 95 |
# File 'app/models/concerns/audit_events/common_model.rb', line 89 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
111 112 113 |
# File 'app/models/concerns/audit_events/common_model.rb', line 111 def target_details super || details[:target_details] end |
#target_id ⇒ Object
107 108 109 |
# File 'app/models/concerns/audit_events/common_model.rb', line 107 def target_id details[:target_id] end |
#target_type ⇒ Object
103 104 105 |
# File 'app/models/concerns/audit_events/common_model.rb', line 103 def target_type super || details[:target_type] end |