Mercurial > gemma
comparison pkg/controllers/user.go @ 4243:d776110b4db0 json-handler-middleware
Made the de-serialized input of the JSON handler accessible via the context of the request.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 22 Aug 2019 10:54:08 +0200 |
parents | 1458c9b0fdaa |
children | 4394daeea96a |
comparison
equal
deleted
inserted
replaced
4242:1458c9b0fdaa | 4243:d776110b4db0 |
---|---|
95 When the status of an data import managed by you changes an automated mail will | 95 When the status of an data import managed by you changes an automated mail will |
96 be send to the address: {{ .Email }} with details on the new import status | 96 be send to the address: {{ .Email }} with details on the new import status |
97 (inkluding import errors) and details on the concerned import.`)) | 97 (inkluding import errors) and details on the concerned import.`)) |
98 ) | 98 ) |
99 | 99 |
100 func deleteUser( | 100 func deleteUser(req *http.Request) (jr JSONResult, err error) { |
101 _ interface{}, req *http.Request, | |
102 ) (jr JSONResult, err error) { | |
103 | 101 |
104 user := mux.Vars(req)["user"] | 102 user := mux.Vars(req)["user"] |
105 if !models.UserName(user).IsValid() { | 103 if !models.UserName(user).IsValid() { |
106 err = JSONError{http.StatusBadRequest, "error: user invalid"} | 104 err = JSONError{http.StatusBadRequest, "error: user invalid"} |
107 return | 105 return |
146 | 144 |
147 jr = JSONResult{Code: http.StatusNoContent} | 145 jr = JSONResult{Code: http.StatusNoContent} |
148 return | 146 return |
149 } | 147 } |
150 | 148 |
151 func updateUser( | 149 func updateUser(req *http.Request) (jr JSONResult, err error) { |
152 input interface{}, | |
153 req *http.Request, | |
154 ) (jr JSONResult, err error) { | |
155 | 150 |
156 user := models.UserName(mux.Vars(req)["user"]) | 151 user := models.UserName(mux.Vars(req)["user"]) |
157 if !user.IsValid() { | 152 if !user.IsValid() { |
158 err = JSONError{http.StatusBadRequest, "error: user invalid"} | 153 err = JSONError{http.StatusBadRequest, "error: user invalid"} |
159 return | 154 return |
160 } | 155 } |
161 | 156 |
162 newUser := input.(*models.User) | 157 newUser := JSONInput(req).(*models.User) |
163 var res sql.Result | 158 var res sql.Result |
164 | 159 |
165 db := JSONConn(req) | 160 db := JSONConn(req) |
166 | 161 |
167 if s, _ := auth.GetSession(req); s.Roles.Has("sys_admin") { | 162 if s, _ := auth.GetSession(req); s.Roles.Has("sys_admin") { |
230 }{"success"}, | 225 }{"success"}, |
231 } | 226 } |
232 return | 227 return |
233 } | 228 } |
234 | 229 |
235 func createUser( | 230 func createUser(req *http.Request) (jr JSONResult, err error) { |
236 input interface{}, | 231 |
237 req *http.Request, | 232 user := JSONInput(req).(*models.User) |
238 ) (jr JSONResult, err error) { | |
239 | |
240 user := input.(*models.User) | |
241 | 233 |
242 db := JSONConn(req) | 234 db := JSONConn(req) |
243 | 235 |
244 if user.Extent == nil { | 236 if user.Extent == nil { |
245 _, err = db.ExecContext( | 237 _, err = db.ExecContext( |
278 }{"success"}, | 270 }{"success"}, |
279 } | 271 } |
280 return | 272 return |
281 } | 273 } |
282 | 274 |
283 func listUsers( | 275 func listUsers(req *http.Request) (jr JSONResult, err error) { |
284 _ interface{}, | |
285 req *http.Request, | |
286 ) (jr JSONResult, err error) { | |
287 | 276 |
288 var rows *sql.Rows | 277 var rows *sql.Rows |
289 | 278 |
290 rows, err = JSONConn(req).QueryContext(req.Context(), listUsersSQL) | 279 rows, err = JSONConn(req).QueryContext(req.Context(), listUsersSQL) |
291 if err != nil { | 280 if err != nil { |
316 }{users}, | 305 }{users}, |
317 } | 306 } |
318 return | 307 return |
319 } | 308 } |
320 | 309 |
321 func listUser( | 310 func listUser(req *http.Request) (jr JSONResult, err error) { |
322 _ interface{}, | |
323 req *http.Request, | |
324 ) (jr JSONResult, err error) { | |
325 | 311 |
326 user := models.UserName(mux.Vars(req)["user"]) | 312 user := models.UserName(mux.Vars(req)["user"]) |
327 if !user.IsValid() { | 313 if !user.IsValid() { |
328 err = JSONError{http.StatusBadRequest, "error: user invalid"} | 314 err = JSONError{http.StatusBadRequest, "error: user invalid"} |
329 return | 315 return |
355 | 341 |
356 jr.Result = result | 342 jr.Result = result |
357 return | 343 return |
358 } | 344 } |
359 | 345 |
360 func sendTestMail( | 346 func sendTestMail(req *http.Request) (jr JSONResult, err error) { |
361 _ interface{}, | |
362 req *http.Request, | |
363 ) (jr JSONResult, err error) { | |
364 | 347 |
365 user := models.UserName(mux.Vars(req)["user"]) | 348 user := models.UserName(mux.Vars(req)["user"]) |
366 if !user.IsValid() { | 349 if !user.IsValid() { |
367 err = JSONError{http.StatusBadRequest, "error: user invalid"} | 350 err = JSONError{http.StatusBadRequest, "error: user invalid"} |
368 return | 351 return |