CI / go (Server) (push) Failing after 4m38s
CI / go (Web-App) (push) Successful in 12m18s
Docs / build (push) Canceled after 0s
Docs / deploy (push) Canceled after 0s
CI / frontend (push) Failing after 7m49s
CI / desktop (ubuntu-latest) (push) Successful in 1h25m30s
CI / mobile (push) Failing after 5m14s
CI / docker (push) Successful in 39m26s
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
Databases (ADR-13 follow-ups):
- Relation properties link records to another database, on the same page
or on any page the reader can open (read live and read-only, like synced
pages). Cells list the linked titles; clicking one opens the record.
- Rollup properties work out counts, sums, averages, medians, min/max,
ranges, earliest/latest dates and checked counts over related records.
Neither is stored: views compute them before drawing (linked.ts), so they
follow both databases live, and rollups sort and filter as numbers.
- Exports (Markdown, HTML, PDF, Word) resolve them for same-page databases.
- A record opens as a full page at /p/<page>/r/<database>/<record>, with
"Open as full page" on the side panel and "Back to the page".
Edgeless mode (ADR-14 follow-ups):
- History previews show a version's canvas and count canvas changes.
- Comments can be anchored to canvas elements (anchor {element}); elements
with open threads show a badge that opens the thread.
- Workspaces choose how new pages open (workspaces.default_page_mode); the
per-device choice now defaults to following the workspace.
- Phones edit the canvas once a page is opened for editing; the page note
shows the page title.
Languages:
- The admin panel speaks English, Polish, German, French and Spanish, with
a picker sharing the web app's setting and a key parity test.
- The phone app speaks the same five, follows the phone's language (and
Android's per-app language setting), and has its own parity test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
166 lines
6.7 KiB
Go
166 lines
6.7 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package httpapi
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"docwell/server/internal/access"
|
|
"docwell/server/internal/auth"
|
|
"docwell/server/internal/directory"
|
|
)
|
|
|
|
// DirectoryService is the part of directory.Service the HTTP layer uses.
|
|
type DirectoryService interface {
|
|
ListUsers(ctx context.Context, c access.Caller, in directory.ListUsersInput) (directory.UserList, error)
|
|
CreateUser(ctx context.Context, c access.Caller, in directory.CreateUserInput) (auth.User, error)
|
|
UpdateUser(ctx context.Context, c access.Caller, id string, in directory.UpdateUserInput) (auth.User, error)
|
|
DeleteUser(ctx context.Context, c access.Caller, id string) error
|
|
|
|
ListOrgs(ctx context.Context, c access.Caller) ([]directory.Org, error)
|
|
CreateOrg(ctx context.Context, c access.Caller, name string) (directory.Org, error)
|
|
RenameOrg(ctx context.Context, c access.Caller, id, name string) (directory.Org, error)
|
|
DeleteOrg(ctx context.Context, c access.Caller, id string) error
|
|
|
|
ListWorkspaces(ctx context.Context, c access.Caller) ([]directory.Workspace, error)
|
|
CreateWorkspace(ctx context.Context, c access.Caller, in directory.CreateWorkspaceInput) (directory.Workspace, error)
|
|
UpdateWorkspace(ctx context.Context, c access.Caller, id string, in directory.UpdateWorkspaceInput) (directory.Workspace, error)
|
|
DeleteWorkspace(ctx context.Context, c access.Caller, id string) error
|
|
ListMembers(ctx context.Context, c access.Caller, wsID string) ([]directory.Member, error)
|
|
SetMember(ctx context.Context, c access.Caller, wsID, email, role string) (directory.Member, error)
|
|
RemoveMember(ctx context.Context, c access.Caller, wsID, userID string) error
|
|
ListPeople(ctx context.Context, c access.Caller, wsID, query string, limit int) ([]directory.MemberUser, error)
|
|
|
|
SpaceService
|
|
InviteService
|
|
GroupService
|
|
FavoriteService
|
|
AttachmentService
|
|
SearchService
|
|
TransferService
|
|
ShareService
|
|
PermissionService
|
|
LinkService
|
|
UserManager
|
|
WebhookService
|
|
CommentService
|
|
OrganizeService
|
|
}
|
|
|
|
func caller(r *http.Request) access.Caller {
|
|
u, _ := CurrentUser(r.Context())
|
|
return u.Caller()
|
|
}
|
|
|
|
func (a *api) directoryRoutes(mux *routeMux) {
|
|
// Users (admins: own organization; superadmins: everyone).
|
|
mux.HandleFunc("GET /api/v1/users", a.requireManager(func(w http.ResponseWriter, r *http.Request) {
|
|
q := r.URL.Query()
|
|
page, _ := strconv.Atoi(q.Get("page"))
|
|
perPage, _ := strconv.Atoi(q.Get("perPage"))
|
|
list, err := a.dir.ListUsers(r.Context(), caller(r), directory.ListUsersInput{
|
|
Page: page, PerPage: min(max(perPage, 0), 200), Search: q.Get("q"), Organization: q.Get("organization"),
|
|
})
|
|
a.respond(w, list, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/users", a.requireManager(func(w http.ResponseWriter, r *http.Request) {
|
|
var in directory.CreateUserInput
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
u, err := a.dir.CreateUser(r.Context(), caller(r), in)
|
|
a.respondStatus(w, http.StatusCreated, u, err)
|
|
}))
|
|
mux.HandleFunc("PATCH /api/v1/users/{id}", a.requireManager(func(w http.ResponseWriter, r *http.Request) {
|
|
var in directory.UpdateUserInput
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
u, err := a.dir.UpdateUser(r.Context(), caller(r), r.PathValue("id"), in)
|
|
a.respond(w, u, err)
|
|
}))
|
|
mux.HandleFunc("DELETE /api/v1/users/{id}", a.requireManager(func(w http.ResponseWriter, r *http.Request) {
|
|
a.respondNoContent(w, a.dir.DeleteUser(r.Context(), caller(r), r.PathValue("id")))
|
|
}))
|
|
|
|
// Organizations. Creating one is open to any signed-in user who has none.
|
|
mux.HandleFunc("GET /api/v1/orgs", a.requireManager(func(w http.ResponseWriter, r *http.Request) {
|
|
orgs, err := a.dir.ListOrgs(r.Context(), caller(r))
|
|
a.respond(w, orgs, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/orgs", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in struct{ Name string }
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
org, err := a.dir.CreateOrg(r.Context(), caller(r), in.Name)
|
|
a.respondStatus(w, http.StatusCreated, org, err)
|
|
}))
|
|
mux.HandleFunc("PATCH /api/v1/orgs/{id}", a.requireManager(func(w http.ResponseWriter, r *http.Request) {
|
|
var in struct{ Name string }
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
org, err := a.dir.RenameOrg(r.Context(), caller(r), r.PathValue("id"), in.Name)
|
|
a.respond(w, org, err)
|
|
}))
|
|
mux.HandleFunc("DELETE /api/v1/orgs/{id}", a.requireManager(func(w http.ResponseWriter, r *http.Request) {
|
|
a.respondNoContent(w, a.dir.DeleteOrg(r.Context(), caller(r), r.PathValue("id")))
|
|
}))
|
|
|
|
// Workspaces and their members. Rights are resolved per workspace.
|
|
mux.HandleFunc("GET /api/v1/workspaces", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
list, err := a.dir.ListWorkspaces(r.Context(), caller(r))
|
|
a.respond(w, list, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/workspaces", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in directory.CreateWorkspaceInput
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
ws, err := a.dir.CreateWorkspace(r.Context(), caller(r), in)
|
|
a.respondStatus(w, http.StatusCreated, ws, err)
|
|
}))
|
|
mux.HandleFunc("PATCH /api/v1/workspaces/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in directory.UpdateWorkspaceInput
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
ws, err := a.dir.UpdateWorkspace(r.Context(), caller(r), r.PathValue("id"), in)
|
|
a.respond(w, ws, err)
|
|
}))
|
|
mux.HandleFunc("DELETE /api/v1/workspaces/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
a.respondNoContent(w, a.dir.DeleteWorkspace(r.Context(), caller(r), r.PathValue("id")))
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/workspaces/{id}/members", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
members, err := a.dir.ListMembers(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, members, err)
|
|
}))
|
|
mux.HandleFunc("PUT /api/v1/workspaces/{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.SetMember(r.Context(), caller(r), r.PathValue("id"), in.Email, in.Role)
|
|
a.respond(w, m, err)
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/workspaces/{id}/people", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
limit, _ := strconv.Atoi(r.URL.Query().Get("limit"))
|
|
people, err := a.dir.ListPeople(r.Context(), caller(r), r.PathValue("id"), r.URL.Query().Get("q"), limit)
|
|
a.respond(w, people, err)
|
|
}))
|
|
mux.HandleFunc("DELETE /api/v1/workspaces/{id}/members/{userId}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
a.respondNoContent(w, a.dir.RemoveMember(r.Context(), caller(r), r.PathValue("id"), r.PathValue("userId")))
|
|
}))
|
|
}
|
|
|
|
func (a *api) respondStatus(w http.ResponseWriter, status int, v any, err error) {
|
|
if err != nil {
|
|
a.writeError(w, err)
|
|
return
|
|
}
|
|
writeJSON(w, status, v)
|
|
}
|