summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-08-21 11:45:50 +0100
committerGitHub <noreply@github.com>2020-08-21 13:45:50 +0300
commit7c2cf236f8a54038e1688e6256e6c32b8b4e6913 (patch)
tree2b91975d306c3de933a2ca949507d5b2f87ce3eb /routers
parentae23bbdae3102ebc187ff504fe07d75116815ff4 (diff)
downloadgitea-7c2cf236f8a54038e1688e6256e6c32b8b4e6913.tar.gz
gitea-7c2cf236f8a54038e1688e6256e6c32b8b4e6913.zip
Allow addition of gpg keyring with multiple keys (#12487)
Related #6778 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/user/gpg_key.go4
-rw-r--r--routers/user/setting/keys.go12
2 files changed, 12 insertions, 4 deletions
diff --git a/routers/api/v1/user/gpg_key.go b/routers/api/v1/user/gpg_key.go
index 9fbe351c27..7290ef485a 100644
--- a/routers/api/v1/user/gpg_key.go
+++ b/routers/api/v1/user/gpg_key.go
@@ -118,12 +118,12 @@ func GetGPGKey(ctx *context.APIContext) {
// CreateUserGPGKey creates new GPG key to given user by ID.
func CreateUserGPGKey(ctx *context.APIContext, form api.CreateGPGKeyOption, uid int64) {
- key, err := models.AddGPGKey(uid, form.ArmoredKey)
+ keys, err := models.AddGPGKey(uid, form.ArmoredKey)
if err != nil {
HandleAddGPGKeyError(ctx, err)
return
}
- ctx.JSON(http.StatusCreated, convert.ToGPGKey(key))
+ ctx.JSON(http.StatusCreated, convert.ToGPGKey(keys[0]))
}
// swagger:parameters userCurrentPostGPGKey
diff --git a/routers/user/setting/keys.go b/routers/user/setting/keys.go
index 73ae73da40..a7978fe14e 100644
--- a/routers/user/setting/keys.go
+++ b/routers/user/setting/keys.go
@@ -41,7 +41,7 @@ func KeysPost(ctx *context.Context, form auth.AddKeyForm) {
}
switch form.Type {
case "gpg":
- key, err := models.AddGPGKey(ctx.User.ID, form.Content)
+ keys, err := models.AddGPGKey(ctx.User.ID, form.Content)
if err != nil {
ctx.Data["HasGPGError"] = true
switch {
@@ -63,7 +63,15 @@ func KeysPost(ctx *context.Context, form auth.AddKeyForm) {
}
return
}
- ctx.Flash.Success(ctx.Tr("settings.add_gpg_key_success", key.KeyID))
+ keyIDs := ""
+ for _, key := range keys {
+ keyIDs += key.KeyID
+ keyIDs += ", "
+ }
+ if len(keyIDs) > 0 {
+ keyIDs = keyIDs[:len(keyIDs)-2]
+ }
+ ctx.Flash.Success(ctx.Tr("settings.add_gpg_key_success", keyIDs))
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
case "ssh":
content, err := models.CheckPublicKeyString(form.Content)