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
@@ -0,0 +1,89 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"mime"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
// A deliberately bounded PROPPATCH surface: default-list DAV:displayname only.
|
||||
// Validate the whole instruction sequence before saving anything. Unsupported
|
||||
// properties fail independently, with 424 for otherwise-valid dependent edits.
|
||||
func (s *Server) handleTaskDAVDefaultProperties(w http.ResponseWriter, r *http.Request, domain, actor, credential string) {
|
||||
media, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
||||
if err != nil || media != "application/xml" && media != "text/xml" {
|
||||
w.WriteHeader(http.StatusUnsupportedMediaType)
|
||||
return
|
||||
}
|
||||
if v := r.Header.Get("If-Match"); v != "" && v != "*" || r.Header.Get("If-None-Match") == "*" {
|
||||
w.WriteHeader(http.StatusPreconditionFailed)
|
||||
return
|
||||
}
|
||||
n, err := readDAV(w, r)
|
||||
if err != nil || n.XMLName != (xml.Name{Space: davNS, Local: "propertyupdate"}) || len(n.Children) == 0 || taskDAVAttrCount(n) != 0 || strings.TrimSpace(n.Text) != "" {
|
||||
http.Error(w, "invalid propertyupdate", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
var properties []xml.Name
|
||||
statuses := map[xml.Name]int{}
|
||||
title := ""
|
||||
failed := false
|
||||
for _, instruction := range n.Children {
|
||||
if instruction.XMLName.Space != davNS || (instruction.XMLName.Local != "set" && instruction.XMLName.Local != "remove") || taskDAVAttrCount(instruction) != 0 || strings.TrimSpace(instruction.Text) != "" || len(instruction.Children) != 1 {
|
||||
http.Error(w, "invalid property instruction", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
prop := instruction.Children[0]
|
||||
if prop.XMLName != (xml.Name{Space: davNS, Local: "prop"}) || len(prop.Children) == 0 || taskDAVAttrCount(prop) != 0 || strings.TrimSpace(prop.Text) != "" {
|
||||
http.Error(w, "invalid properties", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
for _, p := range prop.Children {
|
||||
if _, exists := statuses[p.XMLName]; !exists {
|
||||
properties = append(properties, p.XMLName)
|
||||
statuses[p.XMLName] = http.StatusOK
|
||||
}
|
||||
if instruction.XMLName.Local != "set" || p.XMLName != (xml.Name{Space: davNS, Local: "displayname"}) || len(p.Children) != 0 || taskDAVAttrCount(p) != 0 {
|
||||
statuses[p.XMLName], failed = http.StatusForbidden, true
|
||||
continue
|
||||
}
|
||||
if !store.ValidTaskDAVTitle(p.Text) {
|
||||
statuses[p.XMLName], failed = http.StatusConflict, true
|
||||
continue
|
||||
}
|
||||
title = p.Text
|
||||
}
|
||||
}
|
||||
if !failed {
|
||||
err = s.store.SetTaskDAVDefaultTitle(r.Context(), domain, actor, title, credential)
|
||||
if errors.Is(err, store.ErrTaskInvalid) {
|
||||
statuses[xml.Name{Space: davNS, Local: "displayname"}], failed = http.StatusConflict, true
|
||||
} else if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/xml; charset=utf-8")
|
||||
w.WriteHeader(http.StatusMultiStatus)
|
||||
io.WriteString(w, `<?xml version="1.0" encoding="UTF-8"?><d:multistatus xmlns:d="DAV:"><d:response><d:href>`+taskDAVCollection+`</d:href>`)
|
||||
for _, p := range properties {
|
||||
status := statuses[p]
|
||||
if failed && status == http.StatusOK {
|
||||
status = http.StatusFailedDependency
|
||||
}
|
||||
io.WriteString(w, `<d:propstat><d:prop>`)
|
||||
if p.Space == "" {
|
||||
fmt.Fprintf(w, `<%s/>`, p.Local)
|
||||
} else {
|
||||
fmt.Fprintf(w, `<p:%s xmlns:p="%s"/>`, p.Local, xmlText(p.Space))
|
||||
}
|
||||
fmt.Fprintf(w, `</d:prop><d:status>HTTP/1.1 %d %s</d:status></d:propstat>`, status, http.StatusText(status))
|
||||
}
|
||||
io.WriteString(w, `</d:response></d:multistatus>`)
|
||||
}
|
||||
Reference in new issue
Block a user