summaryrefslogtreecommitdiffstats
path: root/modules/middleware/repo.go
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-04-11 21:47:39 -0400
committerUnknown <joe2010xtmf@163.com>2014-04-11 21:47:39 -0400
commit33aa4f74380ab117673a1cc30bead3a7f2b3cb4b (patch)
treeac6c7c1ebebb86260545386c7ce923593e4d5046 /modules/middleware/repo.go
parentd6dac160dfcac068b31bda9316ddc3d4919e3288 (diff)
downloadgitea-33aa4f74380ab117673a1cc30bead3a7f2b3cb4b.tar.gz
gitea-33aa4f74380ab117673a1cc30bead3a7f2b3cb4b.zip
Support private repo
Diffstat (limited to 'modules/middleware/repo.go')
-rw-r--r--modules/middleware/repo.go48
1 files changed, 46 insertions, 2 deletions
diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go
index 258fc9d2ab..75d9f999c6 100644
--- a/modules/middleware/repo.go
+++ b/modules/middleware/repo.go
@@ -67,12 +67,14 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
ctx.Handle(200, "RepoAssignment", errors.New("invliad user account for single repository"))
return
}
+ ctx.Repo.Owner = user
// get repository
repo, err := models.GetRepositoryByName(user.Id, repoName)
if err != nil {
if err == models.ErrRepoNotExist {
ctx.Handle(404, "RepoAssignment", err)
+ return
} else if redirect {
ctx.Redirect("/")
return
@@ -80,6 +82,26 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
ctx.Handle(500, "RepoAssignment", err)
return
}
+
+ // Check access.
+ if repo.IsPrivate {
+ if ctx.User == nil {
+ ctx.Handle(404, "RepoAssignment(HasAccess)", nil)
+ return
+ }
+
+ hasAccess, err := models.HasAccess(ctx.User.Name, ctx.Repo.Owner.Name+"/"+repo.Name, models.AU_READABLE)
+ if err != nil {
+ ctx.Handle(500, "RepoAssignment(HasAccess)", err)
+ return
+ } else if !hasAccess {
+ ctx.Handle(404, "RepoAssignment(HasAccess)", nil)
+ return
+ }
+ }
+ ctx.Repo.HasAccess = true
+ ctx.Data["HasAccess"] = true
+
repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues
ctx.Repo.Repository = repo
@@ -91,8 +113,6 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
return
}
ctx.Repo.GitRepo = gitRepo
-
- ctx.Repo.Owner = user
ctx.Repo.RepoLink = "/" + user.Name + "/" + repo.Name
ctx.Data["Title"] = user.Name + "/" + repo.Name
@@ -170,3 +190,27 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
ctx.Data["IsRepositoryWatching"] = ctx.Repo.IsWatching
}
}
+
+func WriteAccess() martini.Handler {
+ return func(ctx *Context) {
+ if ctx.Repo.Repository.IsPrivate {
+ ctx.Repo.HasAccess = false
+ ctx.Data["HasAccess"] = false
+ if ctx.User == nil {
+ ctx.Handle(404, "WriteAccess", nil)
+ return
+ }
+
+ hasAccess, err := models.HasAccess(ctx.User.Name, ctx.Repo.Owner.Name+"/"+ctx.Repo.Repository.Name, models.AU_WRITABLE)
+ if err != nil {
+ ctx.Handle(500, "WriteAccess(HasAccess)", err)
+ return
+ } else if !hasAccess {
+ ctx.Handle(404, "WriteAccess(HasAccess)", nil)
+ return
+ }
+ }
+ ctx.Repo.HasAccess = true
+ ctx.Data["HasAccess"] = true
+ }
+}