summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorBwko <bouwko@gmail.com>2017-08-23 03:30:54 +0200
committerLunny Xiao <xiaolunwen@gmail.com>2017-08-23 09:30:54 +0800
commit1a5fe4326f1166eac447cb598db34f7ae348d610 (patch)
tree0ca4412138469051eda63a981b32353e2139698e /routers
parentfaf4b503b24d33a2a0f455d26bb782345ab8e0c9 (diff)
downloadgitea-1a5fe4326f1166eac447cb598db34f7ae348d610.tar.gz
gitea-1a5fe4326f1166eac447cb598db34f7ae348d610.zip
Add collaborative repositories to the dashboard (#2205)
* Add collaborative repositories to the dashboard Remove some unused code from the Dashboard func * fix some bug and some refactor * fix tests
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/repo/repo.go6
-rw-r--r--routers/user/home.go50
-rw-r--r--routers/user/profile.go7
3 files changed, 21 insertions, 42 deletions
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index e8bf026511..305daa064d 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -42,6 +42,7 @@ func Search(ctx *context.APIContext) {
if ctx.IsSigned && opts.OwnerID > 0 {
if ctx.User.ID == opts.OwnerID {
opts.Private = true
+ opts.Collaborate = true
} else {
u, err := models.GetUserByID(opts.OwnerID)
if err != nil {
@@ -54,7 +55,10 @@ func Search(ctx *context.APIContext) {
if u.IsOrganization() && u.IsOwnedBy(ctx.User.ID) {
opts.Private = true
}
- // FIXME: how about collaborators?
+
+ if !u.IsOrganization() {
+ opts.Collaborate = true
+ }
}
}
diff --git a/routers/user/home.go b/routers/user/home.go
index 43f4087fe5..409465c0b4 100644
--- a/routers/user/home.go
+++ b/routers/user/home.go
@@ -54,24 +54,14 @@ func getDashboardContextUser(ctx *context.Context) *models.User {
}
// retrieveFeeds loads feeds for the specified user
-func retrieveFeeds(ctx *context.Context, user *models.User, includePrivate, isProfile bool, includeDeletedComments bool) {
- var requestingID int64
- if ctx.User != nil {
- requestingID = ctx.User.ID
- }
- actions, err := models.GetFeeds(models.GetFeedsOptions{
- RequestedUser: user,
- RequestingUserID: requestingID,
- IncludePrivate: includePrivate,
- OnlyPerformedBy: isProfile,
- IncludeDeleted: includeDeletedComments,
- })
+func retrieveFeeds(ctx *context.Context, options models.GetFeedsOptions) {
+ actions, err := models.GetFeeds(options)
if err != nil {
ctx.Handle(500, "GetFeeds", err)
return
}
- userCache := map[int64]*models.User{user.ID: user}
+ userCache := map[int64]*models.User{options.RequestedUser.ID: options.RequestedUser}
if ctx.User != nil {
userCache[ctx.User.ID] = ctx.User
}
@@ -133,32 +123,14 @@ func Dashboard(ctx *context.Context) {
ctx.Data["PageIsNews"] = true
ctx.Data["SearchLimit"] = setting.UI.User.RepoPagingNum
- // Only user can have collaborative repositories.
- if !ctxUser.IsOrganization() {
- collaborateRepos, err := ctx.User.GetAccessibleRepositories(setting.UI.User.RepoPagingNum)
- if err != nil {
- ctx.Handle(500, "GetAccessibleRepositories", err)
- return
- } else if err = models.RepositoryList(collaborateRepos).LoadAttributes(); err != nil {
- ctx.Handle(500, "RepositoryList.LoadAttributes", err)
- return
- }
- ctx.Data["CollaborativeRepos"] = collaborateRepos
- }
-
var err error
- var repos, mirrors []*models.Repository
+ var mirrors []*models.Repository
if ctxUser.IsOrganization() {
env, err := ctxUser.AccessibleReposEnv(ctx.User.ID)
if err != nil {
ctx.Handle(500, "AccessibleReposEnv", err)
return
}
- repos, err = env.Repos(1, setting.UI.User.RepoPagingNum)
- if err != nil {
- ctx.Handle(500, "env.Repos", err)
- return
- }
mirrors, err = env.MirrorRepos()
if err != nil {
@@ -166,19 +138,12 @@ func Dashboard(ctx *context.Context) {
return
}
} else {
- if err = ctxUser.GetRepositories(1, setting.UI.User.RepoPagingNum); err != nil {
- ctx.Handle(500, "GetRepositories", err)
- return
- }
- repos = ctxUser.Repos
-
mirrors, err = ctxUser.GetMirrorRepositories()
if err != nil {
ctx.Handle(500, "GetMirrorRepositories", err)
return
}
}
- ctx.Data["Repos"] = repos
ctx.Data["MaxShowRepoNum"] = setting.UI.User.RepoPagingNum
if err := models.MirrorRepositoryList(mirrors).LoadAttributes(); err != nil {
@@ -188,7 +153,12 @@ func Dashboard(ctx *context.Context) {
ctx.Data["MirrorCount"] = len(mirrors)
ctx.Data["Mirrors"] = mirrors
- retrieveFeeds(ctx, ctxUser, true, false, false)
+ retrieveFeeds(ctx, models.GetFeedsOptions{RequestedUser: ctxUser,
+ IncludePrivate: true,
+ OnlyPerformedBy: false,
+ Collaborate: true,
+ IncludeDeleted: false,
+ })
if ctx.Written() {
return
}
diff --git a/routers/user/profile.go b/routers/user/profile.go
index 1850286411..f56ddc4eab 100644
--- a/routers/user/profile.go
+++ b/routers/user/profile.go
@@ -138,7 +138,12 @@ func Profile(ctx *context.Context) {
ctx.Data["Keyword"] = keyword
switch tab {
case "activity":
- retrieveFeeds(ctx, ctxUser, showPrivate, true, false)
+ retrieveFeeds(ctx, models.GetFeedsOptions{RequestedUser: ctxUser,
+ IncludePrivate: showPrivate,
+ OnlyPerformedBy: true,
+ Collaborate: true,
+ IncludeDeleted: false,
+ })
if ctx.Written() {
return
}