mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Never use /api/v1 from Gitea UI Pages (#19318)
Reusing `/api/v1` from Gitea UI Pages have pros and cons. Pros: 1) Less code copy Cons: 1) API/v1 have to support shared session with page requests. 2) You need to consider for each other when you want to change something about api/v1 or page. This PR moves all dependencies to API/v1 from UI Pages. Partially replace #16052
This commit is contained in:
		@@ -13,6 +13,7 @@ import (
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"code.gitea.io/gitea/models"
 | 
			
		||||
	"code.gitea.io/gitea/models/db"
 | 
			
		||||
	"code.gitea.io/gitea/models/organization"
 | 
			
		||||
	"code.gitea.io/gitea/models/perm"
 | 
			
		||||
	repo_model "code.gitea.io/gitea/models/repo"
 | 
			
		||||
@@ -20,7 +21,9 @@ import (
 | 
			
		||||
	user_model "code.gitea.io/gitea/models/user"
 | 
			
		||||
	"code.gitea.io/gitea/modules/base"
 | 
			
		||||
	"code.gitea.io/gitea/modules/context"
 | 
			
		||||
	"code.gitea.io/gitea/modules/convert"
 | 
			
		||||
	"code.gitea.io/gitea/modules/log"
 | 
			
		||||
	api "code.gitea.io/gitea/modules/structs"
 | 
			
		||||
	"code.gitea.io/gitea/modules/web"
 | 
			
		||||
	"code.gitea.io/gitea/routers/utils"
 | 
			
		||||
	"code.gitea.io/gitea/services/forms"
 | 
			
		||||
@@ -329,6 +332,51 @@ func TeamRepositories(ctx *context.Context) {
 | 
			
		||||
	ctx.HTML(http.StatusOK, tplTeamRepositories)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SearchTeam api for searching teams
 | 
			
		||||
func SearchTeam(ctx *context.Context) {
 | 
			
		||||
	listOptions := db.ListOptions{
 | 
			
		||||
		Page:     ctx.FormInt("page"),
 | 
			
		||||
		PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")),
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	opts := &organization.SearchTeamOptions{
 | 
			
		||||
		UserID:      ctx.Doer.ID,
 | 
			
		||||
		Keyword:     ctx.FormTrim("q"),
 | 
			
		||||
		OrgID:       ctx.Org.Organization.ID,
 | 
			
		||||
		IncludeDesc: ctx.FormString("include_desc") == "" || ctx.FormBool("include_desc"),
 | 
			
		||||
		ListOptions: listOptions,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	teams, maxResults, err := organization.SearchTeam(opts)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Error("SearchTeam failed: %v", err)
 | 
			
		||||
		ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
 | 
			
		||||
			"ok":    false,
 | 
			
		||||
			"error": "SearchTeam internal failure",
 | 
			
		||||
		})
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	apiTeams := make([]*api.Team, len(teams))
 | 
			
		||||
	for i := range teams {
 | 
			
		||||
		if err := teams[i].GetUnits(); err != nil {
 | 
			
		||||
			log.Error("Team GetUnits failed: %v", err)
 | 
			
		||||
			ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
 | 
			
		||||
				"ok":    false,
 | 
			
		||||
				"error": "SearchTeam failed to get units",
 | 
			
		||||
			})
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		apiTeams[i] = convert.ToTeam(teams[i])
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ctx.SetTotalCountHeader(maxResults)
 | 
			
		||||
	ctx.JSON(http.StatusOK, map[string]interface{}{
 | 
			
		||||
		"ok":   true,
 | 
			
		||||
		"data": apiTeams,
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// EditTeam render team edit page
 | 
			
		||||
func EditTeam(ctx *context.Context) {
 | 
			
		||||
	ctx.Data["Title"] = ctx.Org.Organization.FullName
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user