From 83283bca4cb4e0f4ec48a28af680f0d88db3d2c8 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sat, 25 Oct 2014 07:50:19 -0400 Subject: Safe work --- routers/api/v1/repos.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'routers/api/v1/repos.go') diff --git a/routers/api/v1/repos.go b/routers/api/v1/repos.go index 37a3e47a..2dee512f 100644 --- a/routers/api/v1/repos.go +++ b/routers/api/v1/repos.go @@ -31,6 +31,26 @@ func SearchRepos(ctx *middleware.Context) { opt.Limit = 10 } + // Check visibility. + if ctx.IsSigned && opt.Uid > 0 { + if ctx.User.Id == opt.Uid { + opt.Private = true + } else { + u, err := models.GetUserById(opt.Uid) + if err != nil { + ctx.JSON(500, map[string]interface{}{ + "ok": false, + "error": err.Error(), + }) + return + } + if u.IsOrganization() && u.IsOrgOwner(ctx.User.Id) { + opt.Private = true + } + // FIXME: how about collaborators? + } + } + repos, err := models.SearchRepositoryByName(opt) if err != nil { ctx.JSON(500, map[string]interface{}{ -- cgit v1.2.3