summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGusted <williamzijl7@hotmail.com>2022-04-20 22:24:56 +0000
committerGitHub <noreply@github.com>2022-04-20 23:24:56 +0100
commit0c7bf6801f240c2831f7dffdaa34a22a0344da0b (patch)
tree76ab5386bd7f4a14c61ebc2786247b7a593c858c
parent5863f7e0488e23411c99fbcacc5d7b8cc1570611 (diff)
downloadgitea-0c7bf6801f240c2831f7dffdaa34a22a0344da0b.tar.gz
gitea-0c7bf6801f240c2831f7dffdaa34a22a0344da0b.zip
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 <6543@obermui.de>
-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 e8cc2035e5..aba723cf2e 100644
--- a/routers/api/v1/user/key.go
+++ b/routers/api/v1/user/key.go
@@ -266,16 +266,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.User, 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)