Class: CommandTower::Workflows::Audit::Events::ListForAdminWorkflow

Inherits:
CommandTower::Workflows::ApplicationWorkflow show all
Defined in:
app/workflows/command_tower/workflows/audit/events/list_for_admin_workflow.rb

Constant Summary

Constants inherited from CommandTower::Workflows::ApplicationWorkflow

CommandTower::Workflows::ApplicationWorkflow::ALLOWED_RETRY_STRATEGIES, CommandTower::Workflows::ApplicationWorkflow::InvalidTransactionResult, CommandTower::Workflows::ApplicationWorkflow::TransactionFailure

Instance Method Summary collapse

Methods inherited from CommandTower::Workflows::ApplicationWorkflow

call, call_from_job, continuation_max_attempts, declared_retry_strategy, mark_impersonation_activity!, retry_strategy, validate_retry_strategy!

Methods included from Impersonation::ActivityDeclaration

included

Methods included from Logging::LifecycleDeclaration

included

Methods included from Execution::ContextAccess

#audit, #execution_context, #log_debug, #log_error, #log_info, #log_warn, #publish_event

Methods included from Transactional

#fail_transaction!, #transaction

Instance Method Details

#call(limit:, offset:, user:, scope_value: nil, actions: nil, occurred_after: nil, occurred_before: nil, subject_types: nil, affected_user_id: nil, actor_user_id: nil, originating_administrator_id: nil, attribution_mode: nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/workflows/command_tower/workflows/audit/events/list_for_admin_workflow.rb', line 10

def call(
  limit:,
  offset:,
  user:,
  scope_value: nil,
  actions: nil,
  occurred_after: nil,
  occurred_before: nil,
  subject_types: nil,
  affected_user_id: nil,
  actor_user_id: nil,
  originating_administrator_id: nil,
  attribution_mode: nil
)
  scope_result = resolve_scope(user:, scope_value:)
  return scope_result if scope_result.is_a?(CommandTower::Workflows::WorkflowResult)

  listed = CommandTower::Services::Audit::Events::List.call(
    viewer_scope: :admin,
    limit:,
    offset:,
    actions:,
    occurred_after:,
    occurred_before:,
    subject_types:,
    affected_user_id:,
    actor_user_id:,
    originating_administrator_id:,
    attribution_mode:,
    principal: user,
    scope_context: scope_result
  )
  return result_or_failure(listed) unless listed.success?

  payload = listed.data[:events].filter_map do |event|
    projected = CommandTower::Services::Audit::Events::Project.call(event:, viewer: :admin)
    return result_or_failure(projected) unless projected.success?

    CommandTower::Serializers::Audit::Events::EventSerializer.serialize(projected.data[:projection])
  end
  meta = CommandTower::Serializers::Audit::Events::PaginationMetaSerializer.serialize(listed.data[:pagination])
  success(payload:, meta:, http_status: :ok)
end