1
0
mirror of https://github.com/go-gitea/gitea synced 2024-12-24 03:35:55 +01:00

Merge branch 'master' of github.com:gogits/gogs

This commit is contained in:
Unknown 2014-03-15 12:13:48 -04:00
commit f026ae8652
5 changed files with 96 additions and 69 deletions

@ -12,11 +12,8 @@ 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 {
@ -61,62 +58,3 @@ type DeleteRepoForm struct {
UserName string `form:"userName" binding:"Required"`
RepoId int64 `form:"repoId" binding:"Required"`
}
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
}
}

@ -29,6 +29,12 @@ type Context struct {
Render render.Render
User *models.User
IsSigned bool
Repo struct {
IsValid bool
IsOwner bool
Repository *models.Repository
}
}
// Query querys form parameter.

@ -0,0 +1,76 @@
// Copyright 2014 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package middleware
import (
"github.com/codegangsta/martini"
"github.com/gogits/gogs/models"
)
func RepoAssignment(redirect bool) martini.Handler {
return func(ctx *Context, params martini.Params) {
// assign false first
ctx.Data["IsRepositoryValid"] = false
var (
user *models.User
err error
)
// get repository owner
ctx.Repo.IsOwner = ctx.IsSigned && ctx.User.LowerName == params["username"]
ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner
if !ctx.Repo.IsOwner {
user, err = models.GetUserByName(params["username"])
if err != nil {
if redirect {
ctx.Render.Redirect("/")
return
}
//data["ErrorMsg"] = err
//log.Error("repo.Single: %v", err)
//r.HTML(200, "base/error", data)
return
}
} else {
user = ctx.User
}
if user == nil {
if redirect {
ctx.Render.Redirect("/")
return
}
//data["ErrorMsg"] = "invliad user account for single repository"
//log.Error("repo.Single: %v", err)
//r.HTML(200, "base/error", data)
return
}
// get repository
repo, err := models.GetRepositoryByName(user, params["reponame"])
if err != nil {
if redirect {
ctx.Render.Redirect("/")
return
}
//data["ErrorMsg"] = err
//log.Error("repo.Single: %v", err)
//r.HTML(200, "base/error", data)
return
}
ctx.Repo.IsValid = true
ctx.Repo.Repository = repo
ctx.Data["IsRepositoryValid"] = true
ctx.Data["Repository"] = repo
ctx.Data["Owner"] = user
ctx.Data["Title"] = user.Name + "/" + repo.Name
ctx.Data["RepositoryLink"] = ctx.Data["Title"]
}
}

@ -10,12 +10,14 @@ import (
)
func Single(ctx *middleware.Context, params martini.Params) {
if !ctx.Data["IsRepositoryValid"].(bool) {
if !ctx.Repo.IsValid {
return
}
if params["branchname"] == "" {
params["branchname"] = "master"
}
treename := params["_1"]
files, err := models.GetReposFiles(params["username"], params["reponame"],
params["branchname"], treename)
@ -45,11 +47,16 @@ func Single(ctx *middleware.Context, params martini.Params) {
}
func Setting(ctx *middleware.Context) {
if !ctx.Data["IsRepositoryValid"].(bool) {
if !ctx.Repo.IsValid {
return
}
ctx.Data["Title"] = ctx.Data["Title"].(string) + " - settings"
var title string
if t, ok := ctx.Data["Title"].(string); ok {
title = t
}
ctx.Data["Title"] = title + " - settings"
ctx.Data["IsRepoToolbarSetting"] = true
ctx.Render.HTML(200, "repo/setting", ctx.Data)
}

8
web.go

@ -67,12 +67,12 @@ func runWeb(*cli.Context) {
m.Any("/repo/create", middleware.SignInRequire(true), binding.BindIgnErr(auth.CreateRepoForm{}), repo.Create)
m.Any("/repo/delete", middleware.SignInRequire(true), binding.Bind(auth.DeleteRepoForm{}), repo.Delete)
m.Get("/:username/:reponame/settings", middleware.SignInRequire(false), auth.RepoAssignment(true), repo.Setting)
m.Get("/:username/:reponame/settings", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Setting)
m.Get("/:username/:reponame/tree/:branchname/**",
middleware.SignInRequire(false), auth.RepoAssignment(true), repo.Single)
middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Single)
m.Get("/:username/:reponame/tree/:branchname",
middleware.SignInRequire(false), auth.RepoAssignment(true), repo.Single)
m.Get("/:username/:reponame", middleware.SignInRequire(false), auth.RepoAssignment(true), repo.Single)
middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Single)
m.Get("/:username/:reponame", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Single)
//m.Get("/:username/:reponame", repo.Repo)