Class: CommandTower::AdminController

Inherits:
ApplicationController show all
Includes:
PaginationHelper, SchemaHelper
Defined in:
app/controllers/command_tower/admin_controller.rb

Constant Summary

Constants inherited from ApplicationController

CommandTower::ApplicationController::AUTHENTICATION_EXPIRE_HEADER, CommandTower::ApplicationController::AUTHENTICATION_HEADER, CommandTower::ApplicationController::AUTHENTICATION_WITH_RESET

Instance Method Summary collapse

Methods included from PaginationHelper

#pagination_from_body, #pagination_from_query, #pagination_safe_integer_convert, #pagination_values

Methods included from SchemaHelper

#invalid_arguments!, #schema_succesful!

Methods inherited from ApplicationController

#authenticate_user!, #authenticate_user_without_email_verification!, #authorize_user!, #current_user, #safe_boolean

Instance Method Details

#impersonateObject



64
65
66
# File 'app/controllers/command_tower/admin_controller.rb', line 64

def impersonate
  # TODO: @matt-taylor
end

#modifyObject

POST: /modify



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/command_tower/admin_controller.rb', line 23

def modify
  result = CommandTower::UserAttributes::Modify.(user:, admin_user:, **modify_params)
  if result.success?
    schema = CommandTower::Schema::User.convert_user_object(user: user.reload)
    status = 201
    schema_succesful!(status:, schema:)
  else
    if result.invalid_arguments
      invalid_arguments!(
        status: 400,
        message: result.msg,
        argument_object: result.invalid_argument_hash,
        schema: CommandTower::Schema::PlainText::LoginRequest
      )
    else
      server_error!(result:)
    end
  end
end

#modify_roleObject

POST: /modify/role



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/command_tower/admin_controller.rb', line 44

def modify_role
  result = CommandTower::UserAttributes::Roles.(user:, admin_user:, roles: params[:roles] || [])
  if result.success?
    schema = CommandTower::Schema::User.convert_user_object(user: user.reload)
    status = 201
    schema_succesful!(status:, schema:)
  else
    if result.invalid_arguments
      invalid_arguments!(
        status: 400,
        message: result.msg,
        argument_object: result.invalid_argument_hash,
        schema: CommandTower::Schema::PlainText::LoginRequest
      )
    else
      server_error!(result:)
    end
  end
end

#showObject

GET: /admin Pagination Available



14
15
16
17
18
19
20
# File 'app/controllers/command_tower/admin_controller.rb', line 14

def show
  schema = CommandTower::AdminService::Users.(
    user: admin_user,
    pagination: pagination_values,
  ).schema
  schema_succesful!(status: 200, schema:)
end