diff options
author | FuXiaoHei <fuxiaohei@hexiaz.com> | 2014-03-13 12:50:07 +0800 |
---|---|---|
committer | FuXiaoHei <fuxiaohei@hexiaz.com> | 2014-03-13 12:50:07 +0800 |
commit | b1fe498eb975d112b06814253f9b9e8dc561d91f (patch) | |
tree | f3a84ac499c3d75054c72652c9a97caed94d99ed /modules/auth/repo.go | |
parent | 555c8f1d919eae951bf7f75f4bc6a150ec04b9a6 (diff) | |
download | gitea-b1fe498eb975d112b06814253f9b9e8dc561d91f.tar.gz gitea-b1fe498eb975d112b06814253f9b9e8dc561d91f.zip |
single repository page ui
Diffstat (limited to 'modules/auth/repo.go')
-rw-r--r-- | modules/auth/repo.go | 62 |
1 files changed, 62 insertions, 0 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 + } +} |