Fix permissions for Token DELETE endpoint to match GET and POST (#27610) (#28099)

Backport #27610 by @evantobin

Fixes #27598

In #27080, the logic for the tokens endpoints were updated to allow
admins to create and view tokens in other accounts. However, the same
functionality was not added to the DELETE endpoint. This PR makes the
DELETE endpoint function the same as the other token endpoints and adds
unit tests

Co-authored-by: Evan Tobin <me@evantob.in>
(cherry picked from commit 93ede4bc83)
This commit is contained in:
Giteabot 2023-11-17 12:24:16 +08:00 committed by Earl Warren
parent 1eb83ea8cc
commit 702ef8d12f
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
2 changed files with 30 additions and 3 deletions

View file

@ -193,7 +193,7 @@ func DeleteAccessToken(ctx *context.APIContext) {
return
}
if err := auth_model.DeleteAccessTokenByID(ctx, tokenID, ctx.Doer.ID); err != nil {
if err := auth_model.DeleteAccessTokenByID(ctx, tokenID, ctx.ContextUser.ID); err != nil {
if auth_model.IsErrAccessTokenNotExist(err) {
ctx.NotFound()
} else {