diff options
author | zeripath <art27@cantab.net> | 2022-02-02 08:40:04 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-02 08:40:04 +0000 |
commit | 9c318a17f576887736e97c7bc2971d2ad7579a33 (patch) | |
tree | 3eeb48ec3f45a6401215cc2b71761ba76d9a0af9 /routers | |
parent | 72fa108cbc0a3a7582ca7aaefc46787ec096640a (diff) | |
download | gitea-9c318a17f576887736e97c7bc2971d2ad7579a33.tar.gz gitea-9c318a17f576887736e97c7bc2971d2ad7579a33.zip |
Add `GetUserTeams` (#18499) (#18531)
Backport #18499
* Correct use `UserID` in `SearchTeams`
- Use `UserID` in the `SearchTeams` function, currently it was useless
to pass such information. Now it does a INNER statement to `team_user`
which obtains UserID -> TeamID data.
- Make OrgID optional.
- Resolves #18484
* Seperate searching specific user
* Add condition back
* Use correct struct type
Co-authored-by: Gusted <williamzijl7@hotmail.com>
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/org/team.go | 11 | ||||
-rw-r--r-- | routers/web/org/teams.go | 2 |
2 files changed, 6 insertions, 7 deletions
diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index cc7a63af33..62e6c0a6b4 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -47,7 +47,7 @@ func ListTeams(ctx *context.APIContext) { // "200": // "$ref": "#/responses/TeamList" - teams, count, err := models.SearchTeam(&models.SearchTeamOptions{ + teams, count, err := models.SearchOrgTeams(&models.SearchOrgTeamOptions{ ListOptions: utils.GetListOptions(ctx), OrgID: ctx.Org.Organization.ID, }) @@ -90,7 +90,7 @@ func ListUserTeams(ctx *context.APIContext) { // "200": // "$ref": "#/responses/TeamList" - teams, count, err := models.SearchTeam(&models.SearchTeamOptions{ + teams, count, err := models.GetUserTeams(&models.GetUserTeamOptions{ ListOptions: utils.GetListOptions(ctx), UserID: ctx.User.ID, }) @@ -533,7 +533,7 @@ func GetTeamRepos(ctx *context.APIContext) { // "$ref": "#/responses/RepositoryList" team := ctx.Org.Team - if err := team.GetRepositories(&models.SearchTeamOptions{ + if err := team.GetRepositories(&models.SearchOrgTeamOptions{ ListOptions: utils.GetListOptions(ctx), }); err != nil { ctx.Error(http.StatusInternalServerError, "GetTeamRepos", err) @@ -707,15 +707,14 @@ func SearchTeam(ctx *context.APIContext) { listOptions := utils.GetListOptions(ctx) - opts := &models.SearchTeamOptions{ - UserID: ctx.User.ID, + opts := &models.SearchOrgTeamOptions{ Keyword: ctx.FormTrim("q"), OrgID: ctx.Org.Organization.ID, IncludeDesc: ctx.FormString("include_desc") == "" || ctx.FormBool("include_desc"), ListOptions: listOptions, } - teams, maxResults, err := models.SearchTeam(opts) + teams, maxResults, err := models.SearchOrgTeams(opts) if err != nil { log.Error("SearchTeam failed: %v", err) ctx.JSON(http.StatusInternalServerError, map[string]interface{}{ diff --git a/routers/web/org/teams.go b/routers/web/org/teams.go index 732f24b22c..9b0212e569 100644 --- a/routers/web/org/teams.go +++ b/routers/web/org/teams.go @@ -319,7 +319,7 @@ func TeamRepositories(ctx *context.Context) { ctx.Data["Title"] = ctx.Org.Team.Name ctx.Data["PageIsOrgTeams"] = true ctx.Data["PageIsOrgTeamRepos"] = true - if err := ctx.Org.Team.GetRepositories(&models.SearchTeamOptions{}); err != nil { + if err := ctx.Org.Team.GetRepositories(&models.SearchOrgTeamOptions{}); err != nil { ctx.ServerError("GetRepositories", err) return } |