CI / go (Media) (push) Successful in 13m40s
CI / go (Server) (push) Failing after 23m20s
CI / go (Web-App) (push) Canceled after 0s
CI / frontend (push) Failing after 10m35s
Docs / build (push) Canceled after 0s
Docs / deploy (push) Canceled after 0s
CI / desktop (ubuntu-latest) (push) Failing after 3h4m42s
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
CI / mobile (push) Failing after 9m19s
CI / docker (push) Successful in 2h2m57s
- Columns: /columns puts 2 to 4 columns side by side, with widths dragged between them; they stack on phones. HTML export and import keep them (also Notion column lists and Confluence page layouts). - Suggesting mode: edits become suggested insertions and deletions that editors accept or reject one by one or all at once. Text only. - Verified pages: editors verify a page for a while or without end; the verifier is notified when it runs out (migration 1764700000). - Scanned PDFs attached to pages are read by AI for search where a workspace turns it on. - The server writes error messages, emails, digests and phone notifications in English, Polish, German, French and Spanish; the apps send their language with each request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
207 lines
10 KiB
Go
207 lines
10 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package httpapi
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"docwell/server/internal/access"
|
|
"docwell/server/internal/collab"
|
|
"docwell/server/internal/directory"
|
|
)
|
|
|
|
// SpaceService is the part of directory.Service that serves spaces and pages.
|
|
type SpaceService interface {
|
|
ListSpaces(ctx context.Context, c access.Caller, wsID string) ([]directory.Space, error)
|
|
CreateSpace(ctx context.Context, c access.Caller, wsID string, in directory.CreateSpaceInput) (directory.Space, error)
|
|
GetSpace(ctx context.Context, c access.Caller, id string) (directory.Space, error)
|
|
UpdateSpace(ctx context.Context, c access.Caller, id string, in directory.UpdateSpaceInput) (directory.Space, error)
|
|
DeleteSpace(ctx context.Context, c access.Caller, id string) error
|
|
ListSpaceMembers(ctx context.Context, c access.Caller, id string) ([]directory.Member, error)
|
|
SetSpaceMember(ctx context.Context, c access.Caller, id, email, role string) (directory.Member, error)
|
|
RemoveSpaceMember(ctx context.Context, c access.Caller, id, userID string) error
|
|
|
|
ListPages(ctx context.Context, c access.Caller, spaceID string) ([]directory.PageNode, error)
|
|
CreatePage(ctx context.Context, c access.Caller, spaceID string, in directory.CreatePageInput) (directory.Page, error)
|
|
GetPage(ctx context.Context, c access.Caller, id string) (directory.Page, error)
|
|
UpdatePage(ctx context.Context, c access.Caller, id string, in directory.UpdatePageInput) (directory.Page, error)
|
|
GetPageContent(ctx context.Context, c access.Caller, id string) (directory.PageContent, error)
|
|
SavePageContent(ctx context.Context, c access.Caller, id string, in directory.SavePageContentInput) (directory.PageContent, error)
|
|
CollabAccess(ctx context.Context, c access.Caller, id string) (canWrite bool, err error)
|
|
ListVersions(ctx context.Context, c access.Caller, id string) ([]collab.Version, error)
|
|
GetVersion(ctx context.Context, c access.Caller, id, versionID string) (directory.PageContent, error)
|
|
RestoreVersion(ctx context.Context, c access.Caller, id, versionID string) (directory.PageContent, error)
|
|
MovePage(ctx context.Context, c access.Caller, id string, in directory.MovePageInput) (directory.Page, error)
|
|
TrashPage(ctx context.Context, c access.Caller, id string) error
|
|
RestorePage(ctx context.Context, c access.Caller, id string) (directory.Page, error)
|
|
ListTrash(ctx context.Context, c access.Caller, spaceID string) ([]directory.TrashedPage, error)
|
|
PurgePage(ctx context.Context, c access.Caller, id string) error
|
|
ArchivePage(ctx context.Context, c access.Caller, id string) (directory.Page, error)
|
|
UnarchivePage(ctx context.Context, c access.Caller, id string) (directory.Page, error)
|
|
ListArchive(ctx context.Context, c access.Caller, spaceID string) ([]directory.ArchivedPage, error)
|
|
PinPage(ctx context.Context, c access.Caller, id string) (directory.Page, error)
|
|
UnpinPage(ctx context.Context, c access.Caller, id string) (directory.Page, error)
|
|
VerifyPage(ctx context.Context, c access.Caller, id string, days int) (directory.Page, error)
|
|
UnverifyPage(ctx context.Context, c access.Caller, id string) (directory.Page, error)
|
|
ListPinned(ctx context.Context, c access.Caller, spaceID string) ([]directory.PinnedPage, error)
|
|
}
|
|
|
|
func (a *api) spaceRoutes(mux *routeMux) {
|
|
// Spaces. Rights are resolved per space (see access.SpaceRole).
|
|
mux.HandleFunc("GET /api/v1/workspaces/{id}/spaces", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
list, err := a.dir.ListSpaces(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, list, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/workspaces/{id}/spaces", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in directory.CreateSpaceInput
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
sp, err := a.dir.CreateSpace(r.Context(), caller(r), r.PathValue("id"), in)
|
|
a.respondStatus(w, http.StatusCreated, sp, err)
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/spaces/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
sp, err := a.dir.GetSpace(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, sp, err)
|
|
}))
|
|
mux.HandleFunc("PATCH /api/v1/spaces/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in directory.UpdateSpaceInput
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
sp, err := a.dir.UpdateSpace(r.Context(), caller(r), r.PathValue("id"), in)
|
|
a.respond(w, sp, err)
|
|
}))
|
|
mux.HandleFunc("DELETE /api/v1/spaces/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
a.respondNoContent(w, a.dir.DeleteSpace(r.Context(), caller(r), r.PathValue("id")))
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/spaces/{id}/members", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
members, err := a.dir.ListSpaceMembers(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, members, err)
|
|
}))
|
|
mux.HandleFunc("PUT /api/v1/spaces/{id}/members", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in struct{ Email, Role string }
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
m, err := a.dir.SetSpaceMember(r.Context(), caller(r), r.PathValue("id"), in.Email, in.Role)
|
|
a.respond(w, m, err)
|
|
}))
|
|
mux.HandleFunc("DELETE /api/v1/spaces/{id}/members/{userId}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
a.respondNoContent(w, a.dir.RemoveSpaceMember(r.Context(), caller(r), r.PathValue("id"), r.PathValue("userId")))
|
|
}))
|
|
|
|
// Page tree and trash.
|
|
mux.HandleFunc("GET /api/v1/spaces/{id}/pages", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
pages, err := a.dir.ListPages(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, pages, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/spaces/{id}/pages", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in directory.CreatePageInput
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
p, err := a.dir.CreatePage(r.Context(), caller(r), r.PathValue("id"), in)
|
|
a.respondStatus(w, http.StatusCreated, p, err)
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/spaces/{id}/trash", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
pages, err := a.dir.ListTrash(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, pages, err)
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/spaces/{id}/archive", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
pages, err := a.dir.ListArchive(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, pages, err)
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/spaces/{id}/pinned", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
pages, err := a.dir.ListPinned(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, pages, err)
|
|
}))
|
|
mux.HandleFunc("PUT /api/v1/pages/{id}/pin", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
p, err := a.dir.PinPage(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, p, err)
|
|
}))
|
|
mux.HandleFunc("DELETE /api/v1/pages/{id}/pin", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
p, err := a.dir.UnpinPage(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, p, err)
|
|
}))
|
|
mux.HandleFunc("PUT /api/v1/pages/{id}/verify", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in struct {
|
|
Days int `json:"days"`
|
|
}
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
p, err := a.dir.VerifyPage(r.Context(), caller(r), r.PathValue("id"), in.Days)
|
|
a.respond(w, p, err)
|
|
}))
|
|
mux.HandleFunc("DELETE /api/v1/pages/{id}/verify", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
p, err := a.dir.UnverifyPage(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, p, err)
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/pages/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
p, err := a.dir.GetPage(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, p, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/pages/{id}/archive", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
p, err := a.dir.ArchivePage(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, p, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/pages/{id}/unarchive", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
p, err := a.dir.UnarchivePage(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, p, err)
|
|
}))
|
|
mux.HandleFunc("PATCH /api/v1/pages/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in directory.UpdatePageInput
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
p, err := a.dir.UpdatePage(r.Context(), caller(r), r.PathValue("id"), in)
|
|
a.respond(w, p, err)
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/pages/{id}/content", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
c, err := a.dir.GetPageContent(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, c, err)
|
|
}))
|
|
mux.HandleFunc("PUT /api/v1/pages/{id}/content", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in directory.SavePageContentInput
|
|
if !a.decodeMax(w, r, &in, 10<<20) {
|
|
return
|
|
}
|
|
c, err := a.dir.SavePageContent(r.Context(), caller(r), r.PathValue("id"), in)
|
|
a.respond(w, c, err)
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/pages/{id}/versions", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
v, err := a.dir.ListVersions(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, v, err)
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/pages/{id}/versions/{versionId}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
c, err := a.dir.GetVersion(r.Context(), caller(r), r.PathValue("id"), r.PathValue("versionId"))
|
|
a.respond(w, c, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/pages/{id}/versions/{versionId}/restore", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
c, err := a.dir.RestoreVersion(r.Context(), caller(r), r.PathValue("id"), r.PathValue("versionId"))
|
|
a.respond(w, c, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/pages/{id}/move", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in directory.MovePageInput
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
p, err := a.dir.MovePage(r.Context(), caller(r), r.PathValue("id"), in)
|
|
a.respond(w, p, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/pages/{id}/restore", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
p, err := a.dir.RestorePage(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, p, err)
|
|
}))
|
|
// DELETE moves to the trash; ?permanent=true purges a page that is already there.
|
|
mux.HandleFunc("DELETE /api/v1/pages/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Query().Get("permanent") == "true" {
|
|
a.respondNoContent(w, a.dir.PurgePage(r.Context(), caller(r), r.PathValue("id")))
|
|
return
|
|
}
|
|
a.respondNoContent(w, a.dir.TrashPage(r.Context(), caller(r), r.PathValue("id")))
|
|
}))
|
|
}
|