diff options
author | Daniel Balko <inxonic@users.noreply.github.com> | 2018-11-23 22:23:27 +0100 |
---|---|---|
committer | techknowlogick <hello@techknowlogick.com> | 2018-11-23 16:23:27 -0500 |
commit | 3379141d818804aa8f7143ef32bd538c7e4ce795 (patch) | |
tree | 94af3ba725bc098fca5795b743707e83f14f647f /routers/api | |
parent | 49d9900b1fc05147ff109ab232d9cb2a52a8947f (diff) | |
download | gitea-3379141d818804aa8f7143ef32bd538c7e4ce795.tar.gz gitea-3379141d818804aa8f7143ef32bd538c7e4ce795.zip |
API: '/orgs/:org/repos': return private repos with read access (#5310) (#3829) (#5383)
Signed-off-by: Daniel Balko <inxonic+github@gmail.com>
Diffstat (limited to 'routers/api')
-rw-r--r-- | routers/api/v1/user/repo.go | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/routers/api/v1/user/repo.go b/routers/api/v1/user/repo.go index 38fe76cad4..5dccfac960 100644 --- a/routers/api/v1/user/repo.go +++ b/routers/api/v1/user/repo.go @@ -11,14 +11,13 @@ import ( ) // listUserRepos - List the repositories owned by the given user. -func listUserRepos(ctx *context.APIContext, u *models.User) { - showPrivateRepos := ctx.IsSigned && (ctx.User.ID == u.ID || ctx.User.IsAdmin) - repos, err := models.GetUserRepositories(u.ID, showPrivateRepos, 1, u.NumRepos, "") +func listUserRepos(ctx *context.APIContext, u *models.User, private bool) { + repos, err := models.GetUserRepositories(u.ID, private, 1, u.NumRepos, "") if err != nil { ctx.Error(500, "GetUserRepositories", err) return } - apiRepos := make([]*api.Repository, len(repos)) + apiRepos := make([]*api.Repository, 0, len(repos)) var ctxUserID int64 if ctx.User != nil { ctxUserID = ctx.User.ID @@ -29,7 +28,9 @@ func listUserRepos(ctx *context.APIContext, u *models.User) { ctx.Error(500, "AccessLevel", err) return } - apiRepos[i] = repos[i].APIFormat(access) + if ctx.IsSigned && ctx.User.IsAdmin || access >= models.AccessModeRead { + apiRepos = append(apiRepos, repos[i].APIFormat(access)) + } } ctx.JSON(200, &apiRepos) } @@ -54,7 +55,8 @@ func ListUserRepos(ctx *context.APIContext) { if ctx.Written() { return } - listUserRepos(ctx, user) + private := ctx.IsSigned && (ctx.User.ID == user.ID || ctx.User.IsAdmin) + listUserRepos(ctx, user, private) } // ListMyRepos - list the repositories you own or have access to. @@ -106,5 +108,5 @@ func ListOrgRepos(ctx *context.APIContext) { // responses: // "200": // "$ref": "#/responses/RepositoryList" - listUserRepos(ctx, ctx.Org.Organization) + listUserRepos(ctx, ctx.Org.Organization, ctx.IsSigned) } |