diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/serve.go | 6 | ||||
-rw-r--r-- | cmd/web.go | 40 |
2 files changed, 38 insertions, 8 deletions
diff --git a/cmd/serve.go b/cmd/serve.go index 9638da8b..ec1da3be 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -146,12 +146,12 @@ func runServ(c *cli.Context) { fail("Key permission denied", "Cannot push with deployment key: %d", key.ID) } // Check if this deploy key belongs to current repository. - if !models.HasDeployKey(key.ID, repo.Id) { - fail("Key access denied", "Key access denied: %d-%d", key.ID, repo.Id) + if !models.HasDeployKey(key.ID, repo.ID) { + fail("Key access denied", "Key access denied: %d-%d", key.ID, repo.ID) } // Update deploy key activity. - deployKey, err := models.GetDeployKeyByRepo(key.ID, repo.Id) + deployKey, err := models.GetDeployKeyByRepo(key.ID, repo.ID) if err != nil { fail("Internal error", "GetDeployKey: %v", err) } @@ -325,7 +325,36 @@ func runWeb(ctx *cli.Context) { }) }, adminReq) - m.Get("/:username", ignSignIn, user.Profile) + m.Group("", func() { + m.Get("/:username", user.Profile) + m.Get("/attachments/:uuid", func(ctx *middleware.Context) { + attach, err := models.GetAttachmentByUUID(ctx.Params(":uuid")) + if err != nil { + if models.IsErrAttachmentNotExist(err) { + ctx.Error(404) + } else { + ctx.Handle(500, "GetAttachmentByUUID", err) + } + return + } + + fr, err := os.Open(attach.LocalPath()) + if err != nil { + ctx.Handle(500, "Open", err) + return + } + defer fr.Close() + + ctx.Header().Set("Cache-Control", "public,max-age=86400") + // Fix #312. Attachments with , in their name are not handled correctly by Google Chrome. + // We must put the name in " manually. + if err = repo.ServeData(ctx, "\""+attach.Name+"\"", fr); err != nil { + ctx.Handle(500, "ServeData", err) + return + } + }) + m.Post("/issues/attachments", repo.UploadIssueAttachment) + }, ignSignIn) if macaron.Env == macaron.DEV { m.Get("/template/*", dev.TemplatePreview) @@ -419,13 +448,12 @@ func runWeb(ctx *cli.Context) { m.Get("/action/:action", repo.Action) m.Group("/issues", func() { - m.Get("/new", repo.CreateIssue) - m.Post("/new", bindIgnErr(auth.CreateIssueForm{}), repo.CreateIssuePost) + m.Combo("/new").Get(repo.NewIssue). + Post(bindIgnErr(auth.CreateIssueForm{}), repo.NewIssuePost) m.Post("/:index", bindIgnErr(auth.CreateIssueForm{}), repo.UpdateIssue) m.Post("/:index/label", repo.UpdateIssueLabel) m.Post("/:index/milestone", repo.UpdateIssueMilestone) m.Post("/:index/assignee", repo.UpdateAssignee) - m.Get("/:index/attachment/:id", repo.IssueGetAttachment) }) m.Group("/labels", func() { m.Post("/new", bindIgnErr(auth.CreateLabelForm{}), repo.NewLabel) @@ -449,6 +477,8 @@ func runWeb(ctx *cli.Context) { m.Get("/edit/:tagname", repo.EditRelease) m.Post("/edit/:tagname", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost) }, reqRepoAdmin, middleware.RepoRef()) + + m.Combo("/compare/*").Get(repo.CompareAndPullRequest) }, reqSignIn, middleware.RepoAssignment(true)) m.Group("/:username/:reponame", func() { @@ -469,7 +499,7 @@ func runWeb(ctx *cli.Context) { m.Get("/commit/*", repo.Diff) }, middleware.RepoRef()) - m.Get("/compare/:before([a-z0-9]+)...:after([a-z0-9]+)", repo.CompareDiff) + m.Get("/compare/:before([a-z0-9]{40})...:after([a-z0-9]{40})", repo.CompareDiff) }, ignSignIn, middleware.RepoAssignment(true)) m.Group("/:username", func() { |