| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package ui | 5 package ui |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "net/http" | 9 "net/http" |
| 10 "strconv" | 10 "strconv" |
| 11 | 11 |
| 12 "github.com/julienschmidt/httprouter" | |
| 13 "golang.org/x/net/context" | |
| 14 | |
| 15 "github.com/luci/luci-go/common/clock" | 12 "github.com/luci/luci-go/common/clock" |
| 16 "github.com/luci/luci-go/server/auth" | 13 "github.com/luci/luci-go/server/auth" |
| 14 "github.com/luci/luci-go/server/router" |
| 17 "github.com/luci/luci-go/server/templates" | 15 "github.com/luci/luci-go/server/templates" |
| 18 ) | 16 ) |
| 19 | 17 |
| 20 func invocationPage(c context.Context, w http.ResponseWriter, r *http.Request, p
httprouter.Params) { | 18 func invocationPage(c *router.Context) { |
| 21 » projectID := p.ByName("ProjectID") | 19 » projectID := c.Params.ByName("ProjectID") |
| 22 » jobID := p.ByName("JobID") | 20 » jobID := c.Params.ByName("JobID") |
| 23 » invID, err := strconv.ParseInt(p.ByName("InvID"), 10, 64) | 21 » invID, err := strconv.ParseInt(c.Params.ByName("InvID"), 10, 64) |
| 24 if err != nil { | 22 if err != nil { |
| 25 » » http.Error(w, "No such invocation", http.StatusNotFound) | 23 » » http.Error(c.Writer, "No such invocation", http.StatusNotFound) |
| 26 return | 24 return |
| 27 } | 25 } |
| 28 | 26 |
| 29 » inv, err := config(c).Engine.GetInvocation(c, projectID+"/"+jobID, invID
) | 27 » inv, err := config(c.Context).Engine.GetInvocation(c.Context, projectID+
"/"+jobID, invID) |
| 30 if err != nil { | 28 if err != nil { |
| 31 panic(err) | 29 panic(err) |
| 32 } | 30 } |
| 33 if inv == nil { | 31 if inv == nil { |
| 34 » » http.Error(w, "No such invocation", http.StatusNotFound) | 32 » » http.Error(c.Writer, "No such invocation", http.StatusNotFound) |
| 35 return | 33 return |
| 36 } | 34 } |
| 37 | 35 |
| 38 » now := clock.Now(c).UTC() | 36 » now := clock.Now(c.Context).UTC() |
| 39 » templates.MustRender(c, w, "pages/invocation.html", map[string]interface
{}{ | 37 » templates.MustRender(c.Context, c.Writer, "pages/invocation.html", map[s
tring]interface{}{ |
| 40 "ProjectID": projectID, | 38 "ProjectID": projectID, |
| 41 "JobID": jobID, | 39 "JobID": jobID, |
| 42 "Inv": makeInvocation(projectID, jobID, inv, now), | 40 "Inv": makeInvocation(projectID, jobID, inv, now), |
| 43 }) | 41 }) |
| 44 } | 42 } |
| 45 | 43 |
| 46 //////////////////////////////////////////////////////////////////////////////// | 44 //////////////////////////////////////////////////////////////////////////////// |
| 47 // Actions. | 45 // Actions. |
| 48 | 46 |
| 49 func abortInvocationAction(c context.Context, w http.ResponseWriter, r *http.Req
uest, p httprouter.Params) { | 47 func abortInvocationAction(c *router.Context) { |
| 50 » handleInvAction(c, w, r, p, func(jobID string, invID int64) error { | 48 » handleInvAction(c, func(jobID string, invID int64) error { |
| 51 » » who := auth.CurrentIdentity(c) | 49 » » who := auth.CurrentIdentity(c.Context) |
| 52 » » return config(c).Engine.AbortInvocation(c, jobID, invID, who) | 50 » » return config(c.Context).Engine.AbortInvocation(c.Context, jobID
, invID, who) |
| 53 }) | 51 }) |
| 54 } | 52 } |
| 55 | 53 |
| 56 func handleInvAction(c context.Context, w http.ResponseWriter, r *http.Request,
p httprouter.Params, cb func(string, int64) error) { | 54 func handleInvAction(c *router.Context, cb func(string, int64) error) { |
| 57 » projectID := p.ByName("ProjectID") | 55 » projectID := c.Params.ByName("ProjectID") |
| 58 » jobID := p.ByName("JobID") | 56 » jobID := c.Params.ByName("JobID") |
| 59 » invID := p.ByName("InvID") | 57 » invID := c.Params.ByName("InvID") |
| 60 » if !isJobOwner(c, projectID, jobID) { | 58 » if !isJobOwner(c.Context, projectID, jobID) { |
| 61 » » http.Error(w, "Forbidden", 403) | 59 » » http.Error(c.Writer, "Forbidden", 403) |
| 62 return | 60 return |
| 63 } | 61 } |
| 64 invIDAsInt, err := strconv.ParseInt(invID, 10, 64) | 62 invIDAsInt, err := strconv.ParseInt(invID, 10, 64) |
| 65 if err != nil { | 63 if err != nil { |
| 66 » » http.Error(w, "Bad invocation ID", 400) | 64 » » http.Error(c.Writer, "Bad invocation ID", 400) |
| 67 return | 65 return |
| 68 } | 66 } |
| 69 if err := cb(projectID+"/"+jobID, invIDAsInt); err != nil { | 67 if err := cb(projectID+"/"+jobID, invIDAsInt); err != nil { |
| 70 panic(err) | 68 panic(err) |
| 71 } | 69 } |
| 72 » http.Redirect(w, r, fmt.Sprintf("/jobs/%s/%s/%s", projectID, jobID, invI
D), http.StatusFound) | 70 » http.Redirect(c.Writer, c.Request, fmt.Sprintf("/jobs/%s/%s/%s", project
ID, jobID, invID), http.StatusFound) |
| 73 } | 71 } |
| OLD | NEW |