aboutsummaryrefslogtreecommitdiffstats
path: root/services/org
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/org
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/org')
-rw-r--r--services/org/org.go16
-rw-r--r--services/org/org_test.go6
2 files changed, 12 insertions, 10 deletions
diff --git a/services/org/org.go b/services/org/org.go
index 4ecafc93a6..dca7794b47 100644
--- a/services/org/org.go
+++ b/services/org/org.go
@@ -15,17 +15,24 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/modules/util"
- user_service "code.gitea.io/gitea/services/user"
+ repo_service "code.gitea.io/gitea/services/repository"
)
// DeleteOrganization completely and permanently deletes everything of organization.
-func DeleteOrganization(ctx context.Context, org *org_model.Organization) error {
+func DeleteOrganization(ctx context.Context, org *org_model.Organization, purge bool) error {
ctx, commiter, err := db.TxContext(ctx)
if err != nil {
return err
}
defer commiter.Close()
+ if purge {
+ err := repo_service.DeleteOwnerRepositoriesDirectly(ctx, org.AsUser())
+ if err != nil {
+ return err
+ }
+ }
+
// Check ownership of repository.
count, err := repo_model.CountRepositories(ctx, repo_model.CountRepositoryOptions{OwnerID: org.ID})
if err != nil {
@@ -67,8 +74,3 @@ func DeleteOrganization(ctx context.Context, org *org_model.Organization) error
return nil
}
-
-// RenameOrganization renames an organization.
-func RenameOrganization(ctx context.Context, org *org_model.Organization, newName string) error {
- return user_service.RenameUser(ctx, org.AsUser(), newName)
-}
diff --git a/services/org/org_test.go b/services/org/org_test.go
index 763c708c14..e7d2a18ea9 100644
--- a/services/org/org_test.go
+++ b/services/org/org_test.go
@@ -22,17 +22,17 @@ func TestMain(m *testing.M) {
func TestDeleteOrganization(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 6})
- assert.NoError(t, DeleteOrganization(db.DefaultContext, org))
+ assert.NoError(t, DeleteOrganization(db.DefaultContext, org, false))
unittest.AssertNotExistsBean(t, &organization.Organization{ID: 6})
unittest.AssertNotExistsBean(t, &organization.OrgUser{OrgID: 6})
unittest.AssertNotExistsBean(t, &organization.Team{OrgID: 6})
org = unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3})
- err := DeleteOrganization(db.DefaultContext, org)
+ err := DeleteOrganization(db.DefaultContext, org, false)
assert.Error(t, err)
assert.True(t, models.IsErrUserOwnRepos(err))
user := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 5})
- assert.Error(t, DeleteOrganization(db.DefaultContext, user))
+ assert.Error(t, DeleteOrganization(db.DefaultContext, user, false))
unittest.CheckConsistencyFor(t, &user_model.User{}, &organization.Team{})
}