aboutsummaryrefslogtreecommitdiff
path: root/modules/middleware
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2014-06-28 15:00:32 +0800
committerLunny Xiao <xiaolunwen@gmail.com>2014-06-28 15:00:32 +0800
commita357cda9575b482004329e81f0add6e4c32ab02a (patch)
treedb7d7508a039cfd4dd6cedad236e720bcfe1396c /modules/middleware
parent165e3e8f18bb7d38722d0c836ddbf8c95023cf67 (diff)
parent6e448b07145fbb090e0da6deb97f244c2bfd7ba7 (diff)
Merge branch 'dev' of github.com:gogits/gogs into dev
Diffstat (limited to 'modules/middleware')
-rw-r--r--modules/middleware/context.go10
-rw-r--r--modules/middleware/repo.go13
2 files changed, 10 insertions, 13 deletions
diff --git a/modules/middleware/context.go b/modules/middleware/context.go
index 8c837d08..45f0140a 100644
--- a/modules/middleware/context.go
+++ b/modules/middleware/context.go
@@ -104,12 +104,12 @@ func (ctx *Context) HasError() bool {
}
// HTML calls render.HTML underlying but reduce one argument.
-func (ctx *Context) HTML(status int, name string, htmlOpt ...HTMLOptions) {
- ctx.Render.HTML(status, name, ctx.Data, htmlOpt...)
+func (ctx *Context) HTML(status int, name base.TplName, htmlOpt ...HTMLOptions) {
+ ctx.Render.HTML(status, string(name), ctx.Data, htmlOpt...)
}
// RenderWithErr used for page has form validation but need to prompt error to users.
-func (ctx *Context) RenderWithErr(msg, tpl string, form auth.Form) {
+func (ctx *Context) RenderWithErr(msg string, tpl base.TplName, form auth.Form) {
if form != nil {
auth.AssignForm(form, ctx.Data)
}
@@ -133,7 +133,7 @@ func (ctx *Context) Handle(status int, title string, err error) {
case 500:
ctx.Data["Title"] = "Internal Server Error"
}
- ctx.HTML(status, fmt.Sprintf("status/%d", status))
+ ctx.HTML(status, base.TplName(fmt.Sprintf("status/%d", status)))
}
func (ctx *Context) Debug(msg string, args ...interface{}) {
@@ -358,7 +358,7 @@ func InitContext() martini.Handler {
})
// Get user from session if logined.
- user := auth.SignedInUser(ctx.Session)
+ user := auth.SignedInUser(ctx.req.Header, ctx.Session)
ctx.User = user
ctx.IsSigned = user != nil
diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go
index c1acc827..0c640275 100644
--- a/modules/middleware/repo.go
+++ b/modules/middleware/repo.go
@@ -21,21 +21,17 @@ import (
func RepoAssignment(redirect bool, args ...bool) martini.Handler {
return func(ctx *Context, params martini.Params) {
- log.Trace(fmt.Sprint(args))
// valid brachname
var validBranch bool
// display bare quick start if it is a bare repo
var displayBare bool
if len(args) >= 1 {
- // Note: argument has wrong value in Go1.3 martini.
- // validBranch = args[0]
- validBranch = true
+ validBranch = args[0]
}
if len(args) >= 2 {
- // displayBare = args[1]
- displayBare = true
+ displayBare = args[1]
}
var (
@@ -48,9 +44,10 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
repoName := params["reponame"]
refName := params["branchname"]
+ // TODO: need more advanced onwership and access level check.
// Collaborators who have write access can be seen as owners.
if ctx.IsSigned {
- ctx.Repo.IsOwner, err = models.HasAccess(ctx.User.Name, userName+"/"+repoName, models.AU_WRITABLE)
+ ctx.Repo.IsOwner, err = models.HasAccess(ctx.User.Name, userName+"/"+repoName, models.WRITABLE)
if err != nil {
ctx.Handle(500, "RepoAssignment(HasAccess)", err)
return
@@ -111,7 +108,7 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
return
}
- hasAccess, err := models.HasAccess(ctx.User.Name, ctx.Repo.Owner.Name+"/"+repo.Name, models.AU_READABLE)
+ hasAccess, err := models.HasAccess(ctx.User.Name, ctx.Repo.Owner.Name+"/"+repo.Name, models.READABLE)
if err != nil {
ctx.Handle(500, "RepoAssignment(HasAccess)", err)
return