diff --git a/README.md b/README.md
index ba2750371..a2e06c6fc 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
![](public/img/gogs-large-resize.png)
-##### Current version: 0.7.21 Beta
+##### Current version: 0.7.22 Beta
diff --git a/cmd/web.go b/cmd/web.go
index bf94ad195..791183fdb 100644
--- a/cmd/web.go
+++ b/cmd/web.go
@@ -395,7 +395,7 @@ func runWeb(ctx *cli.Context) {
m.Get("/teams/:team/repositories", org.TeamRepositories)
m.Route("/teams/:team/action/:action", "GET,POST", org.TeamsAction)
m.Route("/teams/:team/action/repo/:action", "GET,POST", org.TeamsRepoAction)
- }, middleware.OrgAssignment(true, true))
+ }, middleware.OrgAssignment(true))
m.Group("/:org", func() {
m.Get("/teams/new", org.NewTeam)
@@ -424,11 +424,8 @@ func runWeb(ctx *cli.Context) {
})
m.Route("/invitations/new", "GET,POST", org.Invitation)
- }, middleware.OrgAssignment(true, true, true))
+ }, middleware.OrgAssignment(true, true))
}, reqSignIn)
- m.Group("/org", func() {
- m.Get("/:org", org.Home)
- }, ignSignIn, middleware.OrgAssignment(true))
// ***** END: Organization *****
// ***** START: Repository *****
diff --git a/gogs.go b/gogs.go
index 581459940..47649e2cb 100644
--- a/gogs.go
+++ b/gogs.go
@@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting"
)
-const APP_VER = "0.7.21.1124 Beta"
+const APP_VER = "0.7.22.1124 Beta"
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
diff --git a/models/user.go b/models/user.go
index 892399c96..fa19e0c4b 100644
--- a/models/user.go
+++ b/models/user.go
@@ -145,9 +145,6 @@ func (u *User) DashboardLink() string {
// HomeLink returns the user or organization home page link.
func (u *User) HomeLink() string {
- if u.IsOrganization() {
- return setting.AppSubUrl + "/org/" + u.Name
- }
return setting.AppSubUrl + "/" + u.Name
}
diff --git a/modules/middleware/org.go b/modules/middleware/org.go
index 1e7d4a679..29754bb92 100644
--- a/modules/middleware/org.go
+++ b/modules/middleware/org.go
@@ -8,97 +8,94 @@ import (
"gopkg.in/macaron.v1"
"github.com/gogits/gogs/models"
- "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/setting"
)
-func OrgAssignment(redirect bool, args ...bool) macaron.Handler {
- return func(ctx *Context) {
- var (
- requireMember bool
- requireOwner bool
- requireAdminTeam bool
- )
- if len(args) >= 1 {
- requireMember = args[0]
- }
- if len(args) >= 2 {
- requireOwner = args[1]
- }
- if len(args) >= 3 {
- requireAdminTeam = args[2]
- }
+func HandleOrgAssignment(ctx *Context, args ...bool) {
+ var (
+ requireMember bool
+ requireOwner bool
+ requireAdminTeam bool
+ )
+ if len(args) >= 1 {
+ requireMember = args[0]
+ }
+ if len(args) >= 2 {
+ requireOwner = args[1]
+ }
+ if len(args) >= 3 {
+ requireAdminTeam = args[2]
+ }
- orgName := ctx.Params(":org")
+ orgName := ctx.Params(":org")
- var err error
- ctx.Org.Organization, err = models.GetUserByName(orgName)
- if err != nil {
- if models.IsErrUserNotExist(err) {
- ctx.Handle(404, "GetUserByName", err)
- } else if redirect {
- log.Error(4, "GetUserByName", err)
- ctx.Redirect(setting.AppSubUrl + "/")
- } else {
- ctx.Handle(500, "GetUserByName", err)
- }
- return
- }
- org := ctx.Org.Organization
- ctx.Data["Org"] = org
-
- // Force redirection when username is actually a user.
- if !org.IsOrganization() {
- ctx.Redirect("/" + org.Name)
- return
- }
-
- if ctx.IsSigned {
- ctx.Org.IsOwner = org.IsOwnedBy(ctx.User.Id)
- if ctx.Org.IsOwner {
- ctx.Org.IsMember = true
- ctx.Org.IsAdminTeam = true
- } else {
- if org.IsOrgMember(ctx.User.Id) {
- ctx.Org.IsMember = true
- }
- }
+ var err error
+ ctx.Org.Organization, err = models.GetUserByName(orgName)
+ if err != nil {
+ if models.IsErrUserNotExist(err) {
+ ctx.Handle(404, "GetUserByName", err)
} else {
- // Fake data.
- ctx.Data["SignedUser"] = &models.User{}
+ ctx.Handle(500, "GetUserByName", err)
}
- if (requireMember && !ctx.Org.IsMember) ||
- (requireOwner && !ctx.Org.IsOwner) {
- ctx.Handle(404, "OrgAssignment", err)
- return
- }
- ctx.Data["IsOrganizationOwner"] = ctx.Org.IsOwner
+ return
+ }
+ org := ctx.Org.Organization
+ ctx.Data["Org"] = org
- ctx.Org.OrgLink = setting.AppSubUrl + "/org/" + org.Name
- ctx.Data["OrgLink"] = ctx.Org.OrgLink
+ // Force redirection when username is actually a user.
+ if !org.IsOrganization() {
+ ctx.Redirect("/" + org.Name)
+ return
+ }
- // Team.
- teamName := ctx.Params(":team")
- if len(teamName) > 0 {
- ctx.Org.Team, err = org.GetTeam(teamName)
- if err != nil {
- if err == models.ErrTeamNotExist {
- ctx.Handle(404, "GetTeam", err)
- } else if redirect {
- log.Error(4, "GetTeam", err)
- ctx.Redirect(setting.AppSubUrl + "/")
- } else {
- ctx.Handle(500, "GetTeam", err)
- }
- return
+ if ctx.IsSigned {
+ ctx.Org.IsOwner = org.IsOwnedBy(ctx.User.Id)
+ if ctx.Org.IsOwner {
+ ctx.Org.IsMember = true
+ ctx.Org.IsAdminTeam = true
+ } else {
+ if org.IsOrgMember(ctx.User.Id) {
+ ctx.Org.IsMember = true
}
- ctx.Data["Team"] = ctx.Org.Team
- ctx.Org.IsAdminTeam = ctx.Org.Team.IsOwnerTeam() || ctx.Org.Team.Authorize >= models.ACCESS_MODE_ADMIN
}
- ctx.Data["IsAdminTeam"] = ctx.Org.IsAdminTeam
- if requireAdminTeam && !ctx.Org.IsAdminTeam {
- ctx.Handle(404, "OrgAssignment", err)
+ } else {
+ // Fake data.
+ ctx.Data["SignedUser"] = &models.User{}
+ }
+ if (requireMember && !ctx.Org.IsMember) ||
+ (requireOwner && !ctx.Org.IsOwner) {
+ ctx.Handle(404, "OrgAssignment", err)
+ return
+ }
+ ctx.Data["IsOrganizationOwner"] = ctx.Org.IsOwner
+
+ ctx.Org.OrgLink = setting.AppSubUrl + "/org/" + org.Name
+ ctx.Data["OrgLink"] = ctx.Org.OrgLink
+
+ // Team.
+ teamName := ctx.Params(":team")
+ if len(teamName) > 0 {
+ ctx.Org.Team, err = org.GetTeam(teamName)
+ if err != nil {
+ if err == models.ErrTeamNotExist {
+ ctx.Handle(404, "GetTeam", err)
+ } else {
+ ctx.Handle(500, "GetTeam", err)
+ }
return
}
+ ctx.Data["Team"] = ctx.Org.Team
+ ctx.Org.IsAdminTeam = ctx.Org.Team.IsOwnerTeam() || ctx.Org.Team.Authorize >= models.ACCESS_MODE_ADMIN
+ }
+ ctx.Data["IsAdminTeam"] = ctx.Org.IsAdminTeam
+ if requireAdminTeam && !ctx.Org.IsAdminTeam {
+ ctx.Handle(404, "OrgAssignment", err)
+ return
+ }
+}
+
+func OrgAssignment(args ...bool) macaron.Handler {
+ return func(ctx *Context) {
+ HandleOrgAssignment(ctx, args...)
}
}
diff --git a/routers/org/org.go b/routers/org/org.go
index d1c1940cb..dff11be47 100644
--- a/routers/org/org.go
+++ b/routers/org/org.go
@@ -14,36 +14,9 @@ import (
)
const (
- HOME base.TplName = "org/home"
CREATE base.TplName = "org/create"
)
-func Home(ctx *middleware.Context) {
- org := ctx.Org.Organization
- ctx.Data["Title"] = org.FullName
-
- repos, err := models.GetRepositories(org.Id, ctx.IsSigned && org.IsOrgMember(ctx.User.Id))
- if err != nil {
- ctx.Handle(500, "GetRepositories", err)
- return
- }
- ctx.Data["Repos"] = repos
-
- if err = org.GetMembers(); err != nil {
- ctx.Handle(500, "GetMembers", err)
- return
- }
- ctx.Data["Members"] = org.Members
-
- if err = org.GetTeams(); err != nil {
- ctx.Handle(500, "GetTeams", err)
- return
- }
- ctx.Data["Teams"] = org.Teams
-
- ctx.HTML(200, HOME)
-}
-
func Create(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("new_org")
ctx.HTML(200, CREATE)
diff --git a/routers/user/home.go b/routers/user/home.go
index 39ceaed2e..df567eaf2 100644
--- a/routers/user/home.go
+++ b/routers/user/home.go
@@ -23,6 +23,7 @@ const (
ISSUES base.TplName = "user/dashboard/issues"
STARS base.TplName = "user/stars"
PROFILE base.TplName = "user/profile"
+ ORG_HOME base.TplName = "org/home"
)
func getDashboardContextUser(ctx *middleware.Context) *models.User {
@@ -305,6 +306,38 @@ func ShowSSHKeys(ctx *middleware.Context, uid int64) {
ctx.PlainText(200, buf.Bytes())
}
+func showOrgProfile(ctx *middleware.Context) {
+ ctx.SetParams(":org", ctx.Params(":username"))
+ middleware.HandleOrgAssignment(ctx)
+ if ctx.Written() {
+ return
+ }
+
+ org := ctx.Org.Organization
+ ctx.Data["Title"] = org.FullName
+
+ repos, err := models.GetRepositories(org.Id, ctx.IsSigned && org.IsOrgMember(ctx.User.Id))
+ if err != nil {
+ ctx.Handle(500, "GetRepositories", err)
+ return
+ }
+ ctx.Data["Repos"] = repos
+
+ if err = org.GetMembers(); err != nil {
+ ctx.Handle(500, "GetMembers", err)
+ return
+ }
+ ctx.Data["Members"] = org.Members
+
+ if err = org.GetTeams(); err != nil {
+ ctx.Handle(500, "GetTeams", err)
+ return
+ }
+ ctx.Data["Teams"] = org.Teams
+
+ ctx.HTML(200, ORG_HOME)
+}
+
func Profile(ctx *middleware.Context) {
ctx.Data["Title"] = "Profile"
ctx.Data["PageIsUserProfile"] = true
@@ -342,7 +375,7 @@ func Profile(ctx *middleware.Context) {
}
if u.IsOrganization() {
- ctx.Redirect(setting.AppSubUrl + "/org/" + u.Name)
+ showOrgProfile(ctx)
return
}
ctx.Data["Owner"] = u
diff --git a/templates/.VERSION b/templates/.VERSION
index 5ca4043c1..06ee4e470 100644
--- a/templates/.VERSION
+++ b/templates/.VERSION
@@ -1 +1 @@
-0.7.21.1124 Beta
\ No newline at end of file
+0.7.22.1124 Beta
\ No newline at end of file
diff --git a/templates/org/header.tmpl b/templates/org/header.tmpl
index 68c25a986..c30433d96 100644
--- a/templates/org/header.tmpl
+++ b/templates/org/header.tmpl
@@ -4,7 +4,7 @@