Files
pages/internal/server/request_context.go
T
Anya Tokugawa d5d21b7841
Build and publish container images / images (push) Successful in 9m34s
Release container images / release (push) Successful in 36s
Refactor architecture into eight components and consolidate reliability work
Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts.

Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation.

Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
2026-11-01 15:23:31 +09:00

109 lines
3.0 KiB
Go

package server
import (
"net/http"
"net/url"
"pageswiki/internal/store"
)
type RequestContext struct {
Campus *store.Campus
Domain *store.Domain
}
func (s *Server) BuildRequestContext(
r *http.Request,
) *RequestContext {
domain :=
s.domainForRequest(
r,
)
return &RequestContext{
Campus: s.campusForDomain(
domain,
),
Domain: domain,
}
}
func (s *Server) renderWithContext(
w http.ResponseWriter,
r *http.Request,
name string,
data map[string]any,
) {
if data == nil {
data = map[string]any{}
}
data["Context"] =
s.BuildRequestContext(
r,
)
data["AuthUser"] = nil
data["AuthIsAdmin"] = false
domainUUID := s.domainUUIDForRequest(r)
data["CommandEnabled"] = name != "home.gohtml" && name != "search_home.gohtml" && r.URL.Path != "/"
data["CommandBrowser"] = name == "browser.gohtml"
data["CommandPath"] = "/"
if semantic, ok := data["Path"].(string); ok && len(semantic) > 0 && semantic[0] == '/' {
data["CommandPath"] = semantic
}
data["QuickThemes"] = themeOptions()
data["DefaultThemeCSS"] = s.getThemeCSS(domainUUID)
data["QuickThemeID"] = ""
if cookie, err := r.Cookie("pageswiki_theme"); err == nil {
id, decodeErr := url.PathUnescape(cookie.Value)
if theme, ok := findTheme(id); ok && decodeErr == nil {
// Presentation only: never change the Domain's configured theme.
data["ThemeCSS"] = theme.CSS
data["QuickThemeID"] = theme.ID
}
}
w.Header().Add("Vary", "Cookie")
data["CalendarEnabled"] = s.systemExtensionEnabled(domainUUID, "organizer.calendar")
data["TasksEnabled"] = s.systemExtensionEnabled(domainUUID, "organizer.tasks")
if r.URL.Path == "/" {
data["IsHome"] = true
data["BookmarkSections"] = s.bookmarkSections(r)
canConfigureHome := s.canManageAssets(r)
if controlled, err := s.store.DomainEntryControlled(domainUUID); err != nil || controlled {
canConfigureHome = false
}
data["CanManageBookmarks"] = s.canManageAssets(r)
data["CanConfigureHome"] = canConfigureHome
transparency := s.homeGlassTransparency(domainUUID)
data["HomeGlassTransparency"] = transparency
data["HomeGlassOpacity"] = 100 - transparency
wallpaper := s.homeWallpaperForRequest(r)
data["HomeWallpaperURL"] = wallpaper.URL
data["HomeWallpaperOpacity"] = wallpaper.Opacity
if wallpaper.URL != "" {
w.Header().Set("Cache-Control", "private, no-cache")
}
if data["CanManageBookmarks"] == true {
data["ManagedBookmarks"] = s.managedBookmarks(domainUUID)
}
}
if _, ok := data["Locale"]; !ok {
data["Locale"] = s.getLocale(domainUUID)
}
if token := s.authTokenFromRequest(r); token != "" {
if principal, err := s.store.PrincipalForSession(domainUUID, token); err == nil {
data["AuthUser"] = principal
data["AuthIsAdmin"] = s.store.Authorize(store.AuthorizationRequest{DomainUUID: domainUUID, PrincipalUUID: principal.UUID, Capability: "manage", TargetType: "domain", TargetID: domainUUID}) == nil
}
}
data["SocialMetadata"] = s.socialMetadataForRequest(r, name, data)
s.render(
w,
name,
data,
)
}