aboutsummaryrefslogtreecommitdiffstats
path: root/services/user
diff options
context:
space:
mode:
authorJakobDev <jakobdev@gmx.de>2023-10-19 15:16:11 +0200
committerGitHub <noreply@github.com>2023-10-19 13:16:11 +0000
commit3dc0c962bf3a74188bed02c01b4d34636112805a (patch)
tree588d9e7d8fbc3a4a862f466cada768558a09cc93 /services/user
parent398eccb322f64dded83a119467af2cb38f6dbd46 (diff)
downloadgitea-3dc0c962bf3a74188bed02c01b4d34636112805a.tar.gz
gitea-3dc0c962bf3a74188bed02c01b4d34636112805a.zip
Delete repos of org when purge delete user (#27273)
Fixes https://codeberg.org/forgejo/forgejo/issues/1514 I had to remove `RenameOrganization` to avoid circular import. We should really add some foreign keys to the database.
Diffstat (limited to 'services/user')
-rw-r--r--services/user/user.go30
1 files changed, 8 insertions, 22 deletions
diff --git a/services/user/user.go b/services/user/user.go
index 2806969638..4a4908fe8e 100644
--- a/services/user/user.go
+++ b/services/user/user.go
@@ -24,6 +24,7 @@ import (
"code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/agit"
+ org_service "code.gitea.io/gitea/services/org"
"code.gitea.io/gitea/services/packages"
container_service "code.gitea.io/gitea/services/packages/container"
repo_service "code.gitea.io/gitea/services/repository"
@@ -158,27 +159,9 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error {
//
// An alternative option here would be write a DeleteAllRepositoriesForUserID function which would delete all of the repos
// but such a function would likely get out of date
- for {
- repos, _, err := repo_model.GetUserRepositories(ctx, &repo_model.SearchRepoOptions{
- ListOptions: db.ListOptions{
- PageSize: repo_model.RepositoryListDefaultPageSize,
- Page: 1,
- },
- Private: true,
- OwnerID: u.ID,
- Actor: u,
- })
- if err != nil {
- return fmt.Errorf("GetUserRepositories: %w", err)
- }
- if len(repos) == 0 {
- break
- }
- for _, repo := range repos {
- if err := repo_service.DeleteRepositoryDirectly(ctx, u, repo.ID); err != nil {
- return fmt.Errorf("unable to delete repository %s for %s[%d]. Error: %w", repo.Name, u.Name, u.ID, err)
- }
- }
+ err := repo_service.DeleteOwnerRepositoriesDirectly(ctx, u)
+ if err != nil {
+ return err
}
// Remove from Organizations and delete last owner organizations
@@ -206,7 +189,10 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error {
for _, org := range orgs {
if err := models.RemoveOrgUser(ctx, org.ID, u.ID); err != nil {
if organization.IsErrLastOrgOwner(err) {
- err = organization.DeleteOrganization(ctx, org)
+ err = org_service.DeleteOrganization(ctx, org, true)
+ if err != nil {
+ return fmt.Errorf("unable to delete organization %d: %w", org.ID, err)
+ }
}
if err != nil {
return fmt.Errorf("unable to remove user %s[%d] from org %s[%d]. Error: %w", u.Name, u.ID, org.Name, org.ID, err)