diff options
author | 6543 <6543@obermui.de> | 2021-01-17 21:48:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-17 21:48:38 +0100 |
commit | 21da519c0cd6e243888ebe573e3496e4eda01f10 (patch) | |
tree | a4e2fe5cf6dae77091e8089fa6b98c8684b07fe1 /models/user.go | |
parent | ca63a9d3f1120d8c76eb83ff1fd07e0992a683a8 (diff) | |
download | gitea-21da519c0cd6e243888ebe573e3496e4eda01f10.tar.gz gitea-21da519c0cd6e243888ebe573e3496e4eda01f10.zip |
Implement ghost comment mitigation (#14349)
* Implement ghost comment mitigation
Adds a config option USER_DELETE_WITH_COMMENTS_MAX_DAYS to the [service] section. See https://codeberg.org/Codeberg/Discussion/issues/24 for the underlying issue.
* cleanup
* use setting module correctly
* add to docs
Co-authored-by: Moritz Marquardt <git@momar.de>
Diffstat (limited to 'models/user.go')
-rw-r--r-- | models/user.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/models/user.go b/models/user.go index de12b804fd..584c9d032d 100644 --- a/models/user.go +++ b/models/user.go @@ -1151,6 +1151,15 @@ func deleteUser(e *xorm.Session, u *User) error { return fmt.Errorf("deleteBeans: %v", err) } + if setting.Service.UserDeleteWithCommentsMaxDays != 0 && + u.CreatedUnix.AsTime().Add(time.Duration(setting.Service.UserDeleteWithCommentsMaxDays)*24*time.Hour).After(time.Now()) { + if err = deleteBeans(e, + &Comment{PosterID: u.ID}, + ); err != nil { + return fmt.Errorf("deleteBeans: %v", err) + } + } + // ***** START: PublicKey ***** if _, err = e.Delete(&PublicKey{OwnerID: u.ID}); err != nil { return fmt.Errorf("deletePublicKeys: %v", err) @@ -1205,7 +1214,8 @@ func deleteUser(e *xorm.Session, u *User) error { } // DeleteUser completely and permanently deletes everything of a user, -// but issues/comments/pulls will be kept and shown as someone has been deleted. +// but issues/comments/pulls will be kept and shown as someone has been deleted, +// unless the user is younger than USER_DELETE_WITH_COMMENTS_MAX_DAYS. func DeleteUser(u *User) (err error) { if u.IsOrganization() { return fmt.Errorf("%s is an organization not a user", u.Name) |