| 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 "crypto/sha1" | 18 "crypto/sha1" |
| 19 "encoding/base64" | 19 "encoding/base64" |
| 20 "fmt" | 20 "fmt" |
| 21 "net/http" | 21 "net/http" |
| 22 "time" | 22 "time" |
| 23 | 23 |
| 24 mc "github.com/luci/gae/service/memcache" | 24 mc "github.com/luci/gae/service/memcache" |
| 25 "github.com/luci/luci-go/common/clock" | 25 "github.com/luci/luci-go/common/clock" |
| 26 » "github.com/luci/luci-go/scheduler/appengine/presentation" | 26 » "github.com/luci/luci-go/scheduler/appengine/acl" |
| 27 "github.com/luci/luci-go/server/auth" | 27 "github.com/luci/luci-go/server/auth" |
| 28 "github.com/luci/luci-go/server/router" | 28 "github.com/luci/luci-go/server/router" |
| 29 "github.com/luci/luci-go/server/templates" | 29 "github.com/luci/luci-go/server/templates" |
| 30 ) | 30 ) |
| 31 | 31 |
| 32 func jobPage(ctx *router.Context) { | 32 func jobPage(ctx *router.Context) { |
| 33 c, w, r, p := ctx.Context, ctx.Writer, ctx.Request, ctx.Params | 33 c, w, r, p := ctx.Context, ctx.Writer, ctx.Request, ctx.Params |
| 34 | 34 |
| 35 projectID := p.ByName("ProjectID") | 35 projectID := p.ByName("ProjectID") |
| 36 jobName := p.ByName("JobName") | 36 jobName := p.ByName("JobName") |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 96 } |
| 97 | 97 |
| 98 //////////////////////////////////////////////////////////////////////////////// | 98 //////////////////////////////////////////////////////////////////////////////// |
| 99 // Actions. | 99 // Actions. |
| 100 | 100 |
| 101 func runJobAction(ctx *router.Context) { | 101 func runJobAction(ctx *router.Context) { |
| 102 c, w, r, p := ctx.Context, ctx.Writer, ctx.Request, ctx.Params | 102 c, w, r, p := ctx.Context, ctx.Writer, ctx.Request, ctx.Params |
| 103 | 103 |
| 104 projectID := p.ByName("ProjectID") | 104 projectID := p.ByName("ProjectID") |
| 105 jobName := p.ByName("JobName") | 105 jobName := p.ByName("JobName") |
| 106 » if !presentation.IsJobOwner(c, projectID, jobName) { | 106 » if !acl.IsJobOwner(c, projectID, jobName) { |
| 107 http.Error(w, "Forbidden", 403) | 107 http.Error(w, "Forbidden", 403) |
| 108 return | 108 return |
| 109 } | 109 } |
| 110 | 110 |
| 111 // genericReply renders "we did something (or we failed to do something)
" | 111 // genericReply renders "we did something (or we failed to do something)
" |
| 112 // page, shown on error or if invocation is starting for too long. | 112 // page, shown on error or if invocation is starting for too long. |
| 113 genericReply := func(err error) { | 113 genericReply := func(err error) { |
| 114 templates.MustRender(c, w, "pages/run_job_result.html", map[stri
ng]interface{}{ | 114 templates.MustRender(c, w, "pages/run_job_result.html", map[stri
ng]interface{}{ |
| 115 "ProjectID": projectID, | 115 "ProjectID": projectID, |
| 116 "JobName": jobName, | 116 "JobName": jobName, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 func abortJobAction(c *router.Context) { | 174 func abortJobAction(c *router.Context) { |
| 175 handleJobAction(c, func(jobID string) error { | 175 handleJobAction(c, func(jobID string) error { |
| 176 who := auth.CurrentIdentity(c.Context) | 176 who := auth.CurrentIdentity(c.Context) |
| 177 return config(c.Context).Engine.AbortJob(c.Context, jobID, who) | 177 return config(c.Context).Engine.AbortJob(c.Context, jobID, who) |
| 178 }) | 178 }) |
| 179 } | 179 } |
| 180 | 180 |
| 181 func handleJobAction(c *router.Context, cb func(string) error) { | 181 func handleJobAction(c *router.Context, cb func(string) error) { |
| 182 projectID := c.Params.ByName("ProjectID") | 182 projectID := c.Params.ByName("ProjectID") |
| 183 jobName := c.Params.ByName("JobName") | 183 jobName := c.Params.ByName("JobName") |
| 184 » if !presentation.IsJobOwner(c.Context, projectID, jobName) { | 184 » if !acl.IsJobOwner(c.Context, projectID, jobName) { |
| 185 http.Error(c.Writer, "Forbidden", 403) | 185 http.Error(c.Writer, "Forbidden", 403) |
| 186 return | 186 return |
| 187 } | 187 } |
| 188 if err := cb(projectID + "/" + jobName); err != nil { | 188 if err := cb(projectID + "/" + jobName); err != nil { |
| 189 panic(err) | 189 panic(err) |
| 190 } | 190 } |
| 191 http.Redirect(c.Writer, c.Request, fmt.Sprintf("/jobs/%s/%s", projectID,
jobName), http.StatusFound) | 191 http.Redirect(c.Writer, c.Request, fmt.Sprintf("/jobs/%s/%s", projectID,
jobName), http.StatusFound) |
| 192 } | 192 } |
| OLD | NEW |