summaryrefslogtreecommitdiffstats
path: root/models/org_team.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-08-25 10:31:57 +0800
committerGitHub <noreply@github.com>2022-08-25 10:31:57 +0800
commit1d8543e7db58d7c4973758e47f005c4d8bd7d7a3 (patch)
treeb60c99e2dfd69ccb998f8a0829d98d7cadcf0d6b /models/org_team.go
parent4a4bfafa238bf48851f8c11fa3701bd42b912475 (diff)
downloadgitea-1d8543e7db58d7c4973758e47f005c4d8bd7d7a3.tar.gz
gitea-1d8543e7db58d7c4973758e47f005c4d8bd7d7a3.zip
Move some files into models' sub packages (#20262)
* Move some files into models' sub packages * Move functions * merge main branch * Fix check * fix check * Fix some tests * Fix lint * Fix lint * Revert lint changes * Fix error comments * Fix lint Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'models/org_team.go')
-rw-r--r--models/org_team.go34
1 files changed, 6 insertions, 28 deletions
diff --git a/models/org_team.go b/models/org_team.go
index 5d29e33337..61ddd2a047 100644
--- a/models/org_team.go
+++ b/models/org_team.go
@@ -25,12 +25,12 @@ import (
"xorm.io/builder"
)
-func addRepository(ctx context.Context, t *organization.Team, repo *repo_model.Repository) (err error) {
+func AddRepository(ctx context.Context, t *organization.Team, repo *repo_model.Repository) (err error) {
if err = organization.AddTeamRepo(ctx, t.OrgID, t.ID, repo.ID); err != nil {
return err
}
- if _, err = db.GetEngine(ctx).Incr("num_repos").ID(t.ID).Update(new(organization.Team)); err != nil {
+ if err = organization.IncrTeamRepoNum(ctx, t.ID); err != nil {
return fmt.Errorf("update team: %v", err)
}
@@ -58,16 +58,15 @@ func addRepository(ctx context.Context, t *organization.Team, repo *repo_model.R
// addAllRepositories adds all repositories to the team.
// If the team already has some repositories they will be left unchanged.
func addAllRepositories(ctx context.Context, t *organization.Team) error {
- var orgRepos []repo_model.Repository
- e := db.GetEngine(ctx)
- if err := e.Where("owner_id = ?", t.OrgID).Find(&orgRepos); err != nil {
+ orgRepos, err := organization.GetOrgRepositories(ctx, t.OrgID)
+ if err != nil {
return fmt.Errorf("get org repos: %v", err)
}
for _, repo := range orgRepos {
if !organization.HasTeamRepo(ctx, t.OrgID, t.ID, repo.ID) {
- if err := addRepository(ctx, t, &repo); err != nil {
- return fmt.Errorf("addRepository: %v", err)
+ if err := AddRepository(ctx, t, repo); err != nil {
+ return fmt.Errorf("AddRepository: %v", err)
}
}
}
@@ -90,27 +89,6 @@ func AddAllRepositories(t *organization.Team) (err error) {
return committer.Commit()
}
-// AddRepository adds new repository to team of organization.
-func AddRepository(t *organization.Team, repo *repo_model.Repository) (err error) {
- if repo.OwnerID != t.OrgID {
- return errors.New("Repository does not belong to organization")
- } else if HasRepository(t, repo.ID) {
- return nil
- }
-
- ctx, committer, err := db.TxContext()
- if err != nil {
- return err
- }
- defer committer.Close()
-
- if err = addRepository(ctx, t, repo); err != nil {
- return err
- }
-
- return committer.Commit()
-}
-
// RemoveAllRepositories removes all repositories from team and recalculates access
func RemoveAllRepositories(t *organization.Team) (err error) {
if t.IncludesAllRepositories {