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



31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/concerns/access_tokens_actions.rb', line 31

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

#indexObject

rubocop:disable Gitlab/ModuleWithInstanceVariables



17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/concerns/access_tokens_actions.rb', line 17

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



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

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



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

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