summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo/teams.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-03-29 14:29:02 +0800
committerGitHub <noreply@github.com>2022-03-29 14:29:02 +0800
commitb06b9a056c0af751e576978f6ef3c914ee959b9c (patch)
treeaa0d11413038baa5d47af65fd435665c698fe456 /routers/api/v1/repo/teams.go
parentd4c789dfc1c341413b77a2f21fe7339982102bed (diff)
downloadgitea-b06b9a056c0af751e576978f6ef3c914ee959b9c.tar.gz
gitea-b06b9a056c0af751e576978f6ef3c914ee959b9c.zip
Move organization related structs into sub package (#18518)
* Move organization related structs into sub package * Fix test * Fix lint * Move more functions into sub packages * Fix bug * Fix test * Update models/organization/team_repo.go Co-authored-by: KN4CK3R <admin@oldschoolhack.me> * Apply suggestions from code review Co-authored-by: KN4CK3R <admin@oldschoolhack.me> * Fix fmt * Follow suggestion from @Gusted * Fix test * Fix test * Fix bug * Use ctx but db.DefaultContext on routers * Fix bug * Fix bug * fix bug * Update models/organization/team_user.go * Fix bug Co-authored-by: KN4CK3R <admin@oldschoolhack.me> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'routers/api/v1/repo/teams.go')
-rw-r--r--routers/api/v1/repo/teams.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/routers/api/v1/repo/teams.go b/routers/api/v1/repo/teams.go
index 024224b5a3..1e3ea326d3 100644
--- a/routers/api/v1/repo/teams.go
+++ b/routers/api/v1/repo/teams.go
@@ -9,6 +9,7 @@ import (
"net/http"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/organization"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
api "code.gitea.io/gitea/modules/structs"
@@ -41,7 +42,7 @@ func ListTeams(ctx *context.APIContext) {
return
}
- teams, err := models.GetRepoTeams(ctx.Repo.Repository)
+ teams, err := organization.GetRepoTeams(ctx.Repo.Repository)
if err != nil {
ctx.InternalServerError(err)
return
@@ -101,7 +102,7 @@ func IsTeam(ctx *context.APIContext) {
return
}
- if team.HasRepository(ctx.Repo.Repository.ID) {
+ if models.HasRepository(team, ctx.Repo.Repository.ID) {
if err := team.GetUnits(); err != nil {
ctx.Error(http.StatusInternalServerError, "GetUnits", err)
return
@@ -196,20 +197,20 @@ func changeRepoTeam(ctx *context.APIContext, add bool) {
return
}
- repoHasTeam := team.HasRepository(ctx.Repo.Repository.ID)
+ repoHasTeam := models.HasRepository(team, ctx.Repo.Repository.ID)
var err error
if add {
if repoHasTeam {
ctx.Error(http.StatusUnprocessableEntity, "alreadyAdded", fmt.Errorf("team '%s' is already added to repo", team.Name))
return
}
- err = team.AddRepository(ctx.Repo.Repository)
+ err = models.AddRepository(team, ctx.Repo.Repository)
} else {
if !repoHasTeam {
ctx.Error(http.StatusUnprocessableEntity, "notAdded", fmt.Errorf("team '%s' was not added to repo", team.Name))
return
}
- err = team.RemoveRepository(ctx.Repo.Repository.ID)
+ err = models.RemoveRepository(team, ctx.Repo.Repository.ID)
}
if err != nil {
ctx.InternalServerError(err)
@@ -219,10 +220,10 @@ func changeRepoTeam(ctx *context.APIContext, add bool) {
ctx.Status(http.StatusNoContent)
}
-func getTeamByParam(ctx *context.APIContext) *models.Team {
- team, err := models.GetTeam(ctx.Repo.Owner.ID, ctx.Params(":team"))
+func getTeamByParam(ctx *context.APIContext) *organization.Team {
+ team, err := organization.GetTeam(ctx.Repo.Owner.ID, ctx.Params(":team"))
if err != nil {
- if models.IsErrTeamNotExist(err) {
+ if organization.IsErrTeamNotExist(err) {
ctx.Error(http.StatusNotFound, "TeamNotExit", err)
return nil
}