diff options
author | Unknwon <u@gogs.io> | 2015-02-28 21:50:29 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-02-28 21:50:29 -0500 |
commit | b0b11fd7b1bd5e556c27ccae73668b7df74cd73e (patch) | |
tree | 134a3b875952990ffe83f5b583d461b6b2e942df /routers/user/home.go | |
parent | 3a6ba39a61c68d967c6c08aa087d2de2d0bf7ec0 (diff) | |
parent | f44204e9449c09e0fef37a4974dc2f2043593d6f (diff) | |
download | gitea-b0b11fd7b1bd5e556c27ccae73668b7df74cd73e.tar.gz gitea-b0b11fd7b1bd5e556c27ccae73668b7df74cd73e.zip |
Merge branch 'access' of github.com:gogits/gogs into dev
Diffstat (limited to 'routers/user/home.go')
-rw-r--r-- | routers/user/home.go | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/routers/user/home.go b/routers/user/home.go index 1aabe08774..0a1d9dd217 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -49,13 +49,19 @@ func Dashboard(ctx *middleware.Context) { } else { // Normal user. ctxUser = ctx.User - collaborates, err := models.GetCollaborativeRepos(ctxUser.Name) + collaborates, err := ctx.User.GetAccessibleRepositories() if err != nil { - ctx.Handle(500, "GetCollaborativeRepos", err) + ctx.Handle(500, "GetAccessibleRepositories", err) return } - ctx.Data["CollaborateCount"] = len(collaborates) - ctx.Data["CollaborativeRepos"] = collaborates + + repositories := make([]*models.Repository, 0, len(collaborates)) + for repo := range collaborates { + repositories = append(repositories, repo) + } + + ctx.Data["CollaborateCount"] = len(repositories) + ctx.Data["CollaborativeRepos"] = repositories } ctx.Data["ContextUser"] = ctxUser @@ -97,10 +103,14 @@ func Dashboard(ctx *middleware.Context) { feeds := make([]*models.Action, 0, len(actions)) for _, act := range actions { if act.IsPrivate { - if has, _ := models.HasAccess(ctx.User.Name, act.RepoUserName+"/"+act.RepoName, - models.READABLE); !has { - continue + // This prevents having to retrieve the repository for each action + repo := &models.Repository{Id: act.RepoId, IsPrivate: true} + if act.RepoUserName != ctx.User.LowerName { + if has, _ := models.HasAccess(ctx.User, repo, models.ACCESS_MODE_READ); !has { + continue + } } + } // FIXME: cache results? u, err := models.GetUserByName(act.ActUserName) @@ -205,10 +215,14 @@ func Profile(ctx *middleware.Context) { if !ctx.IsSigned { continue } - if has, _ := models.HasAccess(ctx.User.Name, act.RepoUserName+"/"+act.RepoName, - models.READABLE); !has { - continue + // This prevents having to retrieve the repository for each action + repo := &models.Repository{Id: act.RepoId, IsPrivate: true} + if act.RepoUserName != ctx.User.LowerName { + if has, _ := models.HasAccess(ctx.User, repo, models.ACCESS_MODE_READ); !has { + continue + } } + } // FIXME: cache results? u, err := models.GetUserByName(act.ActUserName) |