Module: AccessTokensActions

Extended by:
ActiveSupport::Concern
Included in:
Groups::Settings::AccessTokensController, Projects::Settings::AccessTokensController
Defined in:
app/controllers/concerns/access_tokens_actions.rb

Instance Method Summary collapse

Instance Method Details

#createObject

rubocop:disable Gitlab/ModuleWithInstanceVariables



28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/concerns/access_tokens_actions.rb', line 28

def create
  token_response = ResourceAccessTokens::CreateService.new(current_user, resource, create_params).execute

  if token_response.success?
    @resource_access_token = token_response.payload[:access_token]
    tokens, size = active_access_tokens
    render json: { new_token: @resource_access_token.token,
                   active_access_tokens: tokens, total: size }, status: :ok
  else
    render json: { errors: token_response.errors }, status: :unprocessable_entity
  end
end

#inactiveObject



73
74
75
76
77
78
# File 'app/controllers/concerns/access_tokens_actions.rb', line 73

def inactive
  tokens = inactive_access_tokens.page(page)
  add_pagination_headers(tokens)

  render json: represent(tokens)
end

#indexObject

rubocop:disable Gitlab/ModuleWithInstanceVariables



14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/concerns/access_tokens_actions.rb', line 14

def index
  @resource_access_token = PersonalAccessToken.new
  set_index_vars

  respond_to do |format|
    format.html
    format.json do
      render json: @active_access_tokens
    end
  end
end

#revokeObject

rubocop:disable Gitlab/ModuleWithInstanceVariables



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/concerns/access_tokens_actions.rb', line 43

def revoke
  @resource_access_token = finder.find(params[:id])
  revoked_response = ResourceAccessTokens::RevokeService.new(current_user, resource, @resource_access_token).execute

  if revoked_response.success?
    flash[:notice] =
      format(_("Revoked access token %{access_token_name}!"), access_token_name: @resource_access_token.name)
  else
    flash[:alert] =
      format(_("Could not revoke access token %{access_token_name}."), access_token_name: @resource_access_token.name)
  end

  redirect_to resource_access_tokens_path
end

#rotateObject

rubocop:enable Gitlab/ModuleWithInstanceVariables



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/concerns/access_tokens_actions.rb', line 59

def rotate
  token = finder.find(rotate_params[:id])
  result = rotate_service.new(current_user, token, resource, keep_token_lifetime: true).execute
  resource_access_token = result.payload[:personal_access_token]

  if result.success?
    tokens, size = active_access_tokens
    render json: { new_token: resource_access_token.token,
                   active_access_tokens: tokens, total: size }, status: :ok
  else
    render json: { message: result.message }, status: :unprocessable_entity
  end
end