mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-12-26 05:19:05 +01:00
add debug logging for user context and web render
This commit is contained in:
parent
c120d6517f
commit
eabc6212ea
@ -321,9 +321,10 @@ const ContextUserKey ContextKey = "user"
|
|||||||
func GetUserFromContext(ctx context.Context) *schema.User {
|
func GetUserFromContext(ctx context.Context) *schema.User {
|
||||||
x := ctx.Value(ContextUserKey)
|
x := ctx.Value(ContextUserKey)
|
||||||
if x == nil {
|
if x == nil {
|
||||||
|
log.Warnf("no user retrieved from context")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
log.Infof("user retrieved from context: %v", x.(*schema.User))
|
||||||
return x.(*schema.User)
|
return x.(*schema.User)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,6 +254,9 @@ func SetupRoutes(router *mux.Router, buildInfo web.Build) {
|
|||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
route := route
|
route := route
|
||||||
router.HandleFunc(route.Route, func(rw http.ResponseWriter, r *http.Request) {
|
router.HandleFunc(route.Route, func(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
log.Info(">>> HELLO ROUTE HANDLER ...")
|
||||||
|
|
||||||
conf, err := userCfgRepo.GetUIConfig(repository.GetUserFromContext(r.Context()))
|
conf, err := userCfgRepo.GetUIConfig(repository.GetUserFromContext(r.Context()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||||
@ -261,15 +264,21 @@ func SetupRoutes(router *mux.Router, buildInfo web.Build) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
title := route.Title
|
title := route.Title
|
||||||
|
log.Infof(">>> >>> ROUTE TITLE : %s ", title)
|
||||||
|
|
||||||
infos := route.Setup(map[string]interface{}{}, r)
|
infos := route.Setup(map[string]interface{}{}, r)
|
||||||
if id, ok := infos["id"]; ok {
|
if id, ok := infos["id"]; ok {
|
||||||
title = strings.Replace(route.Title, "<ID>", id.(string), 1)
|
title = strings.Replace(route.Title, "<ID>", id.(string), 1)
|
||||||
}
|
}
|
||||||
|
log.Infof(">>> >>> ROUTE INFOS : %v ", infos)
|
||||||
|
|
||||||
// Get User -> What if NIL?
|
// Get User -> What if NIL?
|
||||||
user := repository.GetUserFromContext(r.Context())
|
user := repository.GetUserFromContext(r.Context())
|
||||||
|
log.Infof(">>> >>> ROUTE USER : %v ", *user)
|
||||||
|
|
||||||
// Get Roles
|
// Get Roles
|
||||||
availableRoles, _ := schema.GetValidRolesMap(user)
|
availableRoles, _ := schema.GetValidRolesMap(user)
|
||||||
|
log.Infof(">>> >>> ROUTE AVAILABLE ROLES : %v ", availableRoles)
|
||||||
|
|
||||||
page := web.Page{
|
page := web.Page{
|
||||||
Title: title,
|
Title: title,
|
||||||
@ -279,10 +288,12 @@ func SetupRoutes(router *mux.Router, buildInfo web.Build) {
|
|||||||
Config: conf,
|
Config: conf,
|
||||||
Infos: infos,
|
Infos: infos,
|
||||||
}
|
}
|
||||||
|
log.Infof(">>> >>> ROUTE PAGE : %v ", page)
|
||||||
|
|
||||||
if route.Filter {
|
if route.Filter {
|
||||||
page.FilterPresets = buildFilterPresets(r.URL.Query())
|
page.FilterPresets = buildFilterPresets(r.URL.Query())
|
||||||
}
|
}
|
||||||
|
log.Infof(">>> >>> ROUTE FILTER : %v ", page.FilterPresets)
|
||||||
|
|
||||||
web.RenderTemplate(rw, route.Template, &page)
|
web.RenderTemplate(rw, route.Template, &page)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user