summaryrefslogtreecommitdiffstats
path: root/modules/middleware
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-11-27 01:50:38 -0500
committerUnknwon <u@gogs.io>2015-11-27 01:50:38 -0500
commite42fcb033d4a7ee44fe397be3e933d7031b7d8f7 (patch)
treea203fff39c92f947c4585a746e2345b3ebc67b3c /modules/middleware
parent392f3ee21016476fb9794f78882d6c447acb8449 (diff)
downloadgitea-e42fcb033d4a7ee44fe397be3e933d7031b7d8f7.tar.gz
gitea-e42fcb033d4a7ee44fe397be3e933d7031b7d8f7.zip
wiki: finish edit
Diffstat (limited to 'modules/middleware')
-rw-r--r--modules/middleware/context.go13
-rw-r--r--modules/middleware/repo.go18
2 files changed, 21 insertions, 10 deletions
diff --git a/modules/middleware/context.go b/modules/middleware/context.go
index 4b217b6349..4f7c438382 100644
--- a/modules/middleware/context.go
+++ b/modules/middleware/context.go
@@ -59,7 +59,7 @@ type Context struct {
IsSigned bool
IsBasicAuth bool
- Repo RepoContext
+ Repo *RepoContext
Org struct {
IsOwner bool
@@ -73,17 +73,22 @@ type Context struct {
}
// IsOwner returns true if current user is the owner of repository.
-func (r RepoContext) IsOwner() bool {
+func (r *RepoContext) IsOwner() bool {
return r.AccessMode >= models.ACCESS_MODE_OWNER
}
// IsAdmin returns true if current user has admin or higher access of repository.
-func (r RepoContext) IsAdmin() bool {
+func (r *RepoContext) IsAdmin() bool {
return r.AccessMode >= models.ACCESS_MODE_ADMIN
}
+// IsPusher returns true if current user has write or higher access of repository.
+func (r *RepoContext) IsPusher() bool {
+ return r.AccessMode >= models.ACCESS_MODE_WRITE
+}
+
// Return if the current user has read access for this repository
-func (r RepoContext) HasAccess() bool {
+func (r *RepoContext) HasAccess() bool {
return r.AccessMode >= models.ACCESS_MODE_READ
}
diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go
index 210e563730..84c3f1d4f0 100644
--- a/modules/middleware/repo.go
+++ b/modules/middleware/repo.go
@@ -6,7 +6,6 @@ package middleware
import (
"fmt"
- "net/url"
"path"
"strings"
@@ -225,6 +224,8 @@ func RetrieveBaseRepo(ctx *Context, repo *models.Repository) {
func RepoAssignment(args ...bool) macaron.Handler {
return func(ctx *Context) {
+ ctx.Repo = &RepoContext{}
+
var (
displayBare bool // To display bare page if it is a bare repo.
)
@@ -335,6 +336,7 @@ func RepoAssignment(args ...bool) macaron.Handler {
ctx.Data["Owner"] = ctx.Repo.Repository.Owner
ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner()
ctx.Data["IsRepositoryAdmin"] = ctx.Repo.IsAdmin()
+ ctx.Data["IsRepositoryPusher"] = ctx.Repo.IsPusher()
ctx.Data["DisableSSH"] = setting.DisableSSH
ctx.Repo.CloneLink, err = repo.CloneLink()
@@ -397,11 +399,15 @@ func RepoAssignment(args ...bool) macaron.Handler {
func RequireRepoAdmin() macaron.Handler {
return func(ctx *Context) {
if !ctx.Repo.IsAdmin() {
- if !ctx.IsSigned {
- ctx.SetCookie("redirect_to", "/"+url.QueryEscape(setting.AppSubUrl+ctx.Req.RequestURI), 0, setting.AppSubUrl)
- ctx.Redirect(setting.AppSubUrl + "/user/login")
- return
- }
+ ctx.Handle(404, ctx.Req.RequestURI, nil)
+ return
+ }
+ }
+}
+
+func RequireRepoPusher() macaron.Handler {
+ return func(ctx *Context) {
+ if !ctx.Repo.IsPusher() {
ctx.Handle(404, ctx.Req.RequestURI, nil)
return
}