mirror of
https://github.com/outline/outline.git
synced 2026-12-02 01:34:47 +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
296 lines
9.5 KiB
TypeScript
296 lines
9.5 KiB
TypeScript
import { DeprecationValidation } from "@shared/validations";
|
|
import { Collection } from "@server/models";
|
|
import {
|
|
buildCollection,
|
|
buildPersonalCollection,
|
|
buildUser,
|
|
} from "@server/test/factories";
|
|
import { getTestServer } from "@server/test/support";
|
|
import {
|
|
buildOAuthUser,
|
|
callMcpTool,
|
|
parseMcpListContent,
|
|
} from "@server/test/McpHelper";
|
|
|
|
const server = getTestServer();
|
|
|
|
describe("collection tools", () => {
|
|
it("list_collections returns user collections", async () => {
|
|
const { user, accessToken } = await buildOAuthUser();
|
|
const collection = await buildCollection({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
});
|
|
|
|
const res = await callMcpTool(server, accessToken, "list_collections");
|
|
const data = parseMcpListContent<{ id: string; url: string }>(
|
|
res?.result?.content
|
|
);
|
|
|
|
expect(data.length).toBeGreaterThanOrEqual(1);
|
|
const ids = data.map((c) => c.id);
|
|
expect(ids).toContain(collection.id);
|
|
|
|
const match = data.find((c) => c.id === collection.id);
|
|
expect(match).toBeDefined();
|
|
expect(match!.url).toMatch(/^https?:\/\//);
|
|
});
|
|
|
|
it("list_collections marks the personal collection", async () => {
|
|
const { user, accessToken } = await buildOAuthUser();
|
|
const collection = await buildCollection({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
});
|
|
const personal = await buildPersonalCollection(user);
|
|
|
|
const res = await callMcpTool(server, accessToken, "list_collections");
|
|
const data = parseMcpListContent<{ id: string; isPersonal: boolean }>(
|
|
res?.result?.content
|
|
);
|
|
|
|
expect(data.find((c) => c.id === personal.id)?.isPersonal).toBe(true);
|
|
expect(data.find((c) => c.id === collection.id)?.isPersonal).toBe(false);
|
|
});
|
|
|
|
it("list_collections filters by name ignoring case", async () => {
|
|
const { user, accessToken } = await buildOAuthUser();
|
|
const collection = await buildCollection({
|
|
name: "Product Design",
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
});
|
|
const other = await buildCollection({
|
|
name: "Something else",
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
});
|
|
|
|
const res = await callMcpTool(server, accessToken, "list_collections", {
|
|
query: "duct des",
|
|
});
|
|
const data = parseMcpListContent<{ id: string }>(res?.result?.content);
|
|
|
|
const ids = data.map((c) => c.id);
|
|
expect(ids).toContain(collection.id);
|
|
expect(ids).not.toContain(other.id);
|
|
});
|
|
|
|
it("list_collections does not return collections from another team", async () => {
|
|
const { accessToken } = await buildOAuthUser();
|
|
const otherUser = await buildUser();
|
|
const otherCollection = await buildCollection({
|
|
teamId: otherUser.teamId,
|
|
userId: otherUser.id,
|
|
});
|
|
|
|
const res = await callMcpTool(server, accessToken, "list_collections");
|
|
const data = parseMcpListContent<{ id: string }>(res?.result?.content);
|
|
|
|
const ids = data.map((c: { id: string }) => c.id);
|
|
expect(ids).not.toContain(otherCollection.id);
|
|
});
|
|
|
|
it("create_collection creates with name, description, icon, color", async () => {
|
|
const { accessToken } = await buildOAuthUser();
|
|
|
|
const res = await callMcpTool(server, accessToken, "create_collection", {
|
|
name: "Test Collection",
|
|
description: "A **test** description",
|
|
icon: "rocket",
|
|
color: "#FF0000",
|
|
});
|
|
const data = JSON.parse(res?.result?.content?.[0]?.text ?? "{}");
|
|
|
|
expect(data.success).toBe(true);
|
|
expect(data.name).toEqual("Test Collection");
|
|
expect(data.id).toBeDefined();
|
|
expect(data.url).toMatch(/^https?:\/\//);
|
|
|
|
const collection = await Collection.findByPk(data.id, {
|
|
rejectOnEmpty: true,
|
|
});
|
|
expect(collection.description).toEqual("A **test** description");
|
|
expect(collection.icon).toEqual("rocket");
|
|
expect(collection.color).toEqual("#FF0000");
|
|
expect(collection.permission).toEqual(null);
|
|
});
|
|
|
|
it("update_collection updates fields on existing collection", async () => {
|
|
const { user, accessToken } = await buildOAuthUser();
|
|
const collection = await buildCollection({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
});
|
|
|
|
const res = await callMcpTool(server, accessToken, "update_collection", {
|
|
id: collection.id,
|
|
name: "Updated Name",
|
|
description: "Updated description",
|
|
});
|
|
const data = JSON.parse(res?.result?.content?.[0]?.text ?? "{}");
|
|
|
|
expect(data.success).toBe(true);
|
|
expect(data.name).toEqual("Updated Name");
|
|
expect(data.url).toMatch(/^https?:\/\//);
|
|
|
|
await collection.reload();
|
|
expect(collection.description).toEqual("Updated description");
|
|
});
|
|
|
|
it("update_collection does not rename a personal collection", async () => {
|
|
const { user, accessToken } = await buildOAuthUser();
|
|
const collection = await buildPersonalCollection(user);
|
|
|
|
const res = await callMcpTool(server, accessToken, "update_collection", {
|
|
id: collection.id,
|
|
name: "Notes",
|
|
});
|
|
|
|
expect(res?.result?.isError).toBe(true);
|
|
await collection.reload();
|
|
expect(collection.name).toEqual("Personal");
|
|
});
|
|
|
|
it("update_collection errors when no fields are provided to update", async () => {
|
|
const { user, accessToken } = await buildOAuthUser();
|
|
const collection = await buildCollection({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
});
|
|
|
|
const res = await callMcpTool(server, accessToken, "update_collection", {
|
|
id: collection.id,
|
|
});
|
|
|
|
expect(res?.result?.isError).toBe(true);
|
|
expect(res?.result?.content?.[0]?.text).toContain(
|
|
"The update resulted in no changes to the collection"
|
|
);
|
|
});
|
|
|
|
it("update_collection errors when provided fields are identical to the current collection", async () => {
|
|
const { user, accessToken } = await buildOAuthUser();
|
|
const collection = await buildCollection({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
});
|
|
|
|
const res = await callMcpTool(server, accessToken, "update_collection", {
|
|
id: collection.id,
|
|
name: collection.name,
|
|
});
|
|
|
|
expect(res?.result?.isError).toBe(true);
|
|
expect(res?.result?.content?.[0]?.text).toContain(
|
|
"The update resulted in no changes to the collection"
|
|
);
|
|
});
|
|
});
|
|
|
|
describe.each([false, true])("delete_collection with archive=%s", (archive) => {
|
|
it.each([undefined, " Replaced by a new guide. ", null, " "])(
|
|
"saves reason %j with the status change",
|
|
async (reason) => {
|
|
const { user, accessToken } = await buildOAuthUser();
|
|
const collection = await buildCollection({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
});
|
|
await buildCollection({ teamId: user.teamId });
|
|
|
|
const res = await callMcpTool(server, accessToken, "delete_collection", {
|
|
id: collection.id,
|
|
archive,
|
|
reason,
|
|
});
|
|
|
|
expect(res?.result?.isError).toBeFalsy();
|
|
expect(JSON.parse(res?.result?.content?.[0]?.text ?? "{}").success).toBe(
|
|
true
|
|
);
|
|
await collection.reload({ paranoid: false });
|
|
expect(collection.deprecatedReason).toBe(reason?.trim() || null);
|
|
expect(
|
|
archive ? collection.archivedAt : collection.deletedAt
|
|
).not.toBeNull();
|
|
}
|
|
);
|
|
|
|
it("rejects an oversized reason without changing the item", async () => {
|
|
const { user, accessToken } = await buildOAuthUser();
|
|
const collection = await buildCollection({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
});
|
|
await buildCollection({ teamId: user.teamId });
|
|
|
|
const res = await callMcpTool(server, accessToken, "delete_collection", {
|
|
id: collection.id,
|
|
archive,
|
|
reason: "x".repeat(DeprecationValidation.maxReasonLength + 1),
|
|
});
|
|
|
|
expect(res?.result?.isError).toBe(true);
|
|
await collection.reload();
|
|
expect(collection.deprecatedReason).toBeNull();
|
|
expect(collection.archivedAt).toBeNull();
|
|
expect(collection.deletedAt).toBeNull();
|
|
});
|
|
|
|
it("checks permissions before saving the reason", async () => {
|
|
const { user } = await buildOAuthUser();
|
|
const { accessToken } = await buildOAuthUser();
|
|
const collection = await buildCollection({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
});
|
|
await buildCollection({ teamId: user.teamId });
|
|
|
|
const res = await callMcpTool(server, accessToken, "delete_collection", {
|
|
id: collection.id,
|
|
archive,
|
|
reason: "No longer needed",
|
|
});
|
|
|
|
expect(res?.result?.isError).toBe(true);
|
|
await collection.reload();
|
|
expect(collection.deprecatedReason).toBeNull();
|
|
expect(collection.archivedAt).toBeNull();
|
|
expect(collection.deletedAt).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("delete_collection", () => {
|
|
it.each([undefined, null, " "])(
|
|
"preserves or clears the archive reason when deleting with reason %j",
|
|
async (reason) => {
|
|
const { user, accessToken } = await buildOAuthUser();
|
|
const collection = await buildCollection({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
});
|
|
await buildCollection({ teamId: user.teamId });
|
|
await collection.update({
|
|
archivedAt: new Date(),
|
|
deprecatedReason: "Archived reason",
|
|
});
|
|
|
|
const res = await callMcpTool(server, accessToken, "delete_collection", {
|
|
id: collection.id,
|
|
reason,
|
|
});
|
|
|
|
expect(res?.result?.isError).toBeFalsy();
|
|
expect(JSON.parse(res?.result?.content?.[0]?.text ?? "{}").success).toBe(
|
|
true
|
|
);
|
|
await collection.reload({ paranoid: false });
|
|
expect(collection.deletedAt).not.toBeNull();
|
|
expect(collection.deprecatedReason).toBe(
|
|
reason === undefined ? "Archived reason" : null
|
|
);
|
|
}
|
|
);
|
|
});
|