summaryrefslogtreecommitdiffstats
path: root/models/repo.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-11-19 19:41:40 +0800
committerGitHub <noreply@github.com>2021-11-19 19:41:40 +0800
commit7a0347315995b25bcb2dca4786504fb699b5f004 (patch)
tree803dfd39286216fd0521ad16539ffd9fc5f87fc0 /models/repo.go
parenta09b40de8d1dae7107437cfba42cee201fcd6d42 (diff)
downloadgitea-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 'models/repo.go')
-rw-r--r--models/repo.go26
1 files changed, 13 insertions, 13 deletions
diff --git a/models/repo.go b/models/repo.go
index d62b3ec2b4..3877502926 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -783,7 +783,7 @@ func (repo *Repository) CanUserDelete(user *User) (bool, error) {
}
if repo.Owner.IsOrganization() {
- isOwner, err := repo.Owner.IsOwnedBy(user.ID)
+ isOwner, err := OrgFromUser(repo.Owner).IsOwnedBy(user.ID)
if err != nil {
return false, err
} else if isOwner {
@@ -1118,10 +1118,11 @@ func CreateRepository(ctx context.Context, doer, u *User, repo *Repository, over
// Give access to all members in teams with access to all repositories.
if u.IsOrganization() {
- if err := u.loadTeams(db.GetEngine(ctx)); err != nil {
+ teams, err := OrgFromUser(u).loadTeams(db.GetEngine(ctx))
+ if err != nil {
return fmt.Errorf("loadTeams: %v", err)
}
- for _, t := range u.Teams {
+ for _, t := range teams {
if t.IncludesAllRepositories {
if err := t.addRepository(db.GetEngine(ctx), repo); err != nil {
return fmt.Errorf("addRepository: %v", err)
@@ -1444,11 +1445,6 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
if err != nil {
return err
}
- if org.IsOrganization() {
- if err = org.loadTeams(sess); err != nil {
- return err
- }
- }
repo := &Repository{OwnerID: uid}
has, err := sess.ID(repoID).Get(repo)
@@ -1476,7 +1472,11 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
}
if org.IsOrganization() {
- for _, t := range org.Teams {
+ teams, err := OrgFromUser(org).loadTeams(sess)
+ if err != nil {
+ return err
+ }
+ for _, t := range teams {
if !t.hasRepository(sess, repoID) {
continue
} else if err = t.removeRepository(sess, repo, false); err != nil {
@@ -1790,8 +1790,8 @@ func GetUserMirrorRepositories(userID int64) ([]*Repository, error) {
Find(&repos)
}
-func getRepositoryCount(e db.Engine, u *User) (int64, error) {
- return e.Count(&Repository{OwnerID: u.ID})
+func getRepositoryCount(e db.Engine, ownerID int64) (int64, error) {
+ return e.Count(&Repository{OwnerID: ownerID})
}
func getPublicRepositoryCount(e db.Engine, u *User) (int64, error) {
@@ -1803,8 +1803,8 @@ func getPrivateRepositoryCount(e db.Engine, u *User) (int64, error) {
}
// GetRepositoryCount returns the total number of repositories of user.
-func GetRepositoryCount(ctx context.Context, u *User) (int64, error) {
- return getRepositoryCount(db.GetEngine(ctx), u)
+func GetRepositoryCount(ctx context.Context, ownerID int64) (int64, error) {
+ return getRepositoryCount(db.GetEngine(ctx), ownerID)
}
// GetPublicRepositoryCount returns the total number of public repositories of user.