mirror of
https://github.com/outline/outline.git
synced 2026-11-20 21:23:06 +03:00
* feat: Personal collections backend Adds an owner to collections. A personal collection is private, one per user per team, created lazily through collections.personal, and only its owner can see or manage it. Admin bypasses in policies, lists, exports, events, webhooks and file operations exclude the personal collections of other users. Turning off the PersonalDocs preference makes the collection read-only. * test: Access matrix for personal collections Checks that collection and document endpoints, list and search results, MCP tools, collaboration and websocket rooms agree with the read policy for the owner, collaborators, members, admins, guests and other teams. * feat: Personal collection in the sidebar Adds a Personal sidebar section that renders the personal collection with the collection document tree, creates the collection on the first new document, and keeps it out of the Collections section. Adds the workspace setting, the personal sidebar context, and hides collection sharing and membership UI for personal collections. * fix: Drag and drop in shared with me trees Anchors the reorder drop cursor inside the row, and prefetches documents on hover so that nested rows that were never opened can be dragged. * feat: Personal collection owner for collaborators, no collection page Presents the owner of the personal collection on documents, so that collaborators see the owner in the share popover. Root rows in the Personal section show the default document icon. A personal collection has no page: the scene shows not found, and the breadcrumb, command bar and delete redirect no longer link to it. * fix: Personal sidebar indent and breadcrumb items without a link Children of rows at depth 0 skip a level so that they start beyond the row icon. Breadcrumb items without a destination, such as the personal and deleted collection, are shown as plain text. * test: Reduce personal collection tests to list paths Endpoints that authorize a single model are already covered by the policy tests. Keeps the lists and searches, which filter in queries, and the presenter. * test: Move personal collection list tests into collections tests * feat: Create documents in the personal collection by alias documents.create, documents.import and the MCP create_document tool accept the collectionId "personal", which refers to the personal collection of the user and creates it when it does not exist yet. * refactor: Remove collections.personal route The sidebar creates its first personal document with the personal collectionId alias, so documents.create is the only path that creates the personal collection. * feat: Personal collection name, starring, templates and default Personal collections cannot be starred, renamed or hold templates, and the PersonalDocs preference is on by default. The app shows collections through a displayName getter, which is the translated "Personal" for a personal collection. * fix: Use the same policy for starring and unstarring collections * fix: No pins or viewer insights for personal documents * revert: Show personal collection events in the audit log Admins with audit access should see events in personal collections, even when they cannot open the documents. * fix: Load collection owner in share scopes * fix: Keep personal collections out of workspace exports and webhooks Workspace exports skip all personal collections, while an explicit export of a personal collection stays available to its owner. Events in personal collections, including attachments and documents moved after queueing, are never delivered to workspace webhooks. Personal collections cannot be renamed or made public through any path, cannot hold pins, and are not offered as mentions. * Change icon to avatar * fix: Personal documents cannot be unpublished * feat: Personal collection context for MCP Collections are presented with an isPersonal flag, the server instructions explain the personal collection, and move_document and update_document accept the personal collectionId alias. * fix: Keep moved personal exports private and remove pins on move Document exports record the owner of the personal collection they came from, so they stay private after the document moves. Moving documents into a personal collection removes their pins, including pins to home. * fix: Only create the personal collection in MCP when it is used
212 lines
5.9 KiB
TypeScript
212 lines
5.9 KiB
TypeScript
import {
|
|
buildAdmin,
|
|
buildAttachment,
|
|
buildDocument,
|
|
buildPersonalCollection,
|
|
buildUser,
|
|
buildWebhookSubscription,
|
|
} from "@server/test/factories";
|
|
import { mockTaskSchedule } from "@server/test/support";
|
|
import type { AttachmentEvent, DocumentEvent, UserEvent } from "@server/types";
|
|
import WebhookProcessor from "./WebhookProcessor";
|
|
|
|
const ip = "127.0.0.1";
|
|
const schedule = mockTaskSchedule();
|
|
|
|
describe("WebhookProcessor", () => {
|
|
it("it schedules a delivery for the event", async () => {
|
|
const subscription = await buildWebhookSubscription({
|
|
url: "http://example.com",
|
|
events: ["*"],
|
|
});
|
|
const signedInUser = await buildUser({ teamId: subscription.teamId });
|
|
const processor = new WebhookProcessor();
|
|
|
|
const event: UserEvent = {
|
|
name: "users.signin",
|
|
userId: signedInUser.id,
|
|
teamId: subscription.teamId,
|
|
actorId: signedInUser.id,
|
|
ip,
|
|
};
|
|
|
|
await processor.perform(event);
|
|
|
|
expect(schedule).toHaveBeenCalled();
|
|
expect(schedule).toHaveBeenCalledWith({
|
|
event,
|
|
subscriptionId: subscription.id,
|
|
});
|
|
});
|
|
|
|
it("not schedule a delivery when not subscribed to event", async () => {
|
|
const subscription = await buildWebhookSubscription({
|
|
url: "http://example.com",
|
|
events: ["users.create"],
|
|
});
|
|
const signedInUser = await buildUser({ teamId: subscription.teamId });
|
|
const processor = new WebhookProcessor();
|
|
const event: UserEvent = {
|
|
name: "users.signin",
|
|
userId: signedInUser.id,
|
|
teamId: subscription.teamId,
|
|
actorId: signedInUser.id,
|
|
ip,
|
|
};
|
|
|
|
await processor.perform(event);
|
|
|
|
expect(schedule).toHaveBeenCalledTimes(0);
|
|
});
|
|
|
|
it("it schedules a delivery for the event for each subscription", async () => {
|
|
const subscription = await buildWebhookSubscription({
|
|
url: "http://example.com",
|
|
events: ["*"],
|
|
});
|
|
const subscriptionTwo = await buildWebhookSubscription({
|
|
url: "http://example.com",
|
|
teamId: subscription.teamId,
|
|
events: ["*"],
|
|
});
|
|
const signedInUser = await buildUser({ teamId: subscription.teamId });
|
|
const processor = new WebhookProcessor();
|
|
|
|
const event: UserEvent = {
|
|
name: "users.signin",
|
|
userId: signedInUser.id,
|
|
teamId: subscription.teamId,
|
|
actorId: signedInUser.id,
|
|
ip,
|
|
};
|
|
|
|
await processor.perform(event);
|
|
|
|
expect(schedule).toHaveBeenCalled();
|
|
expect(schedule).toHaveBeenCalledTimes(2);
|
|
expect(schedule).toHaveBeenCalledWith({
|
|
event,
|
|
subscriptionId: subscription.id,
|
|
});
|
|
expect(schedule).toHaveBeenCalledWith({
|
|
event,
|
|
subscriptionId: subscriptionTwo.id,
|
|
});
|
|
});
|
|
|
|
describe("shouldQueue", () => {
|
|
it("returns true when a matching subscription exists", async () => {
|
|
const subscription = await buildWebhookSubscription({
|
|
url: "http://example.com",
|
|
events: ["users"],
|
|
});
|
|
const event: UserEvent = {
|
|
name: "users.signin",
|
|
userId: subscription.createdById,
|
|
teamId: subscription.teamId,
|
|
actorId: subscription.createdById,
|
|
ip,
|
|
};
|
|
|
|
expect(await WebhookProcessor.shouldQueue(event)).toBe(true);
|
|
});
|
|
|
|
it("returns false when no subscription matches the event", async () => {
|
|
const subscription = await buildWebhookSubscription({
|
|
url: "http://example.com",
|
|
events: ["documents.create"],
|
|
});
|
|
const event: UserEvent = {
|
|
name: "users.signin",
|
|
userId: subscription.createdById,
|
|
teamId: subscription.teamId,
|
|
actorId: subscription.createdById,
|
|
ip,
|
|
};
|
|
|
|
expect(await WebhookProcessor.shouldQueue(event)).toBe(false);
|
|
});
|
|
|
|
it("returns false when the team has no subscriptions", async () => {
|
|
const user = await buildUser();
|
|
const event: UserEvent = {
|
|
name: "users.signin",
|
|
userId: user.id,
|
|
teamId: user.teamId,
|
|
actorId: user.id,
|
|
ip,
|
|
};
|
|
|
|
expect(await WebhookProcessor.shouldQueue(event)).toBe(false);
|
|
});
|
|
});
|
|
|
|
it("does not schedule events in a personal collection", async () => {
|
|
const owner = await buildUser();
|
|
const admin = await buildAdmin({ teamId: owner.teamId });
|
|
const personal = await buildPersonalCollection(owner);
|
|
const document = await buildDocument({
|
|
teamId: owner.teamId,
|
|
userId: owner.id,
|
|
collectionId: personal.id,
|
|
});
|
|
for (const createdById of [admin.id, owner.id]) {
|
|
await buildWebhookSubscription({
|
|
teamId: owner.teamId,
|
|
createdById,
|
|
url: "http://example.com",
|
|
events: ["*"],
|
|
});
|
|
}
|
|
const processor = new WebhookProcessor();
|
|
|
|
const event: DocumentEvent = {
|
|
name: "documents.update",
|
|
documentId: document.id,
|
|
collectionId: personal.id,
|
|
teamId: owner.teamId,
|
|
actorId: owner.id,
|
|
ip,
|
|
createdAt: new Date().toISOString(),
|
|
data: { done: true },
|
|
};
|
|
schedule.mockClear();
|
|
await processor.perform(event);
|
|
|
|
expect(schedule).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("does not schedule attachment events in a personal collection", async () => {
|
|
const owner = await buildUser();
|
|
const personal = await buildPersonalCollection(owner);
|
|
const document = await buildDocument({
|
|
teamId: owner.teamId,
|
|
userId: owner.id,
|
|
collectionId: personal.id,
|
|
});
|
|
const attachment = await buildAttachment({
|
|
teamId: owner.teamId,
|
|
userId: owner.id,
|
|
documentId: document.id,
|
|
});
|
|
await buildWebhookSubscription({
|
|
teamId: owner.teamId,
|
|
url: "http://example.com",
|
|
events: ["*"],
|
|
});
|
|
|
|
const event: AttachmentEvent = {
|
|
name: "attachments.create",
|
|
modelId: attachment.id,
|
|
teamId: owner.teamId,
|
|
actorId: owner.id,
|
|
ip,
|
|
data: { name: attachment.name },
|
|
};
|
|
schedule.mockClear();
|
|
await new WebhookProcessor().perform(event);
|
|
|
|
expect(schedule).not.toHaveBeenCalled();
|
|
});
|
|
});
|