summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
Diffstat (limited to 'routers')
-rw-r--r--routers/org/org.go38
-rw-r--r--routers/repo/repo.go20
-rw-r--r--routers/user/home.go6
3 files changed, 60 insertions, 4 deletions
diff --git a/routers/org/org.go b/routers/org/org.go
index 7b2c4d7320..ba4adc5b5a 100644
--- a/routers/org/org.go
+++ b/routers/org/org.go
@@ -16,13 +16,45 @@ import (
)
const (
+ HOME base.TplName = "org/home"
NEW base.TplName = "org/new"
SETTINGS base.TplName = "org/settings"
)
-func Organization(ctx *middleware.Context, params martini.Params) {
+func Home(ctx *middleware.Context, params martini.Params) {
ctx.Data["Title"] = "Organization " + params["org"]
- ctx.HTML(200, "org/org")
+
+ org, err := models.GetUserByName(params["org"])
+ if err != nil {
+ if err == models.ErrUserNotExist {
+ ctx.Handle(404, "org.Home(GetUserByName)", err)
+ } else {
+ ctx.Handle(500, "org.Home(GetUserByName)", err)
+ }
+ return
+ }
+ ctx.Data["Org"] = org
+
+ ctx.Data["Repos"], err = models.GetRepositories(org.Id,
+ ctx.IsSigned && models.IsOrganizationMember(org.Id, ctx.User.Id))
+ if err != nil {
+ ctx.Handle(500, "org.Home(GetRepositories)", err)
+ return
+ }
+
+ if err = org.GetMembers(); err != nil {
+ ctx.Handle(500, "org.Home(GetMembers)", err)
+ return
+ }
+ ctx.Data["Members"] = org.Members
+
+ if err = org.GetTeams(); err != nil {
+ ctx.Handle(500, "org.Home(GetTeams)", err)
+ return
+ }
+ ctx.Data["Teams"] = org.Teams
+
+ ctx.HTML(200, HOME)
}
func Members(ctx *middleware.Context, params martini.Params) {
@@ -63,7 +95,7 @@ func NewPost(ctx *middleware.Context, form auth.CreateOrgForm) {
ctx.Data["Err_OrgName"] = true
ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), NEW, &form)
default:
- ctx.Handle(500, "user.NewPost(CreateUser)", err)
+ ctx.Handle(500, "org.NewPost(CreateUser)", err)
}
return
}
diff --git a/routers/repo/repo.go b/routers/repo/repo.go
index 6cb6c0660e..54e5fcfb20 100644
--- a/routers/repo/repo.go
+++ b/routers/repo/repo.go
@@ -37,11 +37,23 @@ func Create(ctx *middleware.Context) {
ctx.Data["LanguageIgns"] = models.LanguageIgns
ctx.Data["Licenses"] = models.Licenses
+ ctxUser := ctx.User
+ orgId, _ := base.StrTo(ctx.Query("org")).Int64()
+ if orgId > 0 {
+ org, err := models.GetUserById(orgId)
+ if err != nil && err != models.ErrUserNotExist {
+ ctx.Handle(500, "home.Dashboard(GetUserById)", err)
+ return
+ }
+ ctxUser = org
+ }
+ ctx.Data["ContextUser"] = ctxUser
+
if err := ctx.User.GetOrganizations(); err != nil {
ctx.Handle(500, "home.Dashboard(GetOrganizations)", err)
return
}
- ctx.Data["Orgs"] = ctx.User.Orgs
+ ctx.Data["AllUsers"] = append([]*models.User{ctx.User}, ctx.User.Orgs...)
ctx.HTML(200, CREATE)
}
@@ -76,6 +88,12 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) {
}
return
}
+
+ // Check ownership of organization.
+ if !models.IsOrganizationOwner(u.Id, ctx.User.Id) {
+ ctx.Error(403)
+ return
+ }
}
repo, err := models.CreateRepository(u, form.RepoName, form.Description,
diff --git a/routers/user/home.go b/routers/user/home.go
index 86907b5a90..02dc1de154 100644
--- a/routers/user/home.go
+++ b/routers/user/home.go
@@ -83,6 +83,12 @@ func Profile(ctx *middleware.Context, params martini.Params) {
}
return
}
+
+ if u.IsOrganization() {
+ ctx.Redirect("/org/" + u.Name)
+ return
+ }
+
// For security reason, hide e-mail address for anonymous visitors.
if !ctx.IsSigned {
u.Email = ""