| 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 settings | 5 package settings |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "encoding/base64" | 8 "encoding/base64" |
| 9 "encoding/json" | 9 "encoding/json" |
| 10 "fmt" | 10 "fmt" |
| 11 "net/http" | 11 "net/http" |
| 12 "strconv" |
| 12 | 13 |
| 13 ds "github.com/luci/gae/service/datastore" | 14 ds "github.com/luci/gae/service/datastore" |
| 14 "github.com/luci/luci-go/milo/api/resp" | 15 "github.com/luci/luci-go/milo/api/resp" |
| 15 "github.com/luci/luci-go/milo/appengine/model" | 16 "github.com/luci/luci-go/milo/appengine/model" |
| 17 "github.com/luci/luci-go/milo/common/miloerror" |
| 16 "github.com/luci/luci-go/server/auth" | 18 "github.com/luci/luci-go/server/auth" |
| 17 "github.com/luci/luci-go/server/auth/identity" | 19 "github.com/luci/luci-go/server/auth/identity" |
| 18 "github.com/luci/luci-go/server/auth/xsrf" | 20 "github.com/luci/luci-go/server/auth/xsrf" |
| 19 "github.com/luci/luci-go/server/router" | 21 "github.com/luci/luci-go/server/router" |
| 20 | 22 |
| 21 "golang.org/x/net/context" | 23 "golang.org/x/net/context" |
| 22 ) | 24 ) |
| 23 | 25 |
| 24 type updateReq struct { | 26 type updateReq struct { |
| 25 Theme string | 27 Theme string |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 144 |
| 143 result := &resp.Settings{} | 145 result := &resp.Settings{} |
| 144 result.ActionURL = r.URL.String() | 146 result.ActionURL = r.URL.String() |
| 145 result.Theme = &resp.Choices{ | 147 result.Theme = &resp.Choices{ |
| 146 Choices: GetAllThemes(), | 148 Choices: GetAllThemes(), |
| 147 Selected: userSettings.Theme, | 149 Selected: userSettings.Theme, |
| 148 } | 150 } |
| 149 | 151 |
| 150 return result, nil | 152 return result, nil |
| 151 } | 153 } |
| 154 |
| 155 // GetLimit extracts the "limit", "numbuilds", or "num_builds" http param from |
| 156 // the request, or returns "-1" implying no limit was specified. |
| 157 func GetLimit(r *http.Request) (int, error) { |
| 158 sLimit := r.FormValue("limit") |
| 159 if sLimit == "" { |
| 160 sLimit = r.FormValue("numbuilds") |
| 161 if sLimit == "" { |
| 162 sLimit = r.FormValue("num_builds") |
| 163 if sLimit == "" { |
| 164 return -1, nil |
| 165 } |
| 166 } |
| 167 } |
| 168 limit, err := strconv.Atoi(sLimit) |
| 169 if err != nil { |
| 170 return -1, &miloerror.Error{ |
| 171 Message: fmt.Sprintf("limit parameter value %q is not a
number: %s", sLimit, err), |
| 172 Code: http.StatusBadRequest, |
| 173 } |
| 174 } |
| 175 if limit < 0 { |
| 176 return -1, &miloerror.Error{ |
| 177 Message: fmt.Sprintf("limit parameter value %q is less t
han 0", sLimit), |
| 178 Code: http.StatusBadRequest, |
| 179 } |
| 180 } |
| 181 return limit, nil |
| 182 } |
| OLD | NEW |