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>
This commit is contained in:
parent
ca63a9d3f1
commit
21da519c0c
7 changed files with 27 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue