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, )
| 455 | // authenticated user metadata in the HTML state. This is extracted |
| 456 | // from renderHTMLWithState to reduce nesting complexity. |
| 457 | func (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 | }) |
no test coverage detected