summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modules/auth/repo.go62
-rw-r--r--routers/repo/single.go46
-rw-r--r--web.go4
3 files changed, 66 insertions, 46 deletions
diff --git a/modules/auth/repo.go b/modules/auth/repo.go
index 981315d40f..d769664649 100644
--- a/modules/auth/repo.go
+++ b/modules/auth/repo.go
@@ -12,8 +12,11 @@ import (
"github.com/gogits/binding"
+ "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/log"
+ "github.com/martini-contrib/render"
+ "github.com/martini-contrib/sessions"
)
type CreateRepoForm struct {
@@ -52,3 +55,62 @@ func (f *CreateRepoForm) Validate(errors *binding.Errors, req *http.Request, con
validate(errors, data, f)
}
+
+func RepoAssignment(redirect bool) martini.Handler {
+ return func(params martini.Params, r render.Render, data base.TmplData, session sessions.Session) {
+ // assign false first
+ data["IsRepositoryValid"] = false
+
+ var (
+ user *models.User
+ err error
+ )
+ // get repository owner
+ isOwner := (data["SignedUserName"] == params["username"])
+ if !isOwner {
+ user, err = models.GetUserByName(params["username"])
+ if err != nil {
+ if redirect {
+ r.Redirect("/")
+ return
+ }
+ //data["ErrorMsg"] = err
+ //log.Error("repo.Single: %v", err)
+ //r.HTML(200, "base/error", data)
+ return
+ }
+ } else {
+ user = SignedInUser(session)
+ }
+ if user == nil {
+ if redirect {
+ r.Redirect("/")
+ return
+ }
+ //data["ErrorMsg"] = "invliad user account for single repository"
+ //log.Error("repo.Single: %v", err)
+ //r.HTML(200, "base/error", data)
+ return
+ }
+ data["IsRepositoryOwner"] = isOwner
+
+ // get repository
+ repo, err := models.GetRepositoryByName(user, params["reponame"])
+ if err != nil {
+ if redirect {
+ r.Redirect("/")
+ return
+ }
+ //data["ErrorMsg"] = err
+ //log.Error("repo.Single: %v", err)
+ //r.HTML(200, "base/error", data)
+ return
+ }
+
+ data["Repository"] = repo
+ data["Owner"] = user
+ data["Title"] = user.Name + "/" + repo.Name
+ data["RepositoryLink"] = data["Title"]
+ data["IsRepositoryValid"] = true
+ }
+}
diff --git a/routers/repo/single.go b/routers/repo/single.go
index be27db8e05..322f6ce87f 100644
--- a/routers/repo/single.go
+++ b/routers/repo/single.go
@@ -1,56 +1,14 @@
package repo
import (
- "github.com/codegangsta/martini"
- "github.com/gogits/gogs/models"
- "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
"github.com/martini-contrib/render"
- "github.com/martini-contrib/sessions"
- "net/http"
)
-
-func Single(params martini.Params, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) {
- var (
- user *models.User
- err error
- )
- // get repository owner
- isOwner := (data["SignedUserName"] == params["username"])
- if !isOwner {
- user, err = models.GetUserByName(params["username"])
- if err != nil {
- data["ErrorMsg"] = err
- //log.Error("repo.Single: %v", err)
- r.HTML(200, "base/error", data)
- return
- }
- } else {
- user = auth.SignedInUser(session)
- }
- if user == nil {
- data["ErrorMsg"] = "invliad user account for single repository"
- //log.Error("repo.Single: %v", err)
- r.HTML(200, "base/error", data)
+func Single(r render.Render, data base.TmplData) {
+ if !data["IsRepositoryValid"].(bool) {
return
}
- data["IsRepositoryOwner"] = isOwner
-
- // get repository
- repo, err := models.GetRepositoryByName(user, params["reponame"])
- if err != nil {
- data["ErrorMsg"] = err
- //log.Error("repo.Single: %v", err)
- r.HTML(200, "base/error", data)
- return
- }
-
- data["Repository"] = repo
- data["Owner"] = user
- data["Title"] = user.Name + "/" + repo.Name
- data["RepositoryLink"] = data["Title"]
data["IsRepoToolbarSource"] = true
-
r.HTML(200, "repo/single", data)
}
diff --git a/web.go b/web.go
index c8b7ed0d49..9f9b205a74 100644
--- a/web.go
+++ b/web.go
@@ -70,12 +70,12 @@ func runWeb(*cli.Context) {
m.Get("/user/:username", auth.SignInRequire(false), user.Profile)
- m.Get("/:username/:reponame", repo.Repo)
+ //m.Get("/:username/:reponame", repo.Repo)
m.Any("/repo/create", auth.SignInRequire(true), binding.BindIgnErr(auth.CreateRepoForm{}), repo.Create)
m.Any("/repo/delete", auth.SignInRequire(true), repo.Delete)
m.Any("/repo/list", auth.SignInRequire(false), repo.List)
- m.Get("/:username/:reponame", auth.SignInRequire(false), repo.Single)
+ m.Get("/:username/:reponame", auth.SignInRequire(false), auth.RepoAssignment(true), repo.Single)
listenAddr := fmt.Sprintf("%s:%s",
base.Cfg.MustValue("server", "HTTP_ADDR"),