diff options
Diffstat (limited to 'app/controllers/profiles')
-rw-r--r-- | app/controllers/profiles/personal_access_tokens_controller.rb | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/app/controllers/profiles/personal_access_tokens_controller.rb b/app/controllers/profiles/personal_access_tokens_controller.rb index a7eca876c2f..2188350f2fd 100644 --- a/app/controllers/profiles/personal_access_tokens_controller.rb +++ b/app/controllers/profiles/personal_access_tokens_controller.rb @@ -1,10 +1,12 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController + before_action :finder + def index set_index_vars end def create - @personal_access_token = current_user.personal_access_tokens.build(personal_access_token_params) + @personal_access_token = finder.execute.build(personal_access_token_params) if @personal_access_token.save flash[:personal_access_token] = @personal_access_token.token @@ -16,7 +18,7 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController end def revoke - @personal_access_token = current_user.personal_access_tokens.find(params[:id]) + @personal_access_token = finder.execute(id: params[:id]) if @personal_access_token.revoke! flash[:notice] = "Revoked personal access token #{@personal_access_token.name}!" @@ -29,14 +31,21 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController private + def finder + @finder ||= PersonalAccessTokensFinder.new(user: current_user, impersonation: false) + end + def personal_access_token_params params.require(:personal_access_token).permit(:name, :expires_at, scopes: []) end def set_index_vars - @personal_access_token ||= current_user.personal_access_tokens.build + finder.params[:state] = 'active' + @personal_access_token ||= finder.execute.build @scopes = Gitlab::Auth::SCOPES - @active_personal_access_tokens = current_user.personal_access_tokens.active.order(:expires_at) - @inactive_personal_access_tokens = current_user.personal_access_tokens.inactive + finder.params[:order] = :expires_at + @active_personal_access_tokens = finder.execute + finder.params[:state] = 'inactive' + @inactive_personal_access_tokens = finder.execute end end |