diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-19 19:41:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-19 19:41:40 +0800 |
commit | 7a0347315995b25bcb2dca4786504fb699b5f004 (patch) | |
tree | 803dfd39286216fd0521ad16539ffd9fc5f87fc0 /services | |
parent | a09b40de8d1dae7107437cfba42cee201fcd6d42 (diff) | |
download | gitea-7a0347315995b25bcb2dca4786504fb699b5f004.tar.gz gitea-7a0347315995b25bcb2dca4786504fb699b5f004.zip |
Use a standalone struct name for Organization (#17632)
* Use a standalone struct name for Organization
* recover unnecessary change
* make the code readable
* Fix template failure
* Fix template failure
* Move HasMemberWithUserID to org
* Fix test
* Remove unnecessary user type check
* Fix test
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'services')
-rw-r--r-- | services/org/org.go | 8 | ||||
-rw-r--r-- | services/org/org_test.go | 8 | ||||
-rw-r--r-- | services/repository/repository.go | 2 | ||||
-rw-r--r-- | services/user/user.go | 2 |
4 files changed, 8 insertions, 12 deletions
diff --git a/services/org/org.go b/services/org/org.go index cb1f1eca03..c2b21d10ac 100644 --- a/services/org/org.go +++ b/services/org/org.go @@ -14,11 +14,7 @@ import ( ) // DeleteOrganization completely and permanently deletes everything of organization. -func DeleteOrganization(org *models.User) error { - if !org.IsOrganization() { - return fmt.Errorf("%s is a user not an organization", org.Name) - } - +func DeleteOrganization(org *models.Organization) error { ctx, commiter, err := db.TxContext() if err != nil { return err @@ -26,7 +22,7 @@ func DeleteOrganization(org *models.User) error { defer commiter.Close() // Check ownership of repository. - count, err := models.GetRepositoryCount(ctx, org) + count, err := models.GetRepositoryCount(ctx, org.ID) if err != nil { return fmt.Errorf("GetRepositoryCount: %v", err) } else if count > 0 { diff --git a/services/org/org_test.go b/services/org/org_test.go index 5fec086d10..3c620c055b 100644 --- a/services/org/org_test.go +++ b/services/org/org_test.go @@ -20,18 +20,18 @@ func TestMain(m *testing.M) { func TestDeleteOrganization(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - org := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 6}).(*models.User) + org := unittest.AssertExistsAndLoadBean(t, &models.Organization{ID: 6}).(*models.Organization) assert.NoError(t, DeleteOrganization(org)) - unittest.AssertNotExistsBean(t, &models.User{ID: 6}) + unittest.AssertNotExistsBean(t, &models.Organization{ID: 6}) unittest.AssertNotExistsBean(t, &models.OrgUser{OrgID: 6}) unittest.AssertNotExistsBean(t, &models.Team{OrgID: 6}) - org = unittest.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User) + org = unittest.AssertExistsAndLoadBean(t, &models.Organization{ID: 3}).(*models.Organization) err := DeleteOrganization(org) assert.Error(t, err) assert.True(t, models.IsErrUserOwnRepos(err)) - user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User) + user := unittest.AssertExistsAndLoadBean(t, &models.Organization{ID: 5}).(*models.Organization) assert.Error(t, DeleteOrganization(user)) unittest.CheckConsistencyFor(t, &models.User{}, &models.Team{}) } diff --git a/services/repository/repository.go b/services/repository/repository.go index 98d160c223..1d390247f1 100644 --- a/services/repository/repository.go +++ b/services/repository/repository.go @@ -45,7 +45,7 @@ func DeleteRepository(doer *models.User, repo *models.Repository) error { func PushCreateRepo(authUser, owner *models.User, repoName string) (*models.Repository, error) { if !authUser.IsAdmin { if owner.IsOrganization() { - if ok, err := owner.CanCreateOrgRepo(authUser.ID); err != nil { + if ok, err := models.CanCreateOrgRepo(owner.ID, authUser.ID); err != nil { return nil, err } else if !ok { return nil, fmt.Errorf("cannot push-create repository for org") diff --git a/services/user/user.go b/services/user/user.go index a08e40f86e..733cc4a36e 100644 --- a/services/user/user.go +++ b/services/user/user.go @@ -35,7 +35,7 @@ func DeleteUser(u *models.User) error { // cannot perform delete operation. // Check ownership of repository. - count, err := models.GetRepositoryCount(ctx, u) + count, err := models.GetRepositoryCount(ctx, u.ID) if err != nil { return fmt.Errorf("GetRepositoryCount: %v", err) } else if count > 0 { |