|
@ -12,8 +12,11 @@ import ( |
|
|
|
|
|
|
|
|
"github.com/gogits/binding" |
|
|
"github.com/gogits/binding" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/gogits/gogs/models" |
|
|
"github.com/gogits/gogs/modules/base" |
|
|
"github.com/gogits/gogs/modules/base" |
|
|
"github.com/gogits/gogs/modules/log" |
|
|
"github.com/gogits/gogs/modules/log" |
|
|
|
|
|
"github.com/martini-contrib/render" |
|
|
|
|
|
"github.com/martini-contrib/sessions" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
type CreateRepoForm struct { |
|
|
type CreateRepoForm struct { |
|
@ -52,3 +55,62 @@ func (f *CreateRepoForm) Validate(errors *binding.Errors, req *http.Request, con |
|
|
|
|
|
|
|
|
validate(errors, data, f) |
|
|
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 |
|
|
|
|
|
} |
|
|
|
|
|
} |