mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 00:20:25 +08:00 
			
		
		
		
	Add GetUserTeams (#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: 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>
This commit is contained in:
		@@ -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{}{
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user