summaryrefslogtreecommitdiff
path: root/app/controllers/admin/impersonation_tokens_controller.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-10-20 09:40:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-10-20 09:40:42 +0000
commitee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch)
treef8479f94a28f66654c6a4f6fb99bad6b4e86a40e /app/controllers/admin/impersonation_tokens_controller.rb
parent62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff)
downloadgitlab-ce-ee664acb356f8123f4f6b00b73c1e1cf0866c7fb.tar.gz
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'app/controllers/admin/impersonation_tokens_controller.rb')
-rw-r--r--app/controllers/admin/impersonation_tokens_controller.rb19
1 files changed, 9 insertions, 10 deletions
diff --git a/app/controllers/admin/impersonation_tokens_controller.rb b/app/controllers/admin/impersonation_tokens_controller.rb
index eb279298baf..9d884478e98 100644
--- a/app/controllers/admin/impersonation_tokens_controller.rb
+++ b/app/controllers/admin/impersonation_tokens_controller.rb
@@ -14,11 +14,10 @@ class Admin::ImpersonationTokensController < Admin::ApplicationController
@impersonation_token = finder.build(impersonation_token_params)
if @impersonation_token.save
- PersonalAccessToken.redis_store!(current_user.id, @impersonation_token.token)
- redirect_to admin_user_impersonation_tokens_path, notice: _("A new impersonation token has been created.")
+ render json: { new_token: @impersonation_token.token,
+ active_access_tokens: active_impersonation_tokens }, status: :ok
else
- set_index_vars
- render :index
+ render json: { errors: @impersonation_token.errors.full_messages }, status: :unprocessable_entity
end
end
@@ -50,19 +49,19 @@ class Admin::ImpersonationTokensController < Admin::ApplicationController
PersonalAccessTokensFinder.new({ user: user, impersonation: true }.merge(options))
end
+ def active_impersonation_tokens
+ tokens = finder(state: 'active', sort: 'expires_at_asc_id_desc').execute
+ ::ImpersonationAccessTokenSerializer.new.represent(tokens)
+ end
+
def impersonation_token_params
params.require(:personal_access_token).permit(:name, :expires_at, :impersonation, scopes: [])
end
- # rubocop: disable CodeReuse/ActiveRecord
def set_index_vars
@scopes = Gitlab::Auth.available_scopes_for(current_user)
@impersonation_token ||= finder.build
- @inactive_impersonation_tokens = finder(state: 'inactive').execute
- @active_impersonation_tokens = finder(state: 'active').execute.order(:expires_at)
-
- @new_impersonation_token = PersonalAccessToken.redis_getdel(current_user.id)
+ @active_impersonation_tokens = active_impersonation_tokens
end
- # rubocop: enable CodeReuse/ActiveRecord
end