diff options
Diffstat (limited to 'cmd/web.go')
-rw-r--r-- | cmd/web.go | 82 |
1 files changed, 51 insertions, 31 deletions
@@ -17,6 +17,7 @@ import ( "github.com/Unknwon/macaron" "github.com/codegangsta/cli" + "github.com/go-xorm/xorm" "github.com/macaron-contrib/binding" "github.com/macaron-contrib/cache" "github.com/macaron-contrib/captcha" @@ -25,6 +26,7 @@ import ( "github.com/macaron-contrib/oauth2" "github.com/macaron-contrib/session" "github.com/macaron-contrib/toolbox" + "github.com/mcuadros/go-version" "gopkg.in/ini.v1" api "github.com/gogits/go-gogs-client" @@ -35,7 +37,6 @@ import ( "github.com/gogits/gogs/modules/avatar" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/bindata" - "github.com/gogits/gogs/modules/git" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/setting" @@ -69,7 +70,7 @@ type VerChecker struct { // checkVersion checks if binary matches the version of templates files. func checkVersion() { // Templates. - data, err := ioutil.ReadFile(path.Join(setting.StaticRootPath, "templates/.VERSION")) + data, err := ioutil.ReadFile(setting.StaticRootPath + "/templates/.VERSION") if err != nil { log.Fatal(4, "Fail to read 'templates/.VERSION': %v", err) } @@ -79,18 +80,18 @@ func checkVersion() { // Check dependency version. checkers := []VerChecker{ + {"github.com/go-xorm/xorm", func() string { return xorm.Version }, "0.4.3.0806"}, {"github.com/Unknwon/macaron", macaron.Version, "0.5.4"}, - {"github.com/macaron-contrib/binding", binding.Version, "0.0.6"}, + {"github.com/macaron-contrib/binding", binding.Version, "0.1.0"}, {"github.com/macaron-contrib/cache", cache.Version, "0.0.7"}, {"github.com/macaron-contrib/csrf", csrf.Version, "0.0.3"}, {"github.com/macaron-contrib/i18n", i18n.Version, "0.0.7"}, {"github.com/macaron-contrib/session", session.Version, "0.1.6"}, - {"gopkg.in/ini.v1", ini.Version, "1.2.0"}, + {"gopkg.in/ini.v1", ini.Version, "1.3.4"}, } for _, c := range checkers { - ver := strings.Join(strings.Split(c.Version(), ".")[:3], ".") - if git.MustParseVersion(ver).LessThan(git.MustParseVersion(c.Expected)) { - log.Fatal(4, "Package '%s' version is too old(%s -> %s), did you forget to update?", c.ImportPath, ver, c.Expected) + if !version.Compare(c.Version(), c.Expected, ">=") { + log.Fatal(4, "Package '%s' version is too old(%s -> %s), did you forget to update?", c.ImportPath, c.Version(), c.Expected) } } } @@ -98,7 +99,9 @@ func checkVersion() { // newMacaron initializes Macaron instance. func newMacaron() *macaron.Macaron { m := macaron.New() - m.Use(macaron.Logger()) + if !setting.DisableRouterLog { + m.Use(macaron.Logger()) + } m.Use(macaron.Recovery()) if setting.EnableGzip { m.Use(macaron.Gziper()) @@ -109,14 +112,14 @@ func newMacaron() *macaron.Macaron { m.Use(macaron.Static( path.Join(setting.StaticRootPath, "public"), macaron.StaticOptions{ - SkipLogging: !setting.DisableRouterLog, + SkipLogging: setting.DisableRouterLog, }, )) m.Use(macaron.Static( setting.AvatarUploadPath, macaron.StaticOptions{ Prefix: "avatars", - SkipLogging: !setting.DisableRouterLog, + SkipLogging: setting.DisableRouterLog, }, )) m.Use(macaron.Renderer(macaron.RenderOptions{ @@ -242,7 +245,7 @@ func runWeb(ctx *cli.Context) { ctx.HandleAPI(404, "Page not found") }) }) - }) + }, ignSignIn) // User. m.Group("/user", func() { @@ -328,7 +331,7 @@ func runWeb(ctx *cli.Context) { m.Get("/template/*", dev.TemplatePreview) } - reqAdmin := middleware.RequireAdmin() + reqRepoAdmin := middleware.RequireRepoAdmin() // Organization. m.Group("/org", func() { @@ -380,8 +383,8 @@ func runWeb(ctx *cli.Context) { m.Post("/create", bindIgnErr(auth.CreateRepoForm{}), repo.CreatePost) m.Get("/migrate", repo.Migrate) m.Post("/migrate", bindIgnErr(auth.MigrateRepoForm{}), repo.MigratePost) - m.Get("/fork", repo.Fork) - m.Post("/fork", bindIgnErr(auth.CreateRepoForm{}), repo.ForkPost) + m.Combo("/fork/:repoid").Get(repo.Fork). + Post(bindIgnErr(auth.CreateRepoForm{}), repo.ForkPost) }, reqSignIn) m.Group("/:username/:reponame", func() { @@ -402,8 +405,15 @@ func runWeb(ctx *cli.Context) { m.Get("/:name", repo.GitHooksEdit) m.Post("/:name", repo.GitHooksEditPost) }, middleware.GitHookService()) + + m.Group("/keys", func() { + m.Combo("").Get(repo.SettingsDeployKeys). + Post(bindIgnErr(auth.AddSSHKeyForm{}), repo.SettingsDeployKeysPost) + m.Post("/delete", repo.DeleteDeployKey) + }) + }) - }, reqSignIn, middleware.RepoAssignment(true), reqAdmin) + }, reqSignIn, middleware.RepoAssignment(true), reqRepoAdmin) m.Group("/:username/:reponame", func() { m.Get("/action/:action", repo.Action) @@ -416,15 +426,20 @@ func runWeb(ctx *cli.Context) { m.Post("/:index/milestone", repo.UpdateIssueMilestone) m.Post("/:index/assignee", repo.UpdateAssignee) m.Get("/:index/attachment/:id", repo.IssueGetAttachment) - m.Post("/labels/new", bindIgnErr(auth.CreateLabelForm{}), repo.NewLabel) - m.Post("/labels/edit", bindIgnErr(auth.CreateLabelForm{}), repo.UpdateLabel) - m.Post("/labels/delete", repo.DeleteLabel) - m.Get("/milestones/new", repo.NewMilestone) - m.Post("/milestones/new", bindIgnErr(auth.CreateMilestoneForm{}), repo.NewMilestonePost) - m.Get("/milestones/:index/edit", repo.UpdateMilestone) - m.Post("/milestones/:index/edit", bindIgnErr(auth.CreateMilestoneForm{}), repo.UpdateMilestonePost) - m.Get("/milestones/:index/:action", repo.UpdateMilestone) }) + m.Group("/labels", func() { + m.Post("/new", bindIgnErr(auth.CreateLabelForm{}), repo.NewLabel) + m.Post("/edit", bindIgnErr(auth.CreateLabelForm{}), repo.UpdateLabel) + m.Post("/delete", repo.DeleteLabel) + }, reqRepoAdmin) + m.Group("/milestones", func() { + m.Get("/new", repo.NewMilestone) + m.Post("/new", bindIgnErr(auth.CreateMilestoneForm{}), repo.NewMilestonePost) + m.Get("/:id/edit", repo.EditMilestone) + m.Post("/:id/edit", bindIgnErr(auth.CreateMilestoneForm{}), repo.EditMilestonePost) + m.Get("/:id/:action", repo.ChangeMilestonStatus) + m.Post("/delete", repo.DeleteMilestone) + }, reqRepoAdmin) m.Post("/comment/:action", repo.Comment) @@ -433,21 +448,19 @@ func runWeb(ctx *cli.Context) { m.Post("/new", bindIgnErr(auth.NewReleaseForm{}), repo.NewReleasePost) m.Get("/edit/:tagname", repo.EditRelease) m.Post("/edit/:tagname", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost) - }, middleware.RepoRef()) + }, reqRepoAdmin, middleware.RepoRef()) }, reqSignIn, middleware.RepoAssignment(true)) m.Group("/:username/:reponame", func() { m.Get("/releases", middleware.RepoRef(), repo.Releases) - m.Get("/issues", repo.Issues) + m.Get("/issues", repo.RetrieveLabels, repo.Issues) m.Get("/issues/:index", repo.ViewIssue) - m.Get("/issues/milestones", repo.Milestones) + m.Get("/labels/", repo.RetrieveLabels, repo.Labels) + m.Get("/milestones", repo.Milestones) m.Get("/pulls", repo.Pulls) m.Get("/branches", repo.Branches) m.Get("/archive/*", repo.Download) - m.Get("/issues2/", repo.Issues2) m.Get("/pulls2/", repo.PullRequest2) - m.Get("/labels2/", repo.Labels2) - m.Get("/milestone2/", repo.Milestones2) m.Group("", func() { m.Get("/src/*", repo.Home) @@ -460,8 +473,15 @@ func runWeb(ctx *cli.Context) { }, ignSignIn, middleware.RepoAssignment(true)) m.Group("/:username", func() { - m.Get("/:reponame", ignSignIn, middleware.RepoAssignment(true, true), middleware.RepoRef(), repo.Home) - m.Any("/:reponame/*", ignSignInAndCsrf, repo.Http) + m.Group("/:reponame", func() { + m.Get("", repo.Home) + m.Get(".git", repo.Home) + }, ignSignIn, middleware.RepoAssignment(true, true), middleware.RepoRef()) + + m.Group("/:reponame", func() { + m.Any("/*", ignSignInAndCsrf, repo.Http) + m.Head("/hooks/trigger", repo.TriggerHook) + }) }) // robots.txt |