Skip to content

Commit f8898c3

Browse files
KN4CK3Rzeripath6543techknowlogick
authored
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 <[email protected]> Co-authored-by: 6543 <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent df9802c commit f8898c3

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

integrations/user_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ func TestExportUserGPGKeys(t *testing.T) {
121121
defer prepareTestEnv(t)()
122122
// Export empty key list
123123
testExportUserGPGKeys(t, "user1", `-----BEGIN PGP PUBLIC KEY BLOCK-----
124+
Note: This user hasn't uploaded any GPG keys.
124125
125126
126127
=twTO

routers/web/user/home.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ func ShowGPGKeys(ctx *context.Context, uid int64) {
736736
ctx.ServerError("ListGPGKeys", err)
737737
return
738738
}
739+
739740
entities := make([]*openpgp.Entity, 0)
740741
failedEntitiesID := make([]string, 0)
741742
for _, k := range keys {
@@ -755,6 +756,8 @@ func ShowGPGKeys(ctx *context.Context, uid int64) {
755756
headers := make(map[string]string)
756757
if len(failedEntitiesID) > 0 { // If some key need re-import to be exported
757758
headers["Note"] = fmt.Sprintf("The keys with the following IDs couldn't be exported and need to be reuploaded %s", strings.Join(failedEntitiesID, ", "))
759+
} else if len(entities) == 0 {
760+
headers["Note"] = "This user hasn't uploaded any GPG keys."
758761
}
759762
writer, _ := armor.Encode(&buf, "PGP PUBLIC KEY BLOCK", headers)
760763
for _, e := range entities {

0 commit comments

Comments
 (0)