summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-11-22 01:32:09 -0500
committerUnknwon <u@gogs.io>2015-11-22 01:32:09 -0500
commit52c8f691630548fe091d30bcfe8164545a05d3d5 (patch)
tree12ad797f4c2f8ae6ea81e59e4a0e73ec76abaef3 /routers
parentb80e848d02b4e27e067910c03aadeddcbdd5f3f5 (diff)
downloadgitea-52c8f691630548fe091d30bcfe8164545a05d3d5.tar.gz
gitea-52c8f691630548fe091d30bcfe8164545a05d3d5.zip
fix #650
Diffstat (limited to 'routers')
-rw-r--r--routers/org/members.go2
-rw-r--r--routers/org/teams.go13
-rw-r--r--routers/user/home.go104
3 files changed, 44 insertions, 75 deletions
diff --git a/routers/org/members.go b/routers/org/members.go
index dd742bb7a2..a0a3051d4e 100644
--- a/routers/org/members.go
+++ b/routers/org/members.go
@@ -50,7 +50,7 @@ func MembersAction(ctx *middleware.Context) {
}
err = models.ChangeOrgUserStatus(org.Id, uid, false)
case "public":
- if ctx.User.Id != uid {
+ if ctx.User.Id != uid && !ctx.Org.IsOwner {
ctx.Error(404)
return
}
diff --git a/routers/org/teams.go b/routers/org/teams.go
index 6968512fed..2dd3c1981c 100644
--- a/routers/org/teams.go
+++ b/routers/org/teams.go
@@ -120,7 +120,7 @@ func TeamsRepoAction(ctx *middleware.Context) {
var err error
switch ctx.Params(":action") {
case "add":
- repoName := path.Base(ctx.Query("repo-name"))
+ repoName := path.Base(ctx.Query("repo_name"))
var repo *models.Repository
repo, err = models.GetRepositoryByName(ctx.Org.Organization.Id, repoName)
if err != nil {
@@ -280,9 +280,12 @@ func EditTeamPost(ctx *middleware.Context, form auth.CreateTeamForm) {
func DeleteTeam(ctx *middleware.Context) {
if err := models.DeleteTeam(ctx.Org.Team); err != nil {
- ctx.Handle(500, "DeleteTeam", err)
- return
+ ctx.Flash.Error("DeleteTeam: " + err.Error())
+ } else {
+ ctx.Flash.Success(ctx.Tr("org.teams.delete_team_success"))
}
- ctx.Flash.Success(ctx.Tr("org.teams.delete_team_success"))
- ctx.Redirect(ctx.Org.OrgLink + "/teams")
+
+ ctx.JSON(200, map[string]interface{}{
+ "redirect": ctx.Org.OrgLink + "/teams",
+ })
}
diff --git a/routers/user/home.go b/routers/user/home.go
index 96202ed080..39ceaed2e4 100644
--- a/routers/user/home.go
+++ b/routers/user/home.go
@@ -52,6 +52,37 @@ func getDashboardContextUser(ctx *middleware.Context) *models.User {
return ctxUser
}
+func retrieveFeeds(ctx *middleware.Context, uid, offset int64, isProfile bool) {
+ actions, err := models.GetFeeds(uid, offset, isProfile)
+ if err != nil {
+ ctx.Handle(500, "GetFeeds", err)
+ return
+ }
+
+ // Check access of private repositories.
+ feeds := make([]*models.Action, 0, len(actions))
+ unameAvatars := make(map[string]string)
+ for _, act := range actions {
+ // Cache results to reduce queries.
+ _, ok := unameAvatars[act.ActUserName]
+ if !ok {
+ u, err := models.GetUserByName(act.ActUserName)
+ if err != nil {
+ if models.IsErrUserNotExist(err) {
+ continue
+ }
+ ctx.Handle(500, "GetUserByName", err)
+ return
+ }
+ unameAvatars[act.ActUserName] = u.AvatarLink()
+ }
+
+ act.ActAvatar = unameAvatars[act.ActUserName]
+ feeds = append(feeds, act)
+ }
+ ctx.Data["Feeds"] = feeds
+}
+
func Dashboard(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("dashboard")
ctx.Data["PageIsDashboard"] = true
@@ -100,46 +131,10 @@ func Dashboard(ctx *middleware.Context) {
ctx.Data["MirrorCount"] = len(mirrors)
ctx.Data["Mirrors"] = mirrors
- // Get feeds.
- actions, err := models.GetFeeds(ctxUser.Id, 0, false)
- if err != nil {
- ctx.Handle(500, "GetFeeds", err)
+ retrieveFeeds(ctx, ctx.User.Id, 0, false)
+ if ctx.Written() {
return
}
-
- // Check access of private repositories.
- feeds := make([]*models.Action, 0, len(actions))
- unameAvatars := make(map[string]string)
- for _, act := range actions {
- if act.IsPrivate {
- // 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
- }
- }
-
- }
-
- // Cache results to reduce queries.
- _, ok := unameAvatars[act.ActUserName]
- if !ok {
- u, err := models.GetUserByName(act.ActUserName)
- if err != nil {
- if models.IsErrUserNotExist(err) {
- continue
- }
- ctx.Handle(500, "GetUserByName", err)
- return
- }
- unameAvatars[act.ActUserName] = u.AvatarLink()
- }
-
- act.ActAvatar = unameAvatars[act.ActUserName]
- feeds = append(feeds, act)
- }
- ctx.Data["Feeds"] = feeds
ctx.HTML(200, DASHBOARD)
}
@@ -356,39 +351,10 @@ func Profile(ctx *middleware.Context) {
ctx.Data["TabName"] = tab
switch tab {
case "activity":
- actions, err := models.GetFeeds(u.Id, 0, true)
- if err != nil {
- ctx.Handle(500, "GetFeeds", err)
+ retrieveFeeds(ctx, u.Id, 0, true)
+ if ctx.Written() {
return
}
- feeds := make([]*models.Action, 0, len(actions))
- for _, act := range actions {
- if act.IsPrivate {
- if !ctx.IsSigned {
- 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)
- if err != nil {
- if models.IsErrUserNotExist(err) {
- continue
- }
- ctx.Handle(500, "GetUserByName", err)
- return
- }
- act.ActAvatar = u.AvatarLink()
- feeds = append(feeds, act)
- }
- ctx.Data["Feeds"] = feeds
default:
ctx.Data["Repos"], err = models.GetRepositories(u.Id, ctx.IsSigned && ctx.User.Id == u.Id)
if err != nil {