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.
73 lines
2.1 KiB
Go
73 lines
2.1 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"net/http"
|
|
"pageswiki/internal/store"
|
|
"strings"
|
|
)
|
|
|
|
// Issuing/revoking credentials requires a normal login session. A DAV password
|
|
// is deliberately not valid on this management API or any other Wiki endpoint.
|
|
func (s *Server) handleTaskDAVCredentials(w http.ResponseWriter, r *http.Request, actor string, parts []string) {
|
|
domain := s.domainUUIDForRequest(r)
|
|
endpoint := calendarDAV
|
|
if strings.HasPrefix(r.URL.Path, tasksAPI) {
|
|
endpoint = taskDAVRoot
|
|
}
|
|
if len(parts) == 1 && r.Method == "GET" {
|
|
items, e := s.store.ListTaskDAVCredentials(r.Context(), domain, actor)
|
|
if e != nil {
|
|
taskError(w, e)
|
|
return
|
|
}
|
|
writeEventJSON(w, 200, map[string]any{"items": items, "url": endpoint})
|
|
return
|
|
}
|
|
if len(parts) == 2 && r.Method == "DELETE" {
|
|
if e := s.store.RevokeTaskDAVCredential(r.Context(), domain, actor, parts[1]); e != nil {
|
|
taskError(w, e)
|
|
return
|
|
}
|
|
w.WriteHeader(204)
|
|
return
|
|
}
|
|
if len(parts) != 1 || r.Method != "POST" {
|
|
w.WriteHeader(405)
|
|
return
|
|
}
|
|
var body struct {
|
|
Label string `json:"label"`
|
|
Write bool `json:"write"`
|
|
Days int `json:"days"`
|
|
Scope string `json:"scope"`
|
|
CalendarAccessCompat bool `json:"calendar_access_compat"`
|
|
}
|
|
d := json.NewDecoder(http.MaxBytesReader(w, r.Body, 2048))
|
|
d.DisallowUnknownFields()
|
|
if d.Decode(&body) != nil || d.Decode(&struct{}{}) != io.EOF {
|
|
taskError(w, store.ErrTaskInvalid)
|
|
return
|
|
}
|
|
if body.Days == 0 {
|
|
body.Days = 90
|
|
}
|
|
if body.Scope == "" {
|
|
body.Scope = "tasks" // Preserve the legacy API's authority boundary.
|
|
}
|
|
credential, password, e := s.store.CreateDAVCredential(r.Context(), domain, actor, body.Label, body.Write, body.Days, body.Scope, body.CalendarAccessCompat)
|
|
if e != nil {
|
|
taskError(w, e)
|
|
return
|
|
}
|
|
if body.Scope != "tasks" {
|
|
endpoint = calendarDAV
|
|
}
|
|
response := map[string]any{"credential": credential, "username": credential.ID, "password": password, "url": endpoint}
|
|
if body.Scope == "tasks" {
|
|
response["collection"] = taskDAVCollection
|
|
}
|
|
writeEventJSON(w, 201, response)
|
|
}
|