Skip to content

Commit

Permalink
add debug logging for user context and web render
Browse files Browse the repository at this point in the history
  • Loading branch information
spacehamster87 committed Oct 31, 2024
1 parent c120d65 commit eabc621
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/repository/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,10 @@ const ContextUserKey ContextKey = "user"
func GetUserFromContext(ctx context.Context) *schema.User {
x := ctx.Value(ContextUserKey)
if x == nil {
log.Warnf("no user retrieved from context")
return nil
}

log.Infof("user retrieved from context: %v", x.(*schema.User))
return x.(*schema.User)
}

Expand Down
11 changes: 11 additions & 0 deletions internal/routerConfig/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,22 +254,31 @@ func SetupRoutes(router *mux.Router, buildInfo web.Build) {
for _, route := range routes {
route := route
router.HandleFunc(route.Route, func(rw http.ResponseWriter, r *http.Request) {

log.Info(">>> HELLO ROUTE HANDLER ...")

conf, err := userCfgRepo.GetUIConfig(repository.GetUserFromContext(r.Context()))
if err != nil {
http.Error(rw, err.Error(), http.StatusInternalServerError)
return
}

title := route.Title
log.Infof(">>> >>> ROUTE TITLE : %s ", title)

infos := route.Setup(map[string]interface{}{}, r)
if id, ok := infos["id"]; ok {
title = strings.Replace(route.Title, "<ID>", id.(string), 1)
}
log.Infof(">>> >>> ROUTE INFOS : %v ", infos)

// Get User -> What if NIL?
user := repository.GetUserFromContext(r.Context())
log.Infof(">>> >>> ROUTE USER : %v ", *user)

// Get Roles
availableRoles, _ := schema.GetValidRolesMap(user)
log.Infof(">>> >>> ROUTE AVAILABLE ROLES : %v ", availableRoles)

page := web.Page{
Title: title,
Expand All @@ -279,10 +288,12 @@ func SetupRoutes(router *mux.Router, buildInfo web.Build) {
Config: conf,
Infos: infos,
}
log.Infof(">>> >>> ROUTE PAGE : %v ", page)

if route.Filter {
page.FilterPresets = buildFilterPresets(r.URL.Query())
}
log.Infof(">>> >>> ROUTE FILTER : %v ", page.FilterPresets)

web.RenderTemplate(rw, route.Template, &page)
})
Expand Down

0 comments on commit eabc621

Please sign in to comment.