新增:组织团队新增全部项目和移除全部项目接口

This commit is contained in:
yystopf 2023-01-12 15:37:32 +08:00
parent b578e5b990
commit 6fe8614ffe
2 changed files with 88 additions and 0 deletions

View File

@ -158,6 +158,13 @@ func Routers(ctx gocontext.Context) *web.Route {
m.Combo("").Patch(reqToken(), reqOrgOwnership(), bind(hat_api.EditOrgOption{}), org.Edit)
}, orgAssignment(true))
m.Group("/teams/{teamid}", func() {
m.Group("/repos", func() {
m.Put("/{org}", org.AddTeamAllRepository)
m.Delete("/{org}", org.RemoveTeamAllRepository)
})
}, orgAssignment(false, true), reqToken(), reqTeamMembership())
m.Group("/admin", func() {
m.Group("/users", func() {
m.Group("/{username}", func() {
@ -397,6 +404,43 @@ func reqOrgOwnership() func(ctx *context.APIContext) {
}
}
// reqTeamMembership user should be an team member, or a site admin
func reqTeamMembership() func(ctx *context.APIContext) {
return func(ctx *context.APIContext) {
if ctx.Context.IsUserSiteAdmin() {
return
}
if ctx.Org.Team == nil {
ctx.Error(http.StatusInternalServerError, "", "reqTeamMembership: unprepared context")
return
}
orgID := ctx.Org.Team.OrgID
isOwner, err := organization.IsOrganizationOwner(ctx, orgID, ctx.Doer.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "IsOrganizationOwner", err)
return
} else if isOwner {
return
}
if isTeamMember, err := organization.IsTeamMember(ctx, orgID, ctx.Org.Team.ID, ctx.Doer.ID); err != nil {
ctx.Error(http.StatusInternalServerError, "IsTeamMember", err)
return
} else if !isTeamMember {
isOrgMember, err := organization.IsOrganizationMember(ctx, orgID, ctx.Doer.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "IsOrganizationMember", err)
} else if isOrgMember {
ctx.Error(http.StatusForbidden, "", "Must be a team member")
} else {
ctx.NotFound()
}
return
}
}
}
func reqWebhooksEnabled() func(ctx *context.APIContext) {
return func(ctx *context.APIContext) {
if setting.DisableWebhooks {

44
routers/hat/org/team.go Normal file
View File

@ -0,0 +1,44 @@
package org
import (
"net/http"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
)
func AddTeamAllRepository(ctx *context.APIContext) {
if ctx.Written() {
return
}
if ctx.Org.Team.IncludesAllRepositories {
ctx.Error(http.StatusForbidden, "", "Team include all repository not be allow to edit")
return
}
if err := models.AddAllRepositories(ctx.Org.Team); err != nil {
ctx.Error(http.StatusInternalServerError, "AddAllRepositories", err)
return
}
ctx.Status(http.StatusNoContent)
}
func RemoveTeamAllRepository(ctx *context.APIContext) {
if ctx.Written() {
return
}
if ctx.Org.Team.IncludesAllRepositories {
ctx.Error(http.StatusForbidden, "", "Team include all repository not be allow to edit")
return
}
if err := models.RemoveAllRepositories(ctx.Org.Team); err != nil {
ctx.Error(http.StatusInternalServerError, "RemoveAllRepositories", err)
return
}
ctx.Status(http.StatusNoContent)
}