Class: CommandTower::SharedSequences::Admin::Users::ResolveScopedUser

Inherits:
Object
  • Object
show all
Defined in:
app/shared_sequences/command_tower/shared_sequences/admin/users/resolve_scoped_user.rb

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(id:, principal:, scope_value: nil) ⇒ Object



10
11
12
# File 'app/shared_sequences/command_tower/shared_sequences/admin/users/resolve_scoped_user.rb', line 10

def self.call(id:, principal:, scope_value: nil)
  new.call(id:, principal:, scope_value:)
end

Instance Method Details

#call(id:, principal:, scope_value: nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/shared_sequences/command_tower/shared_sequences/admin/users/resolve_scoped_user.rb', line 14

def call(id:, principal:, scope_value: nil)
  scope_result = CommandTower::Workflows::Admin::ScopeResolution.resolve(
    tool_id: "users",
    user: principal,
    scope_value:
  )
  return scope_result if scope_result.is_a?(CommandTower::Workflows::WorkflowResult)

  shown = CommandTower::Services::Admin::Users::Show.call(
    id:,
    principal:,
    scope_context: scope_result
  )
  unless shown.success?
    return CommandTower::Workflows::WorkflowResult.failure(
      errors: shown.errors,
      http_status: CommandTower::Workflows::Admin::Users::ErrorMapping.http_status_for(
        shown.errors.first
      )
    )
  end

  Result.new(user: shown.data[:user])
end