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