Class: Skadi::Event

Inherits:
ApplicationRecord show all
Defined in:
app/models/skadi/event.rb

Class Method Summary collapse

Class Method Details

.redact_and_insert(events, view:, visit:) ⇒ Object

Redacts events that are marked as sensitive



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/skadi/event.rb', line 9

def self.redact_and_insert(events, view:, visit:)
  events.each do |event|
    # Note: both paths must have the same set of keys, which is a requirement for upsert_all
    if event[:sensitive]
      event[:view_id] = nil
      event[:visit_id] = nil

      # Sensitive events should have their created date redacted so they cannot be linked to views/visits based on timings
      event[:created_at] = Time.current.beginning_of_day
    else
      # Attach events to the current visit and view, only if it is not marked as sensitive
      event[:view_id] = view.id
      event[:visit_id] = visit&.id
      event[:created_at] = Time.current
    end

    event[:name] = event[:name].strip[0, 255]

    event.delete(:sensitive)
  end

  Event.insert_all(events)
end