CI / go (Media) (push) Successful in 14m33s
CI / go (Server) (push) Failing after 23m30s
CI / go (Web-App) (push) Canceled after 0s
CI / frontend (push) Failing after 9m30s
CI / desktop (ubuntu-latest) (push) Successful in 1h21m24s
CI / mobile (push) Failing after 4m16s
CI / docker (push) Successful in 1h1m25s
Docs / build (push) Successful in 14m59s
Docs / deploy (push) Skipped
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
Phase G of docs/AFFINE.md (ADR-17): - Invite links: one per workspace (member or guest, optional end date, optional admin approval) on a new /join page. Requests are approved (optionally as another role) or declined from workspace settings; join_request, join_approved and join_declined notifications reach the inbox, phones and the email digest. Workspace admins decide, else the organization's admins, else superadmins. Signup honours ?redirect=. - Workspace switches: allowSharing (off makes every share link answer 404 until it is back on) and urlPreview (chat apps may show private pages' titles). docwell-web writes title and Open Graph tags for known link-preview bots, asking docwell-server via DOCWELL_PREVIEW_API_URL; search engines are left out. - Page analytics: page_views counts opens per page, person and day from the existing visit call and share-link reads; editors see totals, a daily chart and recent viewers in the Info panel. analytics.prune drops rows after 400 days. - Unused files: attachments whose id appears in no page's Yjs state, page icon or comment (older than a day) are listed and deleted from workspace settings. - Migration, schema snapshot, OpenAPI, generated clients, translations in five languages, phone inbox, compose files and user docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
119 lines
5.0 KiB
JavaScript
119 lines
5.0 KiB
JavaScript
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
/// <reference path="../pb_data/types.d.ts" />
|
|
|
|
// Phase G of docs/AFFINE.md: sharing extras (ADR-17).
|
|
//
|
|
// - invite_links: one join link per workspace. Anyone signed in who opens it
|
|
// joins with its role, or, with approval on, asks to join.
|
|
// - invite_requests: those asks; workspace admins approve or decline them.
|
|
// - workspaces.sharing_off turns public share links off for the whole
|
|
// workspace; workspaces.url_preview lets chat apps show the titles of
|
|
// private pages when a link to one is posted.
|
|
// - page_views: one row per page, person (empty for visitors through a share
|
|
// link) and day, counting that day's opens.
|
|
// - notifications gain the join_request, join_approved and join_declined types.
|
|
|
|
migrate(
|
|
(app) => {
|
|
const users = app.findCollectionByNameOrId("users");
|
|
const workspaces = app.findCollectionByNameOrId("workspaces");
|
|
const pages = app.findCollectionByNameOrId("pages");
|
|
|
|
workspaces.fields.add(new BoolField({ name: "sharing_off" }));
|
|
workspaces.fields.add(new BoolField({ name: "url_preview" }));
|
|
app.save(workspaces);
|
|
|
|
app.save(
|
|
new Collection({
|
|
type: "base",
|
|
name: "invite_links",
|
|
fields: [
|
|
{ name: "workspace", type: "relation", collectionId: workspaces.id, maxSelect: 1, required: true, cascadeDelete: true },
|
|
{ name: "token", type: "text", required: true, max: 64 },
|
|
{ name: "role", type: "select", values: ["member", "guest"], maxSelect: 1, required: true },
|
|
{ name: "approval", type: "bool" },
|
|
{ name: "created_by", type: "relation", collectionId: users.id, maxSelect: 1, cascadeDelete: false },
|
|
// Empty means the link does not expire.
|
|
{ name: "expires", type: "date" },
|
|
{ name: "created", type: "autodate", onCreate: true, onUpdate: false },
|
|
{ name: "updated", type: "autodate", onCreate: true, onUpdate: true },
|
|
],
|
|
indexes: [
|
|
"CREATE UNIQUE INDEX idx_invite_links_workspace ON invite_links (workspace)",
|
|
"CREATE UNIQUE INDEX idx_invite_links_token ON invite_links (token)",
|
|
],
|
|
}),
|
|
);
|
|
|
|
app.save(
|
|
new Collection({
|
|
type: "base",
|
|
name: "invite_requests",
|
|
fields: [
|
|
{ name: "workspace", type: "relation", collectionId: workspaces.id, maxSelect: 1, required: true, cascadeDelete: true },
|
|
{ name: "user", type: "relation", collectionId: users.id, maxSelect: 1, required: true, cascadeDelete: true },
|
|
{ name: "role", type: "select", values: ["member", "guest"], maxSelect: 1, required: true },
|
|
{ name: "status", type: "select", values: ["pending", "approved", "declined"], maxSelect: 1, required: true },
|
|
{ name: "reviewed_by", type: "relation", collectionId: users.id, maxSelect: 1, cascadeDelete: false },
|
|
{ name: "reviewed_at", type: "date" },
|
|
{ name: "created", type: "autodate", onCreate: true, onUpdate: false },
|
|
{ name: "updated", type: "autodate", onCreate: true, onUpdate: true },
|
|
],
|
|
indexes: [
|
|
"CREATE UNIQUE INDEX idx_invite_requests_user ON invite_requests (workspace, user)",
|
|
"CREATE INDEX idx_invite_requests_status ON invite_requests (workspace, status)",
|
|
],
|
|
}),
|
|
);
|
|
|
|
app.save(
|
|
new Collection({
|
|
type: "base",
|
|
name: "page_views",
|
|
fields: [
|
|
{ name: "page", type: "relation", collectionId: pages.id, maxSelect: 1, required: true, cascadeDelete: true },
|
|
{ name: "workspace", type: "relation", collectionId: workspaces.id, maxSelect: 1, required: true, cascadeDelete: true },
|
|
{ name: "user", type: "relation", collectionId: users.id, maxSelect: 1, cascadeDelete: true },
|
|
// The UTC day, YYYY-MM-DD.
|
|
{ name: "day", type: "text", required: true, max: 10 },
|
|
{ name: "views", type: "number", onlyInt: true, min: 0 },
|
|
{ name: "last", type: "date" },
|
|
],
|
|
indexes: [
|
|
"CREATE UNIQUE INDEX idx_page_views_key ON page_views (page, user, day)",
|
|
"CREATE INDEX idx_page_views_day ON page_views (day)",
|
|
],
|
|
}),
|
|
);
|
|
|
|
const notifications = app.findCollectionByNameOrId("notifications");
|
|
notifications.fields.getByName("type").values = [
|
|
"comment",
|
|
"reply",
|
|
"mention",
|
|
"share",
|
|
"resolved",
|
|
"reminder",
|
|
"join_request",
|
|
"join_approved",
|
|
"join_declined",
|
|
];
|
|
app.save(notifications);
|
|
},
|
|
(app) => {
|
|
for (const name of ["page_views", "invite_requests", "invite_links"]) {
|
|
try {
|
|
app.delete(app.findCollectionByNameOrId(name));
|
|
} catch (_) {}
|
|
}
|
|
const workspaces = app.findCollectionByNameOrId("workspaces");
|
|
workspaces.fields.removeByName("sharing_off");
|
|
workspaces.fields.removeByName("url_preview");
|
|
app.save(workspaces);
|
|
const notifications = app.findCollectionByNameOrId("notifications");
|
|
notifications.fields.getByName("type").values = ["comment", "reply", "mention", "share", "resolved", "reminder"];
|
|
app.save(notifications);
|
|
},
|
|
);
|