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:
Anya Tokugawa committed 2026-09-27 14:44:43 +09:00
1 parent 288e6e94ac
commit c1175d389f
699 files changed
+110197 -4117

No files matched your search

+115
View File
@@ -0,0 +1,115 @@
package server
import (
"encoding/xml"
"errors"
"mime"
"net/http"
"strings"
"github.com/google/uuid"
mw "pageswiki/internal/server/middleware"
"pageswiki/internal/store"
)
func (s *Server) appendTaskDAVCollections(w http.ResponseWriter, r *http.Request, domain, actor string, writable bool, rows *[]davResponse) bool {
items, err := s.store.TaskDAVCollections(r.Context(), domain, actor)
if err != nil {
taskError(w, err)
return false
}
for _, item := range items {
row := taskDAVCollectionRow()
row.href = calendarDAV + item.TaskDAVCollectionPath() + "/"
row.props[xml.Name{Space: davNS, Local: "displayname"}] = xmlText(item.Title)
row.props[xml.Name{Space: davNS, Local: "current-user-privilege-set"}] = davPrivileges(writable)
row.props[xml.Name{Space: davNS, Local: "current-user-principal"}] = "<d:href>" + calendarDAV + "</d:href>"
*rows = append(*rows, row)
}
return true
}
// A VTODO collection is a private revisioned project. Do not alias every
// arbitrary client URL to the default list or silently accept VEVENT lists.
func (s *Server) handleTaskMKCalendar(w http.ResponseWriter, r *http.Request) {
mw.SetDAVTaskTarget(r, false)
domain := s.domainUUIDForRequest(r)
if !s.systemExtensionEnabled(domain, "organizer.tasks") {
http.NotFound(w, r)
return
}
actor, write, _, credential, ok := s.davActor(w, r, "tasks", false)
if !ok {
return
}
s.setDAVCapabilities(w, r, actor, credential)
if !write {
taskError(w, store.ErrAccessDenied)
return
}
path := strings.TrimSuffix(strings.TrimPrefix(r.URL.Path, calendarDAV), "/")
id, err := uuid.Parse(path)
if err != nil || id.String() != path {
taskDAVError(w, 403, "calendar-collection-location-ok", "VTODO collections require a UUID directly below the CalDAV home")
return
}
media, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
if err != nil || media != "application/xml" && media != "text/xml" {
w.WriteHeader(415)
return
}
n, err := readDAV(w, r)
if err != nil || n.XMLName != (xml.Name{Space: calNS, Local: "mkcalendar"}) || len(n.Children) != 1 {
http.Error(w, "invalid MKCALENDAR", 400)
return
}
set := n.Children[0]
if set.XMLName != (xml.Name{Space: davNS, Local: "set"}) || len(set.Children) != 1 || set.Children[0].XMLName != (xml.Name{Space: davNS, Local: "prop"}) {
http.Error(w, "invalid MKCALENDAR properties", 400)
return
}
title, component := path, false
seen := map[xml.Name]bool{}
for _, p := range set.Children[0].Children {
if seen[p.XMLName] {
http.Error(w, "duplicate property", 400)
return
}
seen[p.XMLName] = true
switch p.XMLName {
case xml.Name{Space: davNS, Local: "displayname"}:
if len(p.Children) != 0 || taskDAVAttrCount(p) != 0 {
http.Error(w, "invalid displayname", 400)
return
}
title = p.Text
case xml.Name{Space: calNS, Local: "supported-calendar-component-set"}:
if taskDAVAttrCount(p) != 0 || len(p.Children) != 1 || p.Children[0].XMLName != (xml.Name{Space: calNS, Local: "comp"}) || p.Children[0].attr("name") != "VTODO" || taskDAVAttrCount(p.Children[0]) != 1 || len(p.Children[0].Children) != 0 {
taskDAVError(w, 403, "supported-calendar-component", "Only VTODO collections are supported by MKCALENDAR")
return
}
component = true
default:
taskDAVError(w, 403, "supported-calendar-data", "Unsupported MKCALENDAR property; no collection was created")
return
}
}
if !component {
taskDAVError(w, 403, "supported-calendar-component", "An explicit VTODO component-set is required")
return
}
_, err = s.store.CreateTaskDAVCollection(r.Context(), domain, actor, path, title, credential)
if errors.Is(err, store.ErrTaskDAVCollectionExists) {
w.Header().Set("Content-Type", "application/xml; charset=utf-8")
w.WriteHeader(405)
w.Write([]byte(`<d:error xmlns:d="DAV:"><d:resource-must-be-null/></d:error>`))
return
}
if err != nil {
taskError(w, err)
return
}
w.Header().Set("Cache-Control", "private, no-cache, no-store")
w.Header().Set("Location", calendarDAV+path+"/")
w.WriteHeader(201)
}