mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-07 12:07:10 +02:00
add api routes and functions to get a repository group's subgroups and repos
This commit is contained in:
1 parent
243ff36900
commit
ab817e4251
4 files changed
+168
-7
No files matched your search
@@ -1806,6 +1806,8 @@ func Routes() *web.Router {
|
||||
Delete(reqToken(), reqGroupMembership(perm.AccessModeAdmin, false), group.DeleteGroup)
|
||||
m.Post("/move", reqToken(), reqGroupMembership(perm.AccessModeWrite, false), bind(api.MoveGroupOption{}), group.MoveGroup)
|
||||
m.Post("/new", reqToken(), reqGroupMembership(perm.AccessModeWrite, true), bind(api.NewGroupOption{}), group.NewSubGroup)
|
||||
m.Get("/subgroups", reqGroupMembership(perm.AccessModeRead, false), group.GetGroupSubGroups)
|
||||
m.Get("/repos", tokenRequiresScopes(auth_model.AccessTokenScopeCategoryRepository), reqGroupMembership(perm.AccessModeRead, false), group.GetGroupRepos)
|
||||
}, checkTokenPublicOnly())
|
||||
})
|
||||
return m
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
access_model "code.gitea.io/gitea/models/perm/access"
|
||||
shared_group_model "code.gitea.io/gitea/models/shared/group"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -265,8 +267,6 @@ func GetGroup(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/Group"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
var (
|
||||
err error
|
||||
group *group_model.Group
|
||||
@@ -318,3 +318,94 @@ func DeleteGroup(ctx *context.APIContext) {
|
||||
}
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func GetGroupRepos(ctx *context.APIContext) {
|
||||
// swagger:operation GET /groups/{group_id}/repos repository-group groupGetRepos
|
||||
// ---
|
||||
// summary: gets the repos contained within a group
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: group_id
|
||||
// in: path
|
||||
// description: id of the group containing the repositories
|
||||
// type: integer
|
||||
// format: int64
|
||||
// required: true
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/RepositoryList"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
gid := ctx.PathParamInt64("group_id")
|
||||
_, err := group_model.GetGroupByID(ctx, gid)
|
||||
if err != nil {
|
||||
if group_model.IsErrGroupNotExist(err) {
|
||||
ctx.APIErrorNotFound()
|
||||
} else {
|
||||
ctx.APIErrorInternal(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
groupRepos, err := shared_group_model.GetGroupRepos(ctx, gid, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
}
|
||||
repos := make([]*api.Repository, len(groupRepos))
|
||||
for i, repo := range groupRepos {
|
||||
permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
}
|
||||
repos[i] = convert.ToRepo(ctx, repo, permission)
|
||||
}
|
||||
ctx.SetTotalCountHeader(int64(len(repos)))
|
||||
ctx.JSON(http.StatusOK, repos)
|
||||
}
|
||||
|
||||
func GetGroupSubGroups(ctx *context.APIContext) {
|
||||
// swagger:operation GET /groups/{group_id}/subgroups repository-group groupGetSubGroups
|
||||
// ---
|
||||
// summary: gets the subgroups contained within a group
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: group_id
|
||||
// in: path
|
||||
// description: id of the parent group
|
||||
// type: integer
|
||||
// format: int64
|
||||
// required: true
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/GroupList"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
g, err := group_model.GetGroupByID(ctx, ctx.PathParamInt64("group_id"))
|
||||
if err != nil {
|
||||
if group_model.IsErrGroupNotExist(err) {
|
||||
ctx.APIErrorNotFound()
|
||||
} else {
|
||||
ctx.APIErrorInternal(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
err = g.LoadAccessibleSubgroups(ctx, false, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
}
|
||||
groups := make([]*api.Group, len(g.Subgroups))
|
||||
for i, group := range g.Subgroups {
|
||||
groups[i], err = convert.ToAPIGroup(ctx, group, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
ctx.SetTotalCountHeader(int64(len(groups)))
|
||||
ctx.JSON(http.StatusOK, groups)
|
||||
}
|
||||
Reference in new issue
Block a user