|
1 | 1 | package group
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + access_model "code.gitea.io/gitea/models/perm/access" |
| 5 | + shared_group_model "code.gitea.io/gitea/models/shared/group" |
4 | 6 | "fmt"
|
5 | 7 | "net/http"
|
6 | 8 | "strings"
|
@@ -265,8 +267,6 @@ func GetGroup(ctx *context.APIContext) {
|
265 | 267 | // "$ref": "#/responses/Group"
|
266 | 268 | // "404":
|
267 | 269 | // "$ref": "#/responses/notFound"
|
268 |
| - // "422": |
269 |
| - // "$ref": "#/responses/validationError" |
270 | 270 | var (
|
271 | 271 | err error
|
272 | 272 | group *group_model.Group
|
@@ -318,3 +318,94 @@ func DeleteGroup(ctx *context.APIContext) {
|
318 | 318 | }
|
319 | 319 | ctx.Status(http.StatusNoContent)
|
320 | 320 | }
|
| 321 | + |
| 322 | +func GetGroupRepos(ctx *context.APIContext) { |
| 323 | + // swagger:operation GET /groups/{group_id}/repos repository-group groupGetRepos |
| 324 | + // --- |
| 325 | + // summary: gets the repos contained within a group |
| 326 | + // produces: |
| 327 | + // - application/json |
| 328 | + // parameters: |
| 329 | + // - name: group_id |
| 330 | + // in: path |
| 331 | + // description: id of the group containing the repositories |
| 332 | + // type: integer |
| 333 | + // format: int64 |
| 334 | + // required: true |
| 335 | + // responses: |
| 336 | + // "200": |
| 337 | + // "$ref": "#/responses/RepositoryList" |
| 338 | + // "404": |
| 339 | + // "$ref": "#/responses/notFound" |
| 340 | + gid := ctx.PathParamInt64("group_id") |
| 341 | + _, err := group_model.GetGroupByID(ctx, gid) |
| 342 | + if err != nil { |
| 343 | + if group_model.IsErrGroupNotExist(err) { |
| 344 | + ctx.APIErrorNotFound() |
| 345 | + } else { |
| 346 | + ctx.APIErrorInternal(err) |
| 347 | + } |
| 348 | + return |
| 349 | + } |
| 350 | + |
| 351 | + groupRepos, err := shared_group_model.GetGroupRepos(ctx, gid, ctx.Doer) |
| 352 | + if err != nil { |
| 353 | + ctx.APIErrorInternal(err) |
| 354 | + return |
| 355 | + } |
| 356 | + repos := make([]*api.Repository, len(groupRepos)) |
| 357 | + for i, repo := range groupRepos { |
| 358 | + permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer) |
| 359 | + if err != nil { |
| 360 | + ctx.APIErrorInternal(err) |
| 361 | + return |
| 362 | + } |
| 363 | + repos[i] = convert.ToRepo(ctx, repo, permission) |
| 364 | + } |
| 365 | + ctx.SetTotalCountHeader(int64(len(repos))) |
| 366 | + ctx.JSON(http.StatusOK, repos) |
| 367 | +} |
| 368 | + |
| 369 | +func GetGroupSubGroups(ctx *context.APIContext) { |
| 370 | + // swagger:operation GET /groups/{group_id}/subgroups repository-group groupGetSubGroups |
| 371 | + // --- |
| 372 | + // summary: gets the subgroups contained within a group |
| 373 | + // produces: |
| 374 | + // - application/json |
| 375 | + // parameters: |
| 376 | + // - name: group_id |
| 377 | + // in: path |
| 378 | + // description: id of the parent group |
| 379 | + // type: integer |
| 380 | + // format: int64 |
| 381 | + // required: true |
| 382 | + // responses: |
| 383 | + // "200": |
| 384 | + // "$ref": "#/responses/GroupList" |
| 385 | + // "404": |
| 386 | + // "$ref": "#/responses/notFound" |
| 387 | + g, err := group_model.GetGroupByID(ctx, ctx.PathParamInt64("group_id")) |
| 388 | + if err != nil { |
| 389 | + if group_model.IsErrGroupNotExist(err) { |
| 390 | + ctx.APIErrorNotFound() |
| 391 | + } else { |
| 392 | + ctx.APIErrorInternal(err) |
| 393 | + } |
| 394 | + return |
| 395 | + } |
| 396 | + err = g.LoadAccessibleSubgroups(ctx, false, ctx.Doer) |
| 397 | + if err != nil { |
| 398 | + ctx.APIErrorInternal(err) |
| 399 | + return |
| 400 | + } |
| 401 | + groups := make([]*api.Group, len(g.Subgroups)) |
| 402 | + for i, group := range g.Subgroups { |
| 403 | + groups[i], err = convert.ToAPIGroup(ctx, group, ctx.Doer) |
| 404 | + if err != nil { |
| 405 | + ctx.APIErrorInternal(err) |
| 406 | + return |
| 407 | + } |
| 408 | + } |
| 409 | + ctx.SetTotalCountHeader(int64(len(groups))) |
| 410 | + ctx.JSON(http.StatusOK, groups) |
| 411 | +} |
0 commit comments