summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGusted <williamzijl7@hotmail.com>2022-04-21 01:08:30 +0000
committerGitHub <noreply@github.com>2022-04-21 03:08:30 +0200
commitf4c1aa75be1974a4243b04346140922fb66b9b9f (patch)
treee07a6eb4801e40a2d425d03a55d2169917ac65df
parentf7a8e5c8f20e4de1a19af093c550331434cffe41 (diff)
downloadgitea-f4c1aa75be1974a4243b04346140922fb66b9b9f.tar.gz
gitea-f4c1aa75be1974a4243b04346140922fb66b9b9f.zip
Fix DELETE request for non-existent public key (#19443)
- Add a return for the first "block" of errors, which fixes the double error messages. - Add a return for `externallyManaged`. - Resolves #19398
-rw-r--r--routers/api/v1/user/key.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/routers/api/v1/user/key.go b/routers/api/v1/user/key.go
index cc7ee739ce..71a2c910a6 100644
--- a/routers/api/v1/user/key.go
+++ b/routers/api/v1/user/key.go
@@ -262,16 +262,21 @@ func DeletePublicKey(ctx *context.APIContext) {
id := ctx.ParamsInt64(":id")
externallyManaged, err := asymkey_model.PublicKeyIsExternallyManaged(id)
if err != nil {
- ctx.Error(http.StatusInternalServerError, "PublicKeyIsExternallyManaged", err)
+ if asymkey_model.IsErrKeyNotExist(err) {
+ ctx.NotFound()
+ } else {
+ ctx.Error(http.StatusInternalServerError, "PublicKeyIsExternallyManaged", err)
+ }
+ return
}
+
if externallyManaged {
ctx.Error(http.StatusForbidden, "", "SSH Key is externally managed for this user")
+ return
}
if err := asymkey_service.DeletePublicKey(ctx.Doer, id); err != nil {
- if asymkey_model.IsErrKeyNotExist(err) {
- ctx.NotFound()
- } else if asymkey_model.IsErrKeyAccessDenied(err) {
+ if asymkey_model.IsErrKeyAccessDenied(err) {
ctx.Error(http.StatusForbidden, "", "You do not have access to this key")
} else {
ctx.Error(http.StatusInternalServerError, "DeletePublicKey", err)