Implement Knowledge City platform, organizer and DAV integration
Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
This commit is contained in:
1 parent
288e6e94ac
commit
c1175d389f
699 files changed
+110197
-4117
No files matched your search
@@ -1,7 +1,11 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func mergeTemplateData(
|
||||
@@ -15,7 +19,8 @@ func mergeTemplateData(
|
||||
"WikiName": wikiName,
|
||||
"Theme": theme,
|
||||
"ThemeCSS": sThemeCSS,
|
||||
"District": nil,
|
||||
"Campus": nil,
|
||||
"Domain": nil,
|
||||
}
|
||||
|
||||
if data == nil {
|
||||
@@ -41,21 +46,85 @@ func (s *Server) render(
|
||||
name string,
|
||||
data any,
|
||||
) {
|
||||
domain := s.currentDomain()
|
||||
campus := s.currentCampus()
|
||||
if values, ok := data.(map[string]any); ok {
|
||||
if context, ok := values["Context"].(*RequestContext); ok {
|
||||
if context.Domain != nil {
|
||||
domain = context.Domain
|
||||
}
|
||||
if context.Campus != nil {
|
||||
campus = context.Campus
|
||||
}
|
||||
}
|
||||
}
|
||||
domainUUID := ""
|
||||
if domain != nil {
|
||||
domainUUID = domain.UUID
|
||||
}
|
||||
nonce := ""
|
||||
if safeProjectionTemplate(name) {
|
||||
var err error
|
||||
nonce, err = setProjectionCSP(w, s.externalResourcePolicy(domainUUID))
|
||||
if err != nil {
|
||||
http.Error(w, "could not secure HTML projection", 500)
|
||||
return
|
||||
}
|
||||
if name == "public_periodical.gohtml" {
|
||||
if values, ok := data.(map[string]any); ok {
|
||||
if origin, ok := values["PublicMediaOrigin"].(string); ok {
|
||||
u, err := url.Parse(origin)
|
||||
if err == nil && (u.Scheme == "https" || u.Scheme == "http") && u.Host != "" && u.User == nil && u.Path == "" && !strings.ContainsAny(origin, " ;\r\n\t") {
|
||||
w.Header().Set("Content-Security-Policy", strings.Replace(w.Header().Get("Content-Security-Policy"), "img-src 'self'", "img-src 'self' "+origin, 1))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
templates, err := s.templates.Clone()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
// Template helpers run for each row/cell. Resolve configuration once per
|
||||
// render instead of issuing locale/timezone queries for every invocation.
|
||||
locale := s.getLocale(domainUUID)
|
||||
location := s.getLocation(domainUUID)
|
||||
templates = templates.Funcs(template.FuncMap{
|
||||
"cspNonce": func() string { return nonce },
|
||||
"T": func(key string) string {
|
||||
return translate(locale, key)
|
||||
},
|
||||
"formatUnix": func(ts int64) string {
|
||||
return time.Unix(ts, 0).
|
||||
In(location).
|
||||
Format("2006-01-02 15:04:05 MST")
|
||||
},
|
||||
"formatUnixMS": func(ts int64) string {
|
||||
if ts <= 0 {
|
||||
return "-"
|
||||
}
|
||||
return time.UnixMilli(ts).In(location).Format("2006-01-02 15:04")
|
||||
},
|
||||
})
|
||||
|
||||
err := s.templates.ExecuteTemplate(
|
||||
err = templates.ExecuteTemplate(
|
||||
w,
|
||||
name,
|
||||
func() map[string]any {
|
||||
m :=
|
||||
mergeTemplateData(
|
||||
data,
|
||||
s.getWikiName(),
|
||||
s.getTheme(),
|
||||
s.getThemeCSS(),
|
||||
s.getWikiName(domainUUID),
|
||||
s.getTheme(domainUUID),
|
||||
s.getThemeCSS(domainUUID),
|
||||
)
|
||||
|
||||
m["District"] =
|
||||
s.currentDistrict()
|
||||
m["Domain"] = domain
|
||||
m["Campus"] = campus
|
||||
if _, ok := m["Timezone"]; !ok {
|
||||
m["Timezone"] = location.String()
|
||||
}
|
||||
|
||||
return m
|
||||
}(),
|
||||
|
||||
Reference in new issue
Block a user