summaryrefslogtreecommitdiffstats
path: root/models/user.go
diff options
context:
space:
mode:
authorAnton Khimich <anton.khimich@gmail.com>2021-02-04 04:16:21 -0500
committerGitHub <noreply@github.com>2021-02-04 17:16:21 +0800
commit80b1d02b2f631a9e68120715a82f7f41f203ef79 (patch)
treeadac8324961f81436ddb0a11ecc4bf93f9c99f1d /models/user.go
parent3c965c3e308a9399b6598e9d0f545f4e31fc578d (diff)
downloadgitea-80b1d02b2f631a9e68120715a82f7f41f203ef79.tar.gz
gitea-80b1d02b2f631a9e68120715a82f7f41f203ef79.zip
Fix gpg key deletion (#14561)
* Fix GPG key deletion when user is deleted Per #14531, deleting a user account will delete the user's GPG keys from the `gpg_key` table but not from `gpg_key_import`, which causes an error when creating an account with the same email and attempting to re-add the same key. This commit deletes all entries from `gpg_key_import` that match any GPG key IDs belonging to the user. * Format added code in models/user.go * Create a new function for listing GPG keys and apply it Create a new function `listGPGKeys` and replace a previous use of `ListGPGKeys`. Thanks to @6543 for the patch. Co-authored-by: Anton Khimich <anton.khimicha@mail.utoronto.ca> Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'models/user.go')
-rw-r--r--models/user.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/models/user.go b/models/user.go
index 8147c9f626..495fed1ff4 100644
--- a/models/user.go
+++ b/models/user.go
@@ -1208,6 +1208,16 @@ func deleteUser(e Engine, u *User) error {
// ***** END: PublicKey *****
// ***** START: GPGPublicKey *****
+ keys, err := listGPGKeys(e, u.ID, ListOptions{})
+ if err != nil {
+ return fmt.Errorf("ListGPGKeys: %v", err)
+ }
+ // Delete GPGKeyImport(s).
+ for _, key := range keys {
+ if _, err = e.Delete(&GPGKeyImport{KeyID: key.KeyID}); err != nil {
+ return fmt.Errorf("deleteGPGKeyImports: %v", err)
+ }
+ }
if _, err = e.Delete(&GPGKey{OwnerID: u.ID}); err != nil {
return fmt.Errorf("deleteGPGKeys: %v", err)
}