summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorUnknwon <joe2010xtmf@163.com>2014-08-14 14:12:21 +0800
committerUnknwon <joe2010xtmf@163.com>2014-08-14 14:12:21 +0800
commit5acc948562547b393ba1e89b012e7421143c6dd8 (patch)
tree657653112b206fb01ff184bd30cb680b5b5a21fa /modules
parent2935ee440c82a7f998a74159255cc38924f6e0bc (diff)
downloadgitea-5acc948562547b393ba1e89b012e7421143c6dd8.tar.gz
gitea-5acc948562547b393ba1e89b012e7421143c6dd8.zip
Page: `/org/:orgname/settings`
Diffstat (limited to 'modules')
-rw-r--r--modules/auth/org.go10
-rw-r--r--modules/auth/user_form.go4
-rw-r--r--modules/middleware/context.go6
-rw-r--r--modules/middleware/org.go55
-rw-r--r--modules/middleware/repo.go15
5 files changed, 75 insertions, 15 deletions
diff --git a/modules/auth/org.go b/modules/auth/org.go
index 0895780e3f..9598e6f834 100644
--- a/modules/auth/org.go
+++ b/modules/auth/org.go
@@ -27,15 +27,17 @@ func (f *CreateOrgForm) Validate(ctx *macaron.Context, errs *binding.Errors, l i
validate(errs, ctx.Data, f, l)
}
-type OrgSettingForm struct {
- DisplayName string `form:"display_name" binding:"Required;MaxSize(100)"`
+type UpdateOrgSettingForm struct {
+ OrgUserName string `form:"uname" binding:"Required;MaxSize(35)"`
+ OrgFullName string `form:"fullname" binding:"MaxSize(100)"`
Email string `form:"email" binding:"Required;Email;MaxSize(50)"`
Description string `form:"desc" binding:"MaxSize(255)"`
- Website string `form:"site" binding:"Url;MaxSize(100)"`
+ Website string `form:"website" binding:"Url;MaxSize(100)"`
Location string `form:"location" binding:"MaxSize(50)"`
+ Avatar string `form:"avatar" binding:"Required;Email;MaxSize(50)"`
}
-func (f *OrgSettingForm) Validate(ctx *macaron.Context, errs *binding.Errors, l i18n.Locale) {
+func (f *UpdateOrgSettingForm) Validate(ctx *macaron.Context, errs *binding.Errors, l i18n.Locale) {
validate(errs, ctx.Data, f, l)
}
diff --git a/modules/auth/user_form.go b/modules/auth/user_form.go
index df713b570f..51a07b9128 100644
--- a/modules/auth/user_form.go
+++ b/modules/auth/user_form.go
@@ -76,9 +76,9 @@ func (f *SignInForm) Validate(ctx *macaron.Context, errs *binding.Errors, l i18n
type UpdateProfileForm struct {
UserName string `form:"uname" binding:"Required;MaxSize(35)"`
- FullName string `form:"fullname" binding:"MaxSize(40)"`
+ FullName string `form:"fullname" binding:"MaxSize(100)"`
Email string `form:"email" binding:"Required;Email;MaxSize(50)"`
- Website string `form:"website" binding:"Url;MaxSize(50)"`
+ Website string `form:"website" binding:"Url;MaxSize(100)"`
Location string `form:"location" binding:"MaxSize(50)"`
Avatar string `form:"avatar" binding:"Required;Email;MaxSize(50)"`
}
diff --git a/modules/middleware/context.go b/modules/middleware/context.go
index 1e6f8e9525..aa1266d649 100644
--- a/modules/middleware/context.go
+++ b/modules/middleware/context.go
@@ -64,6 +64,12 @@ type Context struct {
CommitsCount int
Mirror *models.Mirror
}
+
+ Org struct {
+ IsOwner bool
+ IsMember bool
+ Organization *models.User
+ }
}
// Query querys form parameter.
diff --git a/modules/middleware/org.go b/modules/middleware/org.go
new file mode 100644
index 0000000000..05316a518f
--- /dev/null
+++ b/modules/middleware/org.go
@@ -0,0 +1,55 @@
+// Copyright 2014 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package middleware
+
+import (
+ "github.com/Unknwon/macaron"
+
+ "github.com/gogits/gogs/models"
+)
+
+func OrgAssignment(redirect bool, args ...bool) macaron.Handler {
+ return func(ctx *Context) {
+ var (
+ requireMember bool
+ requireOwner bool
+ )
+ if len(args) >= 1 {
+ requireMember = args[0]
+ }
+ if len(args) >= 2 {
+ requireOwner = args[1]
+ }
+
+ orgName := ctx.Params(":org")
+
+ var err error
+ ctx.Org.Organization, err = models.GetUserByName(orgName)
+ if err != nil {
+ if err == models.ErrUserNotExist {
+ ctx.Handle(404, "GetUserByName", err)
+ } else if redirect {
+ ctx.Redirect("/")
+ } else {
+ ctx.Handle(500, "GetUserByName", err)
+ }
+ return
+ }
+ ctx.Data["Org"] = ctx.Org.Organization
+
+ if ctx.IsSigned {
+ ctx.Org.IsOwner = ctx.Org.Organization.IsOrgOwner(ctx.User.Id)
+ if ctx.Org.IsOwner {
+ ctx.Org.IsMember = true
+ } else {
+ ctx.Org.IsMember = ctx.Org.Organization.IsOrgMember(ctx.User.Id)
+ }
+ }
+ if (requireMember && !ctx.Org.IsMember) || (requireOwner && !ctx.Org.IsOwner) {
+ ctx.Handle(404, "OrgAssignment", err)
+ return
+ }
+ }
+}
diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go
index 929850d202..a028aab802 100644
--- a/modules/middleware/repo.go
+++ b/modules/middleware/repo.go
@@ -20,15 +20,13 @@ import (
func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
return func(ctx *Context) {
- // To valid brach name.
- var validBranch bool
- // To display bare quick start if it is a bare repo.
- var displayBare bool
-
+ var (
+ validBranch bool // To valid brach name.
+ displayBare bool // To display bare page if it is a bare repo.
+ )
if len(args) >= 1 {
validBranch = args[0]
}
-
if len(args) >= 2 {
displayBare = args[1]
}
@@ -60,12 +58,11 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
if err != nil {
if err == models.ErrUserNotExist {
ctx.Handle(404, "GetUserByName", err)
- return
} else if redirect {
ctx.Redirect("/")
- return
+ } else {
+ ctx.Handle(500, "GetUserByName", err)
}
- ctx.Handle(500, "GetUserByName", err)
return
}
} else {