diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2022-03-02 17:32:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-02 11:32:18 -0500 |
commit | f8898c30dc028e8bddadffacbd357c76b0c3506b (patch) | |
tree | 004e3f70a5fa9fd3bf4523b013db4e25e7b1c3d0 /routers/web/user/home.go | |
parent | df9802ca61bac32e9f636e6d813a7fc6608b26a3 (diff) | |
download | gitea-f8898c30dc028e8bddadffacbd357c76b0c3506b.tar.gz gitea-f8898c30dc028e8bddadffacbd357c76b0c3506b.zip |
Add note to GPG key response if user has no keys (#18961)
* Prevent invalid key response.
* Display note instead of 404 response.
* Fixed test.
Co-authored-by: zeripath <art27@cantab.net>
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'routers/web/user/home.go')
-rw-r--r-- | routers/web/user/home.go | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/routers/web/user/home.go b/routers/web/user/home.go index 33512d97c0..379e1f8e20 100644 --- a/routers/web/user/home.go +++ b/routers/web/user/home.go @@ -736,6 +736,7 @@ func ShowGPGKeys(ctx *context.Context, uid int64) { ctx.ServerError("ListGPGKeys", err) return } + entities := make([]*openpgp.Entity, 0) failedEntitiesID := make([]string, 0) for _, k := range keys { @@ -755,6 +756,8 @@ func ShowGPGKeys(ctx *context.Context, uid int64) { headers := make(map[string]string) if len(failedEntitiesID) > 0 { // If some key need re-import to be exported headers["Note"] = fmt.Sprintf("The keys with the following IDs couldn't be exported and need to be reuploaded %s", strings.Join(failedEntitiesID, ", ")) + } else if len(entities) == 0 { + headers["Note"] = "This user hasn't uploaded any GPG keys." } writer, _ := armor.Encode(&buf, "PGP PUBLIC KEY BLOCK", headers) for _, e := range entities { |