Skip to content

Commit 0c7bf68

Browse files
Gusted6543
Gusted
andauthored
Fix DELETE request for non-existent public key (#19443) (#19444)
- Backport #19443 - Add a return for the first "block" of errors, which fixes the double error messages. - Add a return for `externallyManaged`. - Resolves #19398 Co-authored-by: 6543 <[email protected]>
1 parent 5863f7e commit 0c7bf68

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

routers/api/v1/user/key.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,21 @@ func DeletePublicKey(ctx *context.APIContext) {
266266
id := ctx.ParamsInt64(":id")
267267
externallyManaged, err := asymkey_model.PublicKeyIsExternallyManaged(id)
268268
if err != nil {
269-
ctx.Error(http.StatusInternalServerError, "PublicKeyIsExternallyManaged", err)
269+
if asymkey_model.IsErrKeyNotExist(err) {
270+
ctx.NotFound()
271+
} else {
272+
ctx.Error(http.StatusInternalServerError, "PublicKeyIsExternallyManaged", err)
273+
}
274+
return
270275
}
276+
271277
if externallyManaged {
272278
ctx.Error(http.StatusForbidden, "", "SSH Key is externally managed for this user")
279+
return
273280
}
274281

275282
if err := asymkey_service.DeletePublicKey(ctx.User, id); err != nil {
276-
if asymkey_model.IsErrKeyNotExist(err) {
277-
ctx.NotFound()
278-
} else if asymkey_model.IsErrKeyAccessDenied(err) {
283+
if asymkey_model.IsErrKeyAccessDenied(err) {
279284
ctx.Error(http.StatusForbidden, "", "You do not have access to this key")
280285
} else {
281286
ctx.Error(http.StatusInternalServerError, "DeletePublicKey", err)

0 commit comments

Comments
 (0)