aboutsummaryrefslogtreecommitdiffstats
path: root/services/org
diff options
context:
space:
mode:
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{})
}