summaryrefslogtreecommitdiffstats
path: root/routers/api
diff options
context:
space:
mode:
authorPeter Smit <peter@smitmail.eu>2015-01-23 09:54:16 +0200
committerPeter Smit <peter@smitmail.eu>2015-01-23 09:54:16 +0200
commit76f89047183fc70a077ac37b4168d90539f12e09 (patch)
tree4d57f8e0fa667a3a08f1ee55c49b9c0f95085844 /routers/api
parentc6b87aaf02b711d8b1ee7a40f57ba23f560e2a63 (diff)
downloadgitea-76f89047183fc70a077ac37b4168d90539f12e09.tar.gz
gitea-76f89047183fc70a077ac37b4168d90539f12e09.zip
Introducing Collaboration Struct
Diffstat (limited to 'routers/api')
-rw-r--r--routers/api/v1/repo.go21
1 files changed, 12 insertions, 9 deletions
diff --git a/routers/api/v1/repo.go b/routers/api/v1/repo.go
index fbf9c73ea7..469e4808fe 100644
--- a/routers/api/v1/repo.go
+++ b/routers/api/v1/repo.go
@@ -237,28 +237,31 @@ func ListMyRepos(ctx *middleware.Context) {
}
numOwnRepos := len(ownRepos)
- collaRepos, err := models.GetCollaborativeRepos(ctx.User.Name)
+ accessibleRepos, err := ctx.User.GetAccessibleRepositories()
if err != nil {
- ctx.JSON(500, &base.ApiJsonErr{"GetCollaborativeRepos: " + err.Error(), base.DOC_URL})
+ ctx.JSON(500, &base.ApiJsonErr{"GetAccessibleRepositories: " + err.Error(), base.DOC_URL})
return
}
- repos := make([]*api.Repository, numOwnRepos+len(collaRepos))
+ repos := make([]*api.Repository, numOwnRepos+len(accessibleRepos))
for i := range ownRepos {
repos[i] = ToApiRepository(ctx.User, ownRepos[i], api.Permission{true, true, true})
}
- for i := range collaRepos {
- if err = collaRepos[i].GetOwner(); err != nil {
+ i := numOwnRepos
+
+ for repo, access := range accessibleRepos {
+ if err = repo.GetOwner(); err != nil {
ctx.JSON(500, &base.ApiJsonErr{"GetOwner: " + err.Error(), base.DOC_URL})
return
}
- j := i + numOwnRepos
- repos[j] = ToApiRepository(collaRepos[i].Owner, collaRepos[i].Repository, api.Permission{false, collaRepos[i].CanPush, true})
+
+ repos[i] = ToApiRepository(repo.Owner, repo, api.Permission{false, access >= models.WRITABLE, true})
// FIXME: cache result to reduce DB query?
- if collaRepos[i].Owner.IsOrganization() && collaRepos[i].Owner.IsOwnedBy(ctx.User.Id) {
- repos[j].Permissions.Admin = true
+ if repo.Owner.IsOrganization() && repo.Owner.IsOwnedBy(ctx.User.Id) {
+ repos[i].Permissions.Admin = true
}
+ i++
}
ctx.JSON(200, &repos)