comparison pkg/controllers/importconfig.go @ 5399:47c2ca05e8ec

Merged extented-report branch back into default.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 07 Jul 2021 11:44:40 +0200
parents e09e003948c7
children
comparison
equal deleted inserted replaced
5319:4a6feb5d3727 5399:47c2ca05e8ec
28 "gemma.intevation.de/gemma/pkg/scheduler" 28 "gemma.intevation.de/gemma/pkg/scheduler"
29 29
30 mw "gemma.intevation.de/gemma/pkg/middleware" 30 mw "gemma.intevation.de/gemma/pkg/middleware"
31 ) 31 )
32 32
33 // RolesRequierer enforces roles when storing schedules.
34 type RolesRequierer interface {
35 RequiresRoles() auth.Roles
36 }
37
33 func runImportConfig(req *http.Request) (jr mw.JSONResult, err error) { 38 func runImportConfig(req *http.Request) (jr mw.JSONResult, err error) {
34 39
35 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) 40 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64)
36 41
37 ctx := req.Context() 42 ctx := req.Context()
260 Message: fmt.Sprintf("No kind %s found", string(cfg.Kind)), 265 Message: fmt.Sprintf("No kind %s found", string(cfg.Kind)),
261 } 266 }
262 return 267 return
263 } 268 }
264 config := ctor() 269 config := ctor()
270
271 session, _ := auth.GetSession(req)
272
273 if r, ok := config.(RolesRequierer); ok {
274 if roles := r.RequiresRoles(); len(roles) > 0 && !session.Roles.HasAny(roles...) {
275 err = mw.JSONError{
276 Code: http.StatusUnauthorized,
277 Message: fmt.Sprintf(
278 "Not allowed to add config for kind %s", string(cfg.Kind)),
279 }
280 return
281 }
282 }
265 if err = json.Unmarshal(cfg.Config, config); err != nil { 283 if err = json.Unmarshal(cfg.Config, config); err != nil {
266 return 284 return
267 } 285 }
268
269 session, _ := auth.GetSession(req)
270 286
271 pc := imports.PersistentConfig{ 287 pc := imports.PersistentConfig{
272 User: session.User, 288 User: session.User,
273 Kind: string(cfg.Kind), 289 Kind: string(cfg.Kind),
274 Attributes: common.Attributes{}, 290 Attributes: common.Attributes{},