mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-11-02 07:21:02 +00:00
[MODERATION] Purge issues on user deletion
- Forgejo has the option to delete users, in which all data except
issues and comments are removed, this makes sense in some cases where
users need to be removed cleanly but without removing their existing bug
reports or comments to an discussion. In the case of spammers, admins
have the option to enable purging, where comments are removed.
- Add issues to the list of things to be removed if purge is checked.
- No unit testing, as this gigantic function doesn't have one to begin
with.
- Add integration test.
- Resolves https://codeberg.org/forgejo/forgejo/issues/1268
(cherry picked from commit 3ed381c758)
This commit is contained in:
parent
9abb95a844
commit
44d00650ce
11 changed files with 67 additions and 20 deletions
|
|
@ -22,6 +22,7 @@ import (
|
|||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
issue_service "code.gitea.io/gitea/services/issue"
|
||||
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
|
@ -127,6 +128,31 @@ func deleteUser(ctx context.Context, u *user_model.User, purge bool) (err error)
|
|||
}
|
||||
}
|
||||
|
||||
// ***** START: Issues *****
|
||||
if purge {
|
||||
const batchSize = 50
|
||||
|
||||
for {
|
||||
issues := make([]*issues_model.Issue, 0, batchSize)
|
||||
if err = e.Where("poster_id=?", u.ID).Limit(batchSize, 0).Find(&issues); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(issues) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
for _, issue := range issues {
|
||||
// NOTE: Don't open git repositories just to remove the reference data,
|
||||
// `git gc` is able to remove that reference which is run as a cron job
|
||||
// by default. Also use the deleted user as doer to delete the issue.
|
||||
if err = issue_service.DeleteIssue(ctx, u, nil, issue); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// ***** END: Issues *****
|
||||
|
||||
// ***** START: Branch Protections *****
|
||||
{
|
||||
const batchSize = 50
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue