diff --git a/models/repo.go b/models/repo.go index 569c9571b7..6e27a0cc12 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 f5130f47a8..0a805903ec 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 9781b8db1e..5cda6722f0 100644 --- a/templates/user/dashboard.tmpl +++ b/templates/user/dashboard.tmpl @@ -40,6 +40,7 @@ +