summaryrefslogtreecommitdiffstats
path: root/routers/api/v1
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-12-26 04:24:47 +0000
committerGitHub <noreply@github.com>2020-12-25 23:24:47 -0500
commitad1164f73ba277f11a20ea838a62d9b8c8a7cb45 (patch)
tree7854283c1a6a12621cf36b0c6397a12bfea436d8 /routers/api/v1
parenta19447aed128ecadfcd938d6a80cd4951af1f4ce (diff)
downloadgitea-ad1164f73ba277f11a20ea838a62d9b8c8a7cb45.tar.gz
gitea-ad1164f73ba277f11a20ea838a62d9b8c8a7cb45.zip
Disable SSH key deletion of externally managed Keys (#13985)
* Disable SSH key addition and deletion when externally managed When a user has a login source which has SSH key management key addition and deletion using the UI should be disabled. Fix #13983 Signed-off-by: Andrew Thornton <art27@cantab.net> * Make only externally managed keys disabled Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'routers/api/v1')
-rw-r--r--routers/api/v1/user/key.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/routers/api/v1/user/key.go b/routers/api/v1/user/key.go
index 033b29f420..8069660653 100644
--- a/routers/api/v1/user/key.go
+++ b/routers/api/v1/user/key.go
@@ -267,7 +267,16 @@ func DeletePublicKey(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
- if err := models.DeletePublicKey(ctx.User, ctx.ParamsInt64(":id")); err != nil {
+ id := ctx.ParamsInt64(":id")
+ externallyManaged, err := models.PublicKeyIsExternallyManaged(id)
+ if err != nil {
+ ctx.Error(http.StatusInternalServerError, "PublicKeyIsExternallyManaged", err)
+ }
+ if externallyManaged {
+ ctx.Error(http.StatusForbidden, "", "SSH Key is externally managed for this user")
+ }
+
+ if err := models.DeletePublicKey(ctx.User, id); err != nil {
if models.IsErrKeyNotExist(err) {
ctx.NotFound()
} else if models.IsErrKeyAccessDenied(err) {