| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. | 1 // Copyright 2015 The LUCI Authors. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 package ui | 15 package ui |
| 16 | 16 |
| 17 import ( | 17 import ( |
| 18 "fmt" | 18 "fmt" |
| 19 "net/http" | 19 "net/http" |
| 20 "strconv" | 20 "strconv" |
| 21 "sync" | 21 "sync" |
| 22 | 22 |
| 23 "github.com/luci/luci-go/server/auth" | 23 "github.com/luci/luci-go/server/auth" |
| 24 "github.com/luci/luci-go/server/router" | 24 "github.com/luci/luci-go/server/router" |
| 25 "github.com/luci/luci-go/server/templates" | 25 "github.com/luci/luci-go/server/templates" |
| 26 | 26 |
| 27 "github.com/luci/luci-go/scheduler/appengine/acl" |
| 27 "github.com/luci/luci-go/scheduler/appengine/engine" | 28 "github.com/luci/luci-go/scheduler/appengine/engine" |
| 28 "github.com/luci/luci-go/scheduler/appengine/presentation" | |
| 29 ) | 29 ) |
| 30 | 30 |
| 31 func invocationPage(c *router.Context) { | 31 func invocationPage(c *router.Context) { |
| 32 projectID := c.Params.ByName("ProjectID") | 32 projectID := c.Params.ByName("ProjectID") |
| 33 jobName := c.Params.ByName("JobName") | 33 jobName := c.Params.ByName("JobName") |
| 34 invID, err := strconv.ParseInt(c.Params.ByName("InvID"), 10, 64) | 34 invID, err := strconv.ParseInt(c.Params.ByName("InvID"), 10, 64) |
| 35 if err != nil { | 35 if err != nil { |
| 36 http.Error(c.Writer, "No such invocation", http.StatusNotFound) | 36 http.Error(c.Writer, "No such invocation", http.StatusNotFound) |
| 37 return | 37 return |
| 38 } | 38 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 handleInvAction(c, func(jobID string, invID int64) error { | 84 handleInvAction(c, func(jobID string, invID int64) error { |
| 85 who := auth.CurrentIdentity(c.Context) | 85 who := auth.CurrentIdentity(c.Context) |
| 86 return config(c.Context).Engine.AbortInvocation(c.Context, jobID
, invID, who) | 86 return config(c.Context).Engine.AbortInvocation(c.Context, jobID
, invID, who) |
| 87 }) | 87 }) |
| 88 } | 88 } |
| 89 | 89 |
| 90 func handleInvAction(c *router.Context, cb func(string, int64) error) { | 90 func handleInvAction(c *router.Context, cb func(string, int64) error) { |
| 91 projectID := c.Params.ByName("ProjectID") | 91 projectID := c.Params.ByName("ProjectID") |
| 92 jobName := c.Params.ByName("JobName") | 92 jobName := c.Params.ByName("JobName") |
| 93 invID := c.Params.ByName("InvID") | 93 invID := c.Params.ByName("InvID") |
| 94 » if !presentation.IsJobOwner(c.Context, projectID, jobName) { | 94 » if !acl.IsJobOwner(c.Context, projectID, jobName) { |
| 95 http.Error(c.Writer, "Forbidden", 403) | 95 http.Error(c.Writer, "Forbidden", 403) |
| 96 return | 96 return |
| 97 } | 97 } |
| 98 invIDAsInt, err := strconv.ParseInt(invID, 10, 64) | 98 invIDAsInt, err := strconv.ParseInt(invID, 10, 64) |
| 99 if err != nil { | 99 if err != nil { |
| 100 http.Error(c.Writer, "Bad invocation ID", 400) | 100 http.Error(c.Writer, "Bad invocation ID", 400) |
| 101 return | 101 return |
| 102 } | 102 } |
| 103 if err := cb(projectID+"/"+jobName, invIDAsInt); err != nil { | 103 if err := cb(projectID+"/"+jobName, invIDAsInt); err != nil { |
| 104 panic(err) | 104 panic(err) |
| 105 } | 105 } |
| 106 http.Redirect(c.Writer, c.Request, fmt.Sprintf("/jobs/%s/%s/%s", project
ID, jobName, invID), http.StatusFound) | 106 http.Redirect(c.Writer, c.Request, fmt.Sprintf("/jobs/%s/%s/%s", project
ID, jobName, invID), http.StatusFound) |
| 107 } | 107 } |
| OLD | NEW |