2016-06-22 15:30:34 +05:30
|
|
|
class Profiles::PersonalAccessTokensController < Profiles::ApplicationController
|
|
|
|
def index
|
2017-08-17 22:00:37 +05:30
|
|
|
set_index_vars
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2017-08-17 22:00:37 +05:30
|
|
|
@personal_access_token = finder.build(personal_access_token_params)
|
2016-06-22 15:30:34 +05:30
|
|
|
|
|
|
|
if @personal_access_token.save
|
|
|
|
flash[:personal_access_token] = @personal_access_token.token
|
|
|
|
redirect_to profile_personal_access_tokens_path, notice: "Your new personal access token has been created."
|
|
|
|
else
|
2017-08-17 22:00:37 +05:30
|
|
|
set_index_vars
|
2016-06-22 15:30:34 +05:30
|
|
|
render :index
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def revoke
|
2017-08-17 22:00:37 +05:30
|
|
|
@personal_access_token = finder.find(params[:id])
|
2016-06-22 15:30:34 +05:30
|
|
|
|
|
|
|
if @personal_access_token.revoke!
|
|
|
|
flash[:notice] = "Revoked personal access token #{@personal_access_token.name}!"
|
|
|
|
else
|
|
|
|
flash[:alert] = "Could not revoke personal access token #{@personal_access_token.name}."
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to profile_personal_access_tokens_path
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def finder(options = {})
|
|
|
|
PersonalAccessTokensFinder.new({ user: current_user, impersonation: false }.merge(options))
|
|
|
|
end
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
def personal_access_token_params
|
2017-08-17 22:00:37 +05:30
|
|
|
params.require(:personal_access_token).permit(:name, :expires_at, scopes: [])
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def set_index_vars
|
2017-09-10 17:25:29 +05:30
|
|
|
@scopes = Gitlab::Auth::AVAILABLE_SCOPES
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
@personal_access_token = finder.build
|
|
|
|
@inactive_personal_access_tokens = finder(state: 'inactive').execute
|
|
|
|
@active_personal_access_tokens = finder(state: 'active').execute.order(:expires_at)
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
end
|