MCPcopy Index your code
hub / github.com/coder/coder / populateHTMLState

Method populateHTMLState

site/site.go:457–535  ·  view source on GitHub ↗

populateHTMLState runs concurrent goroutines to populate all authenticated user metadata in the HTML state. This is extracted from renderHTMLWithState to reduce nesting complexity.

(
	ctx context.Context,
	state *htmlState,
	af appearance.Fetcher,
	actor *rbac.Subject,
	user database.User,
	orgIDs []uuid.UUID,
	userOrgs []database.Organization,
	userAppearance codersdk.UserAppearanceSettings,
)

Source from the content-addressed store, hash-verified

455// authenticated user metadata in the HTML state. This is extracted
456// from renderHTMLWithState to reduce nesting complexity.
457func (h *Handler) populateHTMLState(
458 ctx context.Context,
459 state *htmlState,
460 af appearance.Fetcher,
461 actor *rbac.Subject,
462 user database.User,
463 orgIDs []uuid.UUID,
464 userOrgs []database.Organization,
465 userAppearance codersdk.UserAppearanceSettings,
466) {
467 var wg sync.WaitGroup
468 wg.Go(func() {
469 data, err := json.Marshal(db2sdk.User(user, orgIDs))
470 if err == nil {
471 state.User = html.EscapeString(string(data))
472 }
473 })
474 wg.Go(func() {
475 data, err := json.Marshal(userAppearance)
476 if err == nil {
477 state.UserAppearance = html.EscapeString(string(data))
478 }
479 })
480 if h.Entitlements != nil {
481 wg.Go(func() {
482 state.Entitlements = html.EscapeString(string(h.Entitlements.AsJSON()))
483 })
484 }
485 wg.Go(func() {
486 cfg, err := af.Fetch(ctx)
487 if err == nil {
488 appr, err := json.Marshal(cfg)
489 if err == nil {
490 state.Appearance = html.EscapeString(string(appr))
491 state.ApplicationName = html.EscapeString(applicationNameOrDefault(cfg))
492 state.LogoURL = html.EscapeString(cfg.LogoURL)
493 }
494 }
495 })
496 if h.RegionsFetcher != nil {
497 wg.Go(func() {
498 regions, err := h.RegionsFetcher(ctx)
499 if err == nil {
500 data, err := json.Marshal(regions)
501 if err == nil {
502 state.Regions = html.EscapeString(string(data))
503 }
504 }
505 })
506 }
507 experiments := h.Experiments.Load()
508 if experiments != nil {
509 wg.Go(func() {
510 data, err := json.Marshal(experiments)
511 if err == nil {
512 state.Experiments = html.EscapeString(string(data))
513 }
514 })

Callers 1

renderHTMLWithStateMethod · 0.95

Implementers 8

dispatchInterceptorcoderd/notifications/utils_test.go
chanHandlercoderd/notifications/utils_test.go
barrierHandlercoderd/notifications/metrics_test.go
fakeHandlercoderd/notifications/notifications_tes
santaHandlercoderd/notifications/manager_test.go
InboxHandlercoderd/notifications/dispatch/inbox.go
SMTPHandlercoderd/notifications/dispatch/smtp.go
WebhookHandlercoderd/notifications/dispatch/webhook.

Calls 10

renderPermissionsMethod · 0.95
UserFunction · 0.92
ListFunction · 0.92
applicationNameOrDefaultFunction · 0.85
GoMethod · 0.80
AsJSONMethod · 0.80
FetchMethod · 0.65
WaitMethod · 0.65
MarshalMethod · 0.45
LoadMethod · 0.45

Tested by

no test coverage detected