From a913aff1d06d638ed2b54d2beaba00e88056e25f Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 12 May 2014 15:14:22 -0400 Subject: [PATCH] Show collaborative repositories in dashboard --- models/repo.go | 32 +++++++++++++++++++++++++++++++- routers/user/home.go | 11 +++++++++-- templates/user/dashboard.tmpl | 13 +++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/models/repo.go b/models/repo.go index 569c9571b7db..6e27a0cc125c 100644 --- a/models/repo.go +++ b/models/repo.go @@ -721,7 +721,7 @@ func GetRepositoryById(id int64) (*Repository, error) { return repo, nil } -// GetRepositories returns the list of repositories of given user. +// GetRepositories returns a list of repositories of given user. func GetRepositories(user *User, private bool) ([]*Repository, error) { repos := make([]*Repository, 0, 10) sess := orm.Desc("updated") @@ -758,6 +758,36 @@ func GetCollaboratorNames(repoName string) ([]string, error) { return names, nil } +// GetCollaborativeRepos returns a list of repositories that user is collaborator. +func GetCollaborativeRepos(uname string) ([]*Repository, error) { + uname = strings.ToLower(uname) + accesses := make([]*Access, 0, 10) + if err := orm.Find(&accesses, &Access{UserName: uname}); err != nil { + return nil, err + } + + repos := make([]*Repository, 0, 10) + for _, access := range accesses { + if strings.HasPrefix(access.RepoName, uname) { + continue + } + + infos := strings.Split(access.RepoName, "/") + u, err := GetUserByName(infos[0]) + if err != nil { + return nil, err + } + + repo, err := GetRepositoryByName(u.Id, infos[1]) + if err != nil { + return nil, err + } + repo.Owner = u + repos = append(repos, repo) + } + return repos, nil +} + // GetCollaborators returns a list of users of repository's collaborators. func GetCollaborators(repoName string) (us []*User, err error) { accesses := make([]*Access, 0, 10) diff --git a/routers/user/home.go b/routers/user/home.go index f5130f47a80c..0a805903ec91 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -22,14 +22,21 @@ func Dashboard(ctx *middleware.Context) { ctx.Data["PageIsUserDashboard"] = true repos, err := models.GetRepositories(&models.User{Id: ctx.User.Id}, true) if err != nil { - ctx.Handle(500, "user.Dashboard", err) + ctx.Handle(500, "home.Dashboard(GetRepositories)", err) return } ctx.Data["MyRepos"] = repos + collaRepos, err := models.GetCollaborativeRepos(ctx.User.Name) + if err != nil { + ctx.Handle(500, "home.Dashboard(GetCollaborativeRepos)", err) + return + } + ctx.Data["CollaborativeRepos"] = collaRepos + actions, err := models.GetFeeds(ctx.User.Id, 0, false) if err != nil { - ctx.Handle(500, "user.Dashboard", err) + ctx.Handle(500, "home.Dashboard", err) return } diff --git a/templates/user/dashboard.tmpl b/templates/user/dashboard.tmpl index 9781b8db1e3b..5cda6722f0a7 100644 --- a/templates/user/dashboard.tmpl +++ b/templates/user/dashboard.tmpl @@ -40,6 +40,7 @@ +
+ +
+
Collaborative Repositories
+
+
{{template "base/footer" .}}