2017-02-23 12:47:06 -05:00
|
|
|
class Admin::ImpersonationTokensController < Admin::ApplicationController
|
2017-02-27 13:56:54 -05:00
|
|
|
before_action :user, :finder
|
2017-02-23 12:47:06 -05:00
|
|
|
|
|
|
|
def index
|
|
|
|
set_index_vars
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2017-02-27 13:56:54 -05:00
|
|
|
@impersonation_token = finder.execute.build(impersonation_token_params)
|
2017-02-23 12:47:06 -05:00
|
|
|
|
|
|
|
if @impersonation_token.save
|
|
|
|
flash[:impersonation_token] = @impersonation_token.token
|
|
|
|
redirect_to admin_user_impersonation_tokens_path, notice: "A new impersonation token has been created."
|
|
|
|
else
|
|
|
|
set_index_vars
|
|
|
|
render :index
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def revoke
|
2017-02-27 13:56:54 -05:00
|
|
|
@impersonation_token = finder.execute(id: params[:id])
|
2017-02-23 12:47:06 -05:00
|
|
|
|
|
|
|
if @impersonation_token.revoke!
|
|
|
|
flash[:notice] = "Revoked impersonation token #{@impersonation_token.name}!"
|
|
|
|
else
|
|
|
|
flash[:alert] = "Could not revoke impersonation token #{@impersonation_token.name}."
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to admin_user_impersonation_tokens_path
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def user
|
|
|
|
@user ||= User.find_by!(username: params[:user_id])
|
|
|
|
end
|
|
|
|
|
2017-02-27 13:56:54 -05:00
|
|
|
def finder
|
|
|
|
@finder ||= PersonalAccessTokensFinder.new(user: user, impersonation: true)
|
|
|
|
end
|
|
|
|
|
2017-02-23 12:47:06 -05:00
|
|
|
def impersonation_token_params
|
|
|
|
params.require(:personal_access_token).permit(:name, :expires_at, :impersonation, scopes: [])
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_index_vars
|
2017-02-27 13:56:54 -05:00
|
|
|
finder.params[:state] = 'active'
|
|
|
|
@impersonation_token ||= finder.execute.build
|
2017-02-23 12:47:06 -05:00
|
|
|
@scopes = Gitlab::Auth::SCOPES
|
2017-02-27 13:56:54 -05:00
|
|
|
finder.params[:order] = :expires_at
|
|
|
|
@active_impersonation_tokens = finder.execute
|
|
|
|
finder.params[:state] = 'inactive'
|
|
|
|
@inactive_impersonation_tokens = finder.execute
|
2017-02-23 12:47:06 -05:00
|
|
|
end
|
|
|
|
end
|