mirror of
https://github.com/outline/outline.git
synced 2026-11-22 14:01:41 +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
708 lines
21 KiB
TypeScript
708 lines
21 KiB
TypeScript
// @vitest-isolate true
|
|
import {
|
|
CollectionPermission,
|
|
FileOperationFormat,
|
|
FileOperationState,
|
|
FileOperationType,
|
|
} from "@shared/types";
|
|
import { createContext } from "@server/context";
|
|
import {
|
|
Collection,
|
|
User,
|
|
Event,
|
|
FileOperation,
|
|
UserMembership,
|
|
} from "@server/models";
|
|
import {
|
|
buildAdmin,
|
|
buildCollection,
|
|
buildDocument,
|
|
buildFileOperation,
|
|
buildPersonalCollection,
|
|
buildTeam,
|
|
buildUser,
|
|
} from "@server/test/factories";
|
|
|
|
import { getTestServer } from "@server/test/support";
|
|
|
|
const server = getTestServer();
|
|
|
|
vi.mock("@server/storage/files");
|
|
|
|
describe("#fileOperations.info", () => {
|
|
it("should return fileOperation", async () => {
|
|
const team = await buildTeam();
|
|
const admin = await buildAdmin({
|
|
teamId: team.id,
|
|
});
|
|
const exportData = await buildFileOperation({
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: admin.id,
|
|
});
|
|
const res = await server.post("/api/fileOperations.info", admin, {
|
|
body: {
|
|
id: exportData.id,
|
|
},
|
|
});
|
|
const body = await res.json();
|
|
expect(res.status).toEqual(200);
|
|
expect(body.data.id).toBe(exportData.id);
|
|
expect(body.data.state).toBe(exportData.state);
|
|
});
|
|
|
|
it("should allow user to read their own export", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const collection = await buildCollection({ teamId: team.id });
|
|
const exportData = await buildFileOperation({
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: user.id,
|
|
collectionId: collection.id,
|
|
});
|
|
const res = await server.post("/api/fileOperations.info", user, {
|
|
body: {
|
|
id: exportData.id,
|
|
},
|
|
});
|
|
const body = await res.json();
|
|
expect(res.status).toEqual(200);
|
|
expect(body.data.id).toBe(exportData.id);
|
|
});
|
|
|
|
it("should not allow user to read their own export of a collection they lost access to", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: null,
|
|
});
|
|
const exportData = await buildFileOperation({
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: user.id,
|
|
collectionId: collection.id,
|
|
});
|
|
const res = await server.post("/api/fileOperations.info", user, {
|
|
body: {
|
|
id: exportData.id,
|
|
},
|
|
});
|
|
expect(res.status).toEqual(403);
|
|
});
|
|
|
|
it("should not allow demoted admin to read their own workspace export", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const exportData = await buildFileOperation({
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: user.id,
|
|
});
|
|
const res = await server.post("/api/fileOperations.info", user, {
|
|
body: {
|
|
id: exportData.id,
|
|
},
|
|
});
|
|
expect(res.status).toEqual(403);
|
|
});
|
|
|
|
it("should not allow user to read another user's export", async () => {
|
|
const team = await buildTeam();
|
|
const admin = await buildAdmin({ teamId: team.id });
|
|
const user = await buildUser({ teamId: team.id });
|
|
const exportData = await buildFileOperation({
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: admin.id,
|
|
});
|
|
const res = await server.post("/api/fileOperations.info", user, {
|
|
body: {
|
|
id: exportData.id,
|
|
},
|
|
});
|
|
expect(res.status).toEqual(403);
|
|
});
|
|
|
|
it("should allow admin to read another admin's export", async () => {
|
|
const team = await buildTeam();
|
|
const admin1 = await buildAdmin({ teamId: team.id });
|
|
const admin2 = await buildAdmin({ teamId: team.id });
|
|
const exportData = await buildFileOperation({
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: admin1.id,
|
|
});
|
|
const res = await server.post("/api/fileOperations.info", admin2, {
|
|
body: {
|
|
id: exportData.id,
|
|
},
|
|
});
|
|
const body = await res.json();
|
|
expect(res.status).toEqual(200);
|
|
expect(body.data.id).toBe(exportData.id);
|
|
});
|
|
|
|
it("should allow admin to read an import file operation", async () => {
|
|
const team = await buildTeam();
|
|
const admin1 = await buildAdmin({ teamId: team.id });
|
|
const admin2 = await buildAdmin({ teamId: team.id });
|
|
const importOp = await buildFileOperation({
|
|
type: FileOperationType.Import,
|
|
teamId: team.id,
|
|
userId: admin1.id,
|
|
});
|
|
const res = await server.post("/api/fileOperations.info", admin2, {
|
|
body: {
|
|
id: importOp.id,
|
|
},
|
|
});
|
|
const body = await res.json();
|
|
expect(res.status).toEqual(200);
|
|
expect(body.data.id).toBe(importOp.id);
|
|
});
|
|
|
|
it("should require authorization", async () => {
|
|
const team = await buildTeam();
|
|
const admin = await buildAdmin();
|
|
await buildUser({
|
|
teamId: team.id,
|
|
});
|
|
const exportData = await buildFileOperation({
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: admin.id,
|
|
});
|
|
const res = await server.post("/api/fileOperations.info", admin, {
|
|
body: {
|
|
id: exportData.id,
|
|
},
|
|
});
|
|
expect(res.status).toEqual(403);
|
|
});
|
|
});
|
|
|
|
describe("#fileOperations.list", () => {
|
|
it("should return fileOperations list", async () => {
|
|
const team = await buildTeam();
|
|
const admin = await buildAdmin({
|
|
teamId: team.id,
|
|
});
|
|
const exportData = await buildFileOperation({
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: admin.id,
|
|
});
|
|
const res = await server.post("/api/fileOperations.list", admin, {
|
|
body: {
|
|
type: FileOperationType.Export,
|
|
},
|
|
});
|
|
const body = await res.json();
|
|
const data = body.data[0];
|
|
expect(res.status).toEqual(200);
|
|
expect(body.data.length).toBe(1);
|
|
expect(data.id).toBe(exportData.id);
|
|
expect(data.key).toBe(undefined);
|
|
expect(data.state).toBe(exportData.state);
|
|
});
|
|
|
|
it("should return exports with collection data", async () => {
|
|
const team = await buildTeam();
|
|
const admin = await buildAdmin({
|
|
teamId: team.id,
|
|
});
|
|
const collection = await buildCollection({
|
|
userId: admin.id,
|
|
teamId: team.id,
|
|
});
|
|
const exportData = await buildFileOperation({
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: admin.id,
|
|
collectionId: collection.id,
|
|
});
|
|
const res = await server.post("/api/fileOperations.list", admin, {
|
|
body: {
|
|
type: FileOperationType.Export,
|
|
},
|
|
});
|
|
const body = await res.json();
|
|
const data = body.data[0];
|
|
expect(res.status).toEqual(200);
|
|
expect(body.data.length).toBe(1);
|
|
expect(data.id).toBe(exportData.id);
|
|
expect(data.key).toBe(undefined);
|
|
expect(data.state).toBe(exportData.state);
|
|
expect(data.collectionId).toBe(collection.id);
|
|
});
|
|
|
|
it("should return exports with collection data even if collection is deleted", async () => {
|
|
const team = await buildTeam();
|
|
const admin = await buildAdmin({
|
|
teamId: team.id,
|
|
});
|
|
const collection = await buildCollection({
|
|
userId: admin.id,
|
|
teamId: team.id,
|
|
});
|
|
const exportData = await buildFileOperation({
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: admin.id,
|
|
collectionId: collection.id,
|
|
});
|
|
await collection.destroy({ hooks: false });
|
|
const isCollectionPresent = await Collection.findByPk(collection.id);
|
|
expect(isCollectionPresent).toBe(null);
|
|
const res = await server.post("/api/fileOperations.list", admin, {
|
|
body: {
|
|
type: FileOperationType.Export,
|
|
},
|
|
});
|
|
const body = await res.json();
|
|
const data = body.data[0];
|
|
expect(res.status).toEqual(200);
|
|
expect(body.data.length).toBe(1);
|
|
expect(data.id).toBe(exportData.id);
|
|
expect(data.key).toBe(undefined);
|
|
expect(data.state).toBe(exportData.state);
|
|
expect(data.collectionId).toBe(collection.id);
|
|
});
|
|
|
|
it("should return exports with user data even if user is deleted", async () => {
|
|
const team = await buildTeam();
|
|
const admin2 = await buildAdmin({
|
|
teamId: team.id,
|
|
});
|
|
const admin = await buildAdmin({
|
|
teamId: team.id,
|
|
});
|
|
const collection = await buildCollection({
|
|
userId: admin.id,
|
|
teamId: team.id,
|
|
});
|
|
const exportData = await buildFileOperation({
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: admin.id,
|
|
collectionId: collection.id,
|
|
});
|
|
await admin.destroy();
|
|
const isAdminPresent = await User.findByPk(admin.id);
|
|
expect(isAdminPresent).toBe(null);
|
|
const res = await server.post("/api/fileOperations.list", admin2, {
|
|
body: {
|
|
type: FileOperationType.Export,
|
|
},
|
|
});
|
|
const body = await res.json();
|
|
const data = body.data[0];
|
|
expect(res.status).toEqual(200);
|
|
expect(body.data.length).toBe(1);
|
|
expect(data.id).toBe(exportData.id);
|
|
expect(data.key).toBe(undefined);
|
|
expect(data.state).toBe(exportData.state);
|
|
expect(data.user.id).toBe(admin.id);
|
|
});
|
|
|
|
it("should require admin", async () => {
|
|
const user = await buildUser();
|
|
const res = await server.post("/api/fileOperations.list", user, {
|
|
body: {
|
|
type: FileOperationType.Export,
|
|
},
|
|
});
|
|
expect(res.status).toEqual(403);
|
|
});
|
|
});
|
|
|
|
describe("#fileOperations.redirect", () => {
|
|
it("should not redirect when file operation is not complete", async () => {
|
|
const team = await buildTeam();
|
|
const admin = await buildAdmin({
|
|
teamId: team.id,
|
|
});
|
|
const exportData = await buildFileOperation({
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: admin.id,
|
|
});
|
|
const res = await server.post("/api/fileOperations.redirect", admin, {
|
|
body: {
|
|
id: exportData.id,
|
|
},
|
|
});
|
|
const body = await res.json();
|
|
expect(res.status).toEqual(400);
|
|
expect(body.message).toEqual("export is not complete yet");
|
|
});
|
|
|
|
it("should allow admin to redirect another admin's export", async () => {
|
|
const team = await buildTeam();
|
|
const admin1 = await buildAdmin({ teamId: team.id });
|
|
const admin2 = await buildAdmin({ teamId: team.id });
|
|
const exportData = await buildFileOperation({
|
|
state: FileOperationState.Complete,
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: admin1.id,
|
|
});
|
|
const res = await server.post("/api/fileOperations.redirect", admin2, {
|
|
body: {
|
|
id: exportData.id,
|
|
},
|
|
redirect: "manual",
|
|
});
|
|
expect(res.status).toEqual(302);
|
|
});
|
|
|
|
it("should allow user to redirect their own export", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const collection = await buildCollection({ teamId: team.id });
|
|
const exportData = await buildFileOperation({
|
|
state: FileOperationState.Complete,
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: user.id,
|
|
collectionId: collection.id,
|
|
});
|
|
const res = await server.post("/api/fileOperations.redirect", user, {
|
|
body: {
|
|
id: exportData.id,
|
|
},
|
|
redirect: "manual",
|
|
});
|
|
expect(res.status).toEqual(302);
|
|
});
|
|
|
|
it("should not allow user to redirect their own export of a collection they lost access to", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: null,
|
|
});
|
|
const exportData = await buildFileOperation({
|
|
state: FileOperationState.Complete,
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: user.id,
|
|
collectionId: collection.id,
|
|
});
|
|
const res = await server.post("/api/fileOperations.redirect", user, {
|
|
body: {
|
|
id: exportData.id,
|
|
},
|
|
redirect: "manual",
|
|
});
|
|
expect(res.status).toEqual(403);
|
|
});
|
|
|
|
it("should allow user to redirect their own export of a private collection they are a member of", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: null,
|
|
});
|
|
await UserMembership.create({
|
|
createdById: user.id,
|
|
collectionId: collection.id,
|
|
userId: user.id,
|
|
permission: CollectionPermission.Admin,
|
|
});
|
|
const exportData = await buildFileOperation({
|
|
state: FileOperationState.Complete,
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: user.id,
|
|
collectionId: collection.id,
|
|
});
|
|
const res = await server.post("/api/fileOperations.redirect", user, {
|
|
body: {
|
|
id: exportData.id,
|
|
},
|
|
redirect: "manual",
|
|
});
|
|
expect(res.status).toEqual(302);
|
|
});
|
|
|
|
it("should allow user to redirect their own document export", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const collection = await buildCollection({ teamId: team.id });
|
|
const document = await buildDocument({
|
|
teamId: team.id,
|
|
userId: user.id,
|
|
collectionId: collection.id,
|
|
});
|
|
const exportData = await buildFileOperation({
|
|
state: FileOperationState.Complete,
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: user.id,
|
|
documentId: document.id,
|
|
});
|
|
const res = await server.post("/api/fileOperations.redirect", user, {
|
|
body: {
|
|
id: exportData.id,
|
|
},
|
|
redirect: "manual",
|
|
});
|
|
expect(res.status).toEqual(302);
|
|
});
|
|
|
|
it("should not allow user to redirect their own document export after losing access", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: null,
|
|
});
|
|
const document = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
const exportData = await buildFileOperation({
|
|
state: FileOperationState.Complete,
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: user.id,
|
|
documentId: document.id,
|
|
});
|
|
const res = await server.post("/api/fileOperations.redirect", user, {
|
|
body: {
|
|
id: exportData.id,
|
|
},
|
|
redirect: "manual",
|
|
});
|
|
expect(res.status).toEqual(403);
|
|
});
|
|
|
|
it("should not allow user to redirect another user's export", async () => {
|
|
const team = await buildTeam();
|
|
const admin = await buildAdmin({ teamId: team.id });
|
|
const user = await buildUser({ teamId: team.id });
|
|
const exportData = await buildFileOperation({
|
|
state: FileOperationState.Complete,
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: admin.id,
|
|
});
|
|
const res = await server.post("/api/fileOperations.redirect", user, {
|
|
body: {
|
|
id: exportData.id,
|
|
},
|
|
});
|
|
expect(res.status).toEqual(403);
|
|
});
|
|
|
|
it("should require authorization", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const admin = await buildAdmin();
|
|
const exportData = await buildFileOperation({
|
|
state: FileOperationState.Complete,
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: user.id,
|
|
});
|
|
const res = await server.post("/api/fileOperations.redirect", admin, {
|
|
body: {
|
|
id: exportData.id,
|
|
},
|
|
});
|
|
expect(res.status).toEqual(403);
|
|
});
|
|
});
|
|
|
|
describe("#fileOperations.delete", () => {
|
|
it.each([
|
|
FileOperationState.Complete,
|
|
FileOperationState.Error,
|
|
FileOperationState.Expired,
|
|
])("should delete %s export file operation", async (state) => {
|
|
const team = await buildTeam();
|
|
const admin = await buildAdmin({
|
|
teamId: team.id,
|
|
});
|
|
const exportData = await buildFileOperation({
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: admin.id,
|
|
state,
|
|
});
|
|
const deleteResponse = await server.post(
|
|
"/api/fileOperations.delete",
|
|
admin,
|
|
{
|
|
body: {
|
|
id: exportData.id,
|
|
},
|
|
}
|
|
);
|
|
expect(deleteResponse.status).toBe(200);
|
|
expect(
|
|
await Event.count({
|
|
where: {
|
|
name: "fileOperations.delete",
|
|
teamId: team.id,
|
|
},
|
|
})
|
|
).toBe(1);
|
|
expect(
|
|
await FileOperation.count({
|
|
where: {
|
|
teamId: team.id,
|
|
},
|
|
})
|
|
).toBe(0);
|
|
});
|
|
|
|
it("should not delete an export file operation in a non-terminal state", async () => {
|
|
const team = await buildTeam();
|
|
const admin = await buildAdmin({ teamId: team.id });
|
|
const exportData = await buildFileOperation({
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: admin.id,
|
|
state: FileOperationState.Creating,
|
|
});
|
|
const res = await server.post("/api/fileOperations.delete", admin, {
|
|
body: {
|
|
id: exportData.id,
|
|
},
|
|
});
|
|
expect(res.status).toEqual(403);
|
|
});
|
|
|
|
it("should require authorization", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const admin = await buildAdmin();
|
|
const exportData = await buildFileOperation({
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: user.id,
|
|
});
|
|
const res = await server.post("/api/fileOperations.delete", admin, {
|
|
body: {
|
|
id: exportData.id,
|
|
},
|
|
});
|
|
expect(res.status).toEqual(403);
|
|
});
|
|
});
|
|
|
|
describe("personal collection exports", () => {
|
|
it("should not show or allow admins to download them", async () => {
|
|
const team = await buildTeam();
|
|
const admin = await buildAdmin({ teamId: team.id });
|
|
const owner = await buildUser({ teamId: team.id });
|
|
const personal = await buildPersonalCollection(owner);
|
|
const document = await buildDocument({
|
|
teamId: team.id,
|
|
userId: owner.id,
|
|
collectionId: personal.id,
|
|
});
|
|
const collectionExport = await buildFileOperation({
|
|
state: FileOperationState.Complete,
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: owner.id,
|
|
collectionId: personal.id,
|
|
});
|
|
const documentExport = await buildFileOperation({
|
|
state: FileOperationState.Complete,
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: owner.id,
|
|
documentId: document.id,
|
|
});
|
|
const workspaceExport = await buildFileOperation({
|
|
state: FileOperationState.Complete,
|
|
type: FileOperationType.Export,
|
|
teamId: team.id,
|
|
userId: admin.id,
|
|
});
|
|
|
|
const res = await server.post("/api/fileOperations.list", admin, {
|
|
body: { type: FileOperationType.Export },
|
|
});
|
|
const body = await res.json();
|
|
expect(res.status).toEqual(200);
|
|
expect(body.data.map((f: { id: string }) => f.id)).toEqual([
|
|
workspaceExport.id,
|
|
]);
|
|
|
|
for (const fileOperation of [collectionExport, documentExport]) {
|
|
const info = await server.post("/api/fileOperations.info", admin, {
|
|
body: { id: fileOperation.id },
|
|
});
|
|
expect(info.status).toEqual(403);
|
|
|
|
const redirect = await server.post(
|
|
"/api/fileOperations.redirect",
|
|
admin,
|
|
{
|
|
body: { id: fileOperation.id },
|
|
redirect: "manual",
|
|
}
|
|
);
|
|
expect(redirect.status).toEqual(403);
|
|
|
|
const own = await server.post("/api/fileOperations.redirect", owner, {
|
|
body: { id: fileOperation.id },
|
|
redirect: "manual",
|
|
});
|
|
expect(own.status).toEqual(302);
|
|
}
|
|
});
|
|
|
|
it("should keep a document export private after the document moves", async () => {
|
|
const team = await buildTeam();
|
|
const admin = await buildAdmin({ teamId: team.id });
|
|
const owner = await buildUser({ teamId: team.id });
|
|
const personal = await buildPersonalCollection(owner);
|
|
const shared = await buildCollection({ teamId: team.id, userId: owner.id });
|
|
const document = await buildDocument({
|
|
teamId: team.id,
|
|
userId: owner.id,
|
|
collectionId: personal.id,
|
|
});
|
|
const fileOperation = await FileOperation.createExport(
|
|
createContext({ user: owner }),
|
|
{ document, format: FileOperationFormat.MarkdownZip }
|
|
);
|
|
fileOperation.state = FileOperationState.Complete;
|
|
await fileOperation.save();
|
|
expect(fileOperation.options?.personalOwnerId).toEqual(owner.id);
|
|
|
|
document.collectionId = shared.id;
|
|
await document.save();
|
|
|
|
const list = await server.post("/api/fileOperations.list", admin, {
|
|
body: { type: FileOperationType.Export },
|
|
});
|
|
const body = await list.json();
|
|
expect(body.data.map((f: { id: string }) => f.id)).not.toContain(
|
|
fileOperation.id
|
|
);
|
|
|
|
const redirect = await server.post("/api/fileOperations.redirect", admin, {
|
|
body: { id: fileOperation.id },
|
|
redirect: "manual",
|
|
});
|
|
expect(redirect.status).toEqual(403);
|
|
|
|
const own = await server.post("/api/fileOperations.redirect", owner, {
|
|
body: { id: fileOperation.id },
|
|
redirect: "manual",
|
|
});
|
|
expect(own.status).toEqual(302);
|
|
});
|
|
});
|