Add filter and sort params to impersonation tokens API
What does this MR do and why?
This is the first step of moving the admin impersonation tokens page (Admin > Users > a user > Impersonation Tokens) onto the shared access tokens Vue app. The group and project token pages already made this move in !195535. That app sends filter and sort query params when it lists tokens.
The problem: GET /api/v4/users/:user_id/impersonation_tokens only declared state (plus pagination), so Grape dropped every other param. PersonalAccessTokensFinder already supports all of them.
The first commit makes the endpoint use the shared access_token_params block. It now accepts:
searchrevokedcreated_before,created_afterexpires_before,expires_afterlast_used_before,last_used_aftersort:created_asc,created_desc,expires_asc,expires_desc,last_used_asc,last_used_desc,name_asc,name_desc
The second commit aligns state. The impersonation endpoint accepted state=all (and defaulted to it). The other endpoints that share the block rejected state=all with a 400. These are the personal, project, group, service account, and group credentials inventory token lists. The shared block now accepts all too, so every endpoint takes the same values and the impersonation endpoint needs no special case.
The finder treats all the same as no state, so results do not change. The change only widens what is accepted. The impersonation endpoint no longer sets a default of all, which returns the same tokens as no default.
The API docs (doc/api/*.md) and doc/api/openapi/openapi_v3.yaml are updated. openapi_v2.yaml does not include these endpoints.
References
- !195535 (the group and project token UI migration this follows)
Screenshots or screen recordings
Not applicable. This is a backend-only API change.
How to set up and validate locally
You need an admin personal access token with the api scope. Replace http://gdk.test:3000 with your GDK URL.
-
Create one or two impersonation tokens for a user (Admin > Users > pick a user > Impersonation Tokens). Give them different names.
-
List the tokens with the new params:
curl --header "PRIVATE-TOKEN: <admin_token>" "http://gdk.test:3000/api/v4/users/<user_id>/impersonation_tokens?search=<part of a name>" curl --header "PRIVATE-TOKEN: <admin_token>" "http://gdk.test:3000/api/v4/users/<user_id>/impersonation_tokens?sort=name_asc" curl --header "PRIVATE-TOKEN: <admin_token>" "http://gdk.test:3000/api/v4/users/<user_id>/impersonation_tokens?revoked=true"Before this MR these params were ignored and all tokens came back.
-
Check that
state=allis accepted on another endpoint:curl --header "PRIVATE-TOKEN: <admin_token>" "http://gdk.test:3000/api/v4/personal_access_tokens?state=all"This returns 200. Before this MR it returned 400 "state does not have a valid value".
-
Optionally, run the specs:
bin/rspec spec/requests/api/users_spec.rb -e 'impersonation_tokens' spec/requests/api/personal_access_tokens_spec.rb spec/requests/api/resource_access_tokens_spec.rb
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.