mirror of
https://github.com/outline/outline.git
synced 2026-11-27 07:58:51 +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
898 lines
31 KiB
TypeScript
898 lines
31 KiB
TypeScript
import {
|
|
CollectionPermission,
|
|
CommentingAccess,
|
|
DocumentPermission,
|
|
TeamPreference,
|
|
UserRole,
|
|
} from "@shared/types";
|
|
import { Document, UserMembership } from "@server/models";
|
|
import {
|
|
buildUser,
|
|
buildTeam,
|
|
buildDocument,
|
|
buildDraftDocument,
|
|
buildCollection,
|
|
buildAdmin,
|
|
buildPersonalCollection,
|
|
} from "@server/test/factories";
|
|
import { serialize } from "./index";
|
|
|
|
describe("read_write collection", () => {
|
|
it("should allow read write permissions for member", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: CollectionPermission.ReadWrite,
|
|
});
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
// reload to get membership
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toBeTruthy();
|
|
expect(abilities.download).toBeTruthy();
|
|
expect(abilities.update).toBeTruthy();
|
|
expect(abilities.createChildDocument).toBeTruthy();
|
|
expect(abilities.manageUsers).toEqual(false);
|
|
expect(abilities.archive).toBeTruthy();
|
|
expect(abilities.delete).toBeTruthy();
|
|
expect(abilities.share).toBeTruthy();
|
|
expect(abilities.move).toBeTruthy();
|
|
expect(abilities.comment).toBeTruthy();
|
|
});
|
|
|
|
it("should allow user management for collection admins", async () => {
|
|
const team = await buildTeam();
|
|
const admin = await buildAdmin({ teamId: team.id });
|
|
const user = await buildUser({ teamId: team.id });
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: null,
|
|
});
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
await collection.$add("user", user, {
|
|
through: {
|
|
permission: CollectionPermission.Admin,
|
|
createdById: admin.id,
|
|
},
|
|
});
|
|
|
|
// reload to get membership
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toBeTruthy();
|
|
expect(abilities.update).toBeTruthy();
|
|
expect(abilities.manageUsers).toBeTruthy();
|
|
});
|
|
|
|
it("should allow user management for workspace admins with read access", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildAdmin({ teamId: team.id });
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: CollectionPermission.Read,
|
|
});
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
|
|
// reload to get membership
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toBeTruthy();
|
|
expect(abilities.update).toEqual(false);
|
|
expect(abilities.manageUsers).toBeTruthy();
|
|
});
|
|
|
|
it("should allow read permissions for viewer", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({
|
|
teamId: team.id,
|
|
role: UserRole.Viewer,
|
|
});
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: CollectionPermission.ReadWrite,
|
|
});
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
// reload to get membership
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toBeTruthy();
|
|
expect(abilities.download).toBeTruthy();
|
|
expect(abilities.update).toEqual(false);
|
|
expect(abilities.createChildDocument).toEqual(false);
|
|
expect(abilities.manageUsers).toEqual(false);
|
|
expect(abilities.archive).toEqual(false);
|
|
expect(abilities.delete).toEqual(false);
|
|
expect(abilities.share).toEqual(false);
|
|
expect(abilities.move).toEqual(false);
|
|
expect(abilities.subscribe).toBeTruthy();
|
|
expect(abilities.unsubscribe).toBeTruthy();
|
|
expect(abilities.comment).toBeTruthy();
|
|
});
|
|
|
|
it("should allow no permissions for guest", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({
|
|
teamId: team.id,
|
|
role: UserRole.Guest,
|
|
});
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: CollectionPermission.ReadWrite,
|
|
});
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
// reload to get membership
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toEqual(false);
|
|
expect(abilities.download).toEqual(false);
|
|
expect(abilities.update).toEqual(false);
|
|
expect(abilities.createChildDocument).toEqual(false);
|
|
expect(abilities.manageUsers).toEqual(false);
|
|
expect(abilities.archive).toEqual(false);
|
|
expect(abilities.delete).toEqual(false);
|
|
expect(abilities.share).toEqual(false);
|
|
expect(abilities.move).toEqual(false);
|
|
expect(abilities.subscribe).toEqual(false);
|
|
expect(abilities.unsubscribe).toEqual(false);
|
|
expect(abilities.comment).toEqual(false);
|
|
});
|
|
});
|
|
|
|
describe("read collection", () => {
|
|
it("should allow read permissions for team member", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: CollectionPermission.Read,
|
|
});
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
// reload to get membership
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toBeTruthy();
|
|
expect(abilities.download).toBeTruthy();
|
|
expect(abilities.update).toEqual(false);
|
|
expect(abilities.createChildDocument).toEqual(false);
|
|
expect(abilities.archive).toEqual(false);
|
|
expect(abilities.delete).toEqual(false);
|
|
expect(abilities.share).toEqual(false);
|
|
expect(abilities.move).toEqual(false);
|
|
expect(abilities.subscribe).toBeTruthy();
|
|
expect(abilities.unsubscribe).toBeTruthy();
|
|
expect(abilities.comment).toBeTruthy();
|
|
});
|
|
|
|
it("should allow no permissions for guest", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({
|
|
teamId: team.id,
|
|
role: UserRole.Guest,
|
|
});
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: CollectionPermission.Read,
|
|
});
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
// reload to get membership
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toEqual(false);
|
|
expect(abilities.download).toEqual(false);
|
|
expect(abilities.update).toEqual(false);
|
|
expect(abilities.createChildDocument).toEqual(false);
|
|
expect(abilities.manageUsers).toEqual(false);
|
|
expect(abilities.archive).toEqual(false);
|
|
expect(abilities.delete).toEqual(false);
|
|
expect(abilities.share).toEqual(false);
|
|
expect(abilities.move).toEqual(false);
|
|
expect(abilities.subscribe).toEqual(false);
|
|
expect(abilities.unsubscribe).toEqual(false);
|
|
expect(abilities.comment).toEqual(false);
|
|
});
|
|
});
|
|
|
|
describe("private collection", () => {
|
|
it("should allow no permissions for team member", 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 abilities = serialize(user, document);
|
|
expect(abilities.read).toEqual(false);
|
|
expect(abilities.download).toEqual(false);
|
|
expect(abilities.update).toEqual(false);
|
|
expect(abilities.createChildDocument).toEqual(false);
|
|
expect(abilities.manageUsers).toEqual(false);
|
|
expect(abilities.archive).toEqual(false);
|
|
expect(abilities.delete).toEqual(false);
|
|
expect(abilities.share).toEqual(false);
|
|
expect(abilities.move).toEqual(false);
|
|
expect(abilities.subscribe).toEqual(false);
|
|
expect(abilities.unsubscribe).toEqual(false);
|
|
expect(abilities.comment).toEqual(false);
|
|
});
|
|
|
|
it("should allow no permissions for guest", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({
|
|
teamId: team.id,
|
|
role: UserRole.Guest,
|
|
});
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: null,
|
|
});
|
|
const document = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toEqual(false);
|
|
expect(abilities.download).toEqual(false);
|
|
expect(abilities.update).toEqual(false);
|
|
expect(abilities.createChildDocument).toEqual(false);
|
|
expect(abilities.manageUsers).toEqual(false);
|
|
expect(abilities.archive).toEqual(false);
|
|
expect(abilities.delete).toEqual(false);
|
|
expect(abilities.share).toEqual(false);
|
|
expect(abilities.move).toEqual(false);
|
|
expect(abilities.subscribe).toEqual(false);
|
|
expect(abilities.unsubscribe).toEqual(false);
|
|
expect(abilities.comment).toEqual(false);
|
|
});
|
|
});
|
|
|
|
describe("membership ids", () => {
|
|
it("should return the collection membership that grants access", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: null,
|
|
});
|
|
const membership = await UserMembership.create({
|
|
collectionId: collection.id,
|
|
userId: user.id,
|
|
createdById: user.id,
|
|
permission: CollectionPermission.ReadWrite,
|
|
});
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toEqual([membership.id]);
|
|
expect(abilities.update).toEqual([membership.id]);
|
|
});
|
|
|
|
it("should return the document membership that grants access", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: null,
|
|
});
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
const membership = await UserMembership.create({
|
|
documentId: doc.id,
|
|
userId: user.id,
|
|
createdById: user.id,
|
|
permission: DocumentPermission.Read,
|
|
});
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toEqual([membership.id]);
|
|
});
|
|
});
|
|
|
|
describe("duplicate", () => {
|
|
it("should allow members to duplicate from a read-write collection", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: CollectionPermission.ReadWrite,
|
|
});
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.duplicate).toBeTruthy();
|
|
});
|
|
|
|
it("should allow members to duplicate from a read-only collection", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: CollectionPermission.Read,
|
|
});
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.duplicate).toBeTruthy();
|
|
});
|
|
|
|
it("should allow guests to duplicate documents they can update", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({
|
|
teamId: team.id,
|
|
role: UserRole.Guest,
|
|
});
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: null,
|
|
});
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
await UserMembership.create({
|
|
documentId: doc.id,
|
|
userId: user.id,
|
|
createdById: user.id,
|
|
permission: DocumentPermission.ReadWrite,
|
|
});
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.update).toBeTruthy();
|
|
expect(abilities.duplicate).toBeTruthy();
|
|
});
|
|
|
|
it("should not allow guests to duplicate read-only documents", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({
|
|
teamId: team.id,
|
|
role: UserRole.Guest,
|
|
});
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: null,
|
|
});
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
await UserMembership.create({
|
|
documentId: doc.id,
|
|
userId: user.id,
|
|
createdById: user.id,
|
|
permission: DocumentPermission.Read,
|
|
});
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toBeTruthy();
|
|
expect(abilities.update).toEqual(false);
|
|
expect(abilities.duplicate).toEqual(false);
|
|
});
|
|
});
|
|
|
|
describe("no collection", () => {
|
|
it("should allow no permissions for team member", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const document = await buildDraftDocument({
|
|
teamId: team.id,
|
|
});
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toEqual(false);
|
|
expect(abilities.download).toEqual(false);
|
|
expect(abilities.update).toEqual(false);
|
|
expect(abilities.createChildDocument).toEqual(false);
|
|
expect(abilities.archive).toEqual(false);
|
|
expect(abilities.delete).toEqual(false);
|
|
expect(abilities.share).toEqual(false);
|
|
expect(abilities.move).toEqual(false);
|
|
expect(abilities.subscribe).toEqual(false);
|
|
expect(abilities.unsubscribe).toEqual(false);
|
|
expect(abilities.comment).toEqual(false);
|
|
});
|
|
|
|
it("should allow no permissions for guest", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({
|
|
teamId: team.id,
|
|
role: UserRole.Guest,
|
|
});
|
|
const document = await buildDraftDocument({
|
|
teamId: team.id,
|
|
});
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toEqual(false);
|
|
expect(abilities.download).toEqual(false);
|
|
expect(abilities.update).toEqual(false);
|
|
expect(abilities.createChildDocument).toEqual(false);
|
|
expect(abilities.archive).toEqual(false);
|
|
expect(abilities.delete).toEqual(false);
|
|
expect(abilities.share).toEqual(false);
|
|
expect(abilities.move).toEqual(false);
|
|
expect(abilities.subscribe).toEqual(false);
|
|
expect(abilities.unsubscribe).toEqual(false);
|
|
expect(abilities.comment).toEqual(false);
|
|
});
|
|
|
|
it("should allow edit permissions for creator", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const doc = await buildDraftDocument({
|
|
teamId: team.id,
|
|
userId: user.id,
|
|
});
|
|
// reload to get membership
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toBeTruthy();
|
|
expect(abilities.download).toBeTruthy();
|
|
expect(abilities.update).toBeTruthy();
|
|
expect(abilities.createChildDocument).toEqual(false);
|
|
expect(abilities.archive).toEqual(false);
|
|
expect(abilities.delete).toBeTruthy();
|
|
expect(abilities.share).toBeTruthy();
|
|
expect(abilities.move).toBeTruthy();
|
|
expect(abilities.subscribe).toBeTruthy();
|
|
expect(abilities.unsubscribe).toBeTruthy();
|
|
expect(abilities.comment).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
describe("archived document", () => {
|
|
it("should have correct permissions", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
userId: user.id,
|
|
archivedAt: new Date(),
|
|
});
|
|
// reload to get membership
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toBeTruthy();
|
|
expect(abilities.download).toBeTruthy();
|
|
expect(abilities.delete).toBeTruthy();
|
|
expect(abilities.unsubscribe).toBeTruthy();
|
|
expect(abilities.unarchive).toBeTruthy();
|
|
expect(abilities.update).toEqual(false);
|
|
expect(abilities.createChildDocument).toEqual(false);
|
|
expect(abilities.manageUsers).toBeTruthy();
|
|
expect(abilities.archive).toEqual(false);
|
|
expect(abilities.share).toEqual(false);
|
|
expect(abilities.move).toEqual(false);
|
|
expect(abilities.comment).toEqual(false);
|
|
});
|
|
});
|
|
|
|
describe("read document", () => {
|
|
for (const role of Object.values(UserRole)) {
|
|
it(`should allow read permissions for ${role}`, async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: null,
|
|
});
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
await UserMembership.create({
|
|
userId: user.id,
|
|
documentId: doc.id,
|
|
permission: DocumentPermission.Read,
|
|
createdById: user.id,
|
|
});
|
|
|
|
// reload to get membership
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toBeTruthy();
|
|
expect(abilities.download).toBeTruthy();
|
|
expect(abilities.subscribe).toBeTruthy();
|
|
expect(abilities.unsubscribe).toBeTruthy();
|
|
expect(abilities.comment).toBeTruthy();
|
|
expect(abilities.update).toEqual(false);
|
|
expect(abilities.createChildDocument).toEqual(false);
|
|
expect(abilities.manageUsers).toEqual(false);
|
|
expect(abilities.archive).toEqual(false);
|
|
expect(abilities.delete).toEqual(false);
|
|
expect(abilities.share).toEqual(false);
|
|
expect(abilities.move).toEqual(false);
|
|
});
|
|
}
|
|
});
|
|
|
|
describe("read_write document", () => {
|
|
const nonAdminRoles = Object.values(UserRole).filter(
|
|
(role) => role !== UserRole.Admin
|
|
);
|
|
for (const role of nonAdminRoles) {
|
|
it(`should allow write permissions for ${role}`, async () => {
|
|
const team = await buildTeam();
|
|
team.setPreference(TeamPreference.Commenting, CommentingAccess.Everyone);
|
|
await team.save();
|
|
const user = await buildUser({ teamId: team.id, role });
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: null,
|
|
});
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
await UserMembership.create({
|
|
userId: user.id,
|
|
documentId: doc.id,
|
|
permission: DocumentPermission.ReadWrite,
|
|
createdById: user.id,
|
|
});
|
|
|
|
// reload to get membership
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toBeTruthy();
|
|
expect(abilities.download).toBeTruthy();
|
|
expect(abilities.update).toBeTruthy();
|
|
expect(abilities.delete).toBeTruthy();
|
|
expect(abilities.subscribe).toBeTruthy();
|
|
expect(abilities.unsubscribe).toBeTruthy();
|
|
expect(abilities.comment).toBeTruthy();
|
|
expect(abilities.createChildDocument).toBeTruthy();
|
|
expect(abilities.manageUsers).toEqual(false);
|
|
expect(abilities.archive).toEqual(false);
|
|
expect(abilities.share).toEqual(false);
|
|
expect(abilities.move).toBeTruthy();
|
|
});
|
|
}
|
|
|
|
it(`should allow write permissions for admin`, async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildAdmin({ teamId: team.id });
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: null,
|
|
});
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
await UserMembership.create({
|
|
userId: user.id,
|
|
documentId: doc.id,
|
|
permission: DocumentPermission.ReadWrite,
|
|
createdById: user.id,
|
|
});
|
|
|
|
// reload to get membership
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toBeTruthy();
|
|
expect(abilities.download).toBeTruthy();
|
|
expect(abilities.update).toBeTruthy();
|
|
expect(abilities.delete).toBeTruthy();
|
|
expect(abilities.subscribe).toBeTruthy();
|
|
expect(abilities.unsubscribe).toBeTruthy();
|
|
expect(abilities.comment).toBeTruthy();
|
|
expect(abilities.createChildDocument).toBeTruthy();
|
|
expect(abilities.manageUsers).toBeTruthy();
|
|
expect(abilities.archive).toBeTruthy();
|
|
expect(abilities.share).toEqual(false);
|
|
expect(abilities.move).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
describe("commenting access", () => {
|
|
const buildGuestWithRead = async (commenting: CommentingAccess) => {
|
|
const team = await buildTeam();
|
|
team.setPreference(TeamPreference.Commenting, commenting);
|
|
await team.save();
|
|
const user = await buildUser({ teamId: team.id, role: UserRole.Guest });
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: null,
|
|
});
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
await UserMembership.create({
|
|
userId: user.id,
|
|
documentId: doc.id,
|
|
permission: DocumentPermission.Read,
|
|
createdById: user.id,
|
|
});
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
return { user, document };
|
|
};
|
|
|
|
it("should allow guest with read access to comment when members and guests", async () => {
|
|
const { user, document } = await buildGuestWithRead(
|
|
CommentingAccess.Everyone
|
|
);
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toBeTruthy();
|
|
expect(abilities.comment).toBeTruthy();
|
|
// proves commenting no longer requires write access
|
|
expect(abilities.update).toEqual(false);
|
|
});
|
|
|
|
it("should not allow guest with read access to comment when members only", async () => {
|
|
const { user, document } = await buildGuestWithRead(
|
|
CommentingAccess.Members
|
|
);
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toBeTruthy();
|
|
expect(abilities.comment).toEqual(false);
|
|
});
|
|
|
|
it("should not allow guest with read access to comment when disabled", async () => {
|
|
const { user, document } = await buildGuestWithRead(CommentingAccess.None);
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toBeTruthy();
|
|
expect(abilities.comment).toEqual(false);
|
|
});
|
|
|
|
it("should not allow guest without document access to comment when members and guests", async () => {
|
|
const team = await buildTeam();
|
|
team.setPreference(TeamPreference.Commenting, CommentingAccess.Everyone);
|
|
await team.save();
|
|
const user = await buildUser({ teamId: team.id, role: UserRole.Guest });
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: null,
|
|
});
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toEqual(false);
|
|
expect(abilities.comment).toEqual(false);
|
|
});
|
|
|
|
it("should allow member with read access to comment when members only (default)", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: null,
|
|
});
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
await UserMembership.create({
|
|
userId: user.id,
|
|
documentId: doc.id,
|
|
permission: DocumentPermission.Read,
|
|
createdById: user.id,
|
|
});
|
|
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toBeTruthy();
|
|
expect(abilities.comment).toBeTruthy();
|
|
});
|
|
|
|
it("should not allow member with read access to comment when disabled", async () => {
|
|
const team = await buildTeam();
|
|
team.setPreference(TeamPreference.Commenting, CommentingAccess.None);
|
|
await team.save();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: null,
|
|
});
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
await UserMembership.create({
|
|
userId: user.id,
|
|
documentId: doc.id,
|
|
permission: DocumentPermission.Read,
|
|
createdById: user.id,
|
|
});
|
|
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toBeTruthy();
|
|
expect(abilities.comment).toEqual(false);
|
|
});
|
|
});
|
|
|
|
describe("manage document", () => {
|
|
for (const role of Object.values(UserRole)) {
|
|
it(`should allow write permissions, user management, and sub-document creation for ${role}`, async () => {
|
|
const team = await buildTeam();
|
|
team.setPreference(TeamPreference.Commenting, CommentingAccess.Everyone);
|
|
await team.save();
|
|
const user = await buildUser({
|
|
teamId: team.id,
|
|
role,
|
|
});
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
permission: null,
|
|
});
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
});
|
|
await UserMembership.create({
|
|
userId: user.id,
|
|
documentId: doc.id,
|
|
permission: DocumentPermission.Admin,
|
|
createdById: user.id,
|
|
});
|
|
|
|
// reload to get membership
|
|
const document = await Document.findByPk(doc.id, { userId: user.id });
|
|
const abilities = serialize(user, document);
|
|
expect(abilities.read).toBeTruthy();
|
|
expect(abilities.download).toBeTruthy();
|
|
expect(abilities.update).toBeTruthy();
|
|
expect(abilities.delete).toBeTruthy();
|
|
expect(abilities.subscribe).toBeTruthy();
|
|
expect(abilities.unsubscribe).toBeTruthy();
|
|
expect(abilities.comment).toBeTruthy();
|
|
expect(abilities.createChildDocument).toBeTruthy();
|
|
expect(abilities.manageUsers).toBeTruthy();
|
|
expect(abilities.archive).toBeTruthy();
|
|
expect(abilities.move).toBeTruthy();
|
|
expect(abilities.share).toEqual(false);
|
|
});
|
|
}
|
|
});
|
|
|
|
describe("personal collection", () => {
|
|
const buildPersonal = async () => {
|
|
const team = await buildTeam();
|
|
team.setPreference(TeamPreference.PersonalDocs, true);
|
|
await team.save();
|
|
const owner = await buildUser({ teamId: team.id });
|
|
owner.team = team;
|
|
const collection = await buildPersonalCollection(owner);
|
|
const doc = await buildDocument({
|
|
teamId: team.id,
|
|
userId: owner.id,
|
|
collectionId: collection.id,
|
|
});
|
|
return { team, owner, collection, doc };
|
|
};
|
|
|
|
it("should allow the owner full access", async () => {
|
|
const { owner, doc } = await buildPersonal();
|
|
const document = await Document.findByPk(doc.id, { userId: owner.id });
|
|
const abilities = serialize(owner, document);
|
|
expect(abilities.read).toBeTruthy();
|
|
expect(abilities.update).toBeTruthy();
|
|
expect(abilities.move).toBeTruthy();
|
|
expect(abilities.archive).toBeTruthy();
|
|
expect(abilities.delete).toBeTruthy();
|
|
expect(abilities.share).toBeTruthy();
|
|
expect(abilities.manageUsers).toBeTruthy();
|
|
expect(abilities.unpublish).toEqual(false);
|
|
expect(abilities.updateInsights).toEqual(false);
|
|
expect(abilities.pin).toEqual(false);
|
|
expect(abilities.unpin).toEqual(false);
|
|
expect(abilities.pinToHome).toEqual(false);
|
|
});
|
|
|
|
it("should allow nothing for a workspace admin", async () => {
|
|
const { team, doc } = await buildPersonal();
|
|
const admin = await buildAdmin({ teamId: team.id });
|
|
const document = await Document.findByPk(doc.id, { userId: admin.id });
|
|
const abilities = serialize(admin, document);
|
|
for (const [ability, value] of Object.entries(abilities)) {
|
|
expect({ ability, value }).toEqual({ ability, value: false });
|
|
}
|
|
});
|
|
|
|
it("should not allow a workspace admin to permanently delete", async () => {
|
|
const { team, owner, doc } = await buildPersonal();
|
|
const admin = await buildAdmin({ teamId: team.id });
|
|
await doc.destroy({ hooks: false });
|
|
const ownerDocument = await Document.findByPk(doc.id, {
|
|
userId: owner.id,
|
|
paranoid: false,
|
|
});
|
|
const adminDocument = await Document.findByPk(doc.id, {
|
|
userId: admin.id,
|
|
paranoid: false,
|
|
});
|
|
expect(serialize(admin, adminDocument).permanentDelete).toEqual(false);
|
|
expect(serialize(owner, ownerDocument).restore).toBeTruthy();
|
|
});
|
|
|
|
it("should allow a collaborator through a document membership", async () => {
|
|
const { team, owner, doc } = await buildPersonal();
|
|
const collaborator = await buildUser({ teamId: team.id });
|
|
collaborator.team = team;
|
|
await UserMembership.create({
|
|
documentId: doc.id,
|
|
userId: collaborator.id,
|
|
permission: DocumentPermission.ReadWrite,
|
|
createdById: owner.id,
|
|
});
|
|
const document = await Document.findByPk(doc.id, {
|
|
userId: collaborator.id,
|
|
});
|
|
const abilities = serialize(collaborator, document);
|
|
expect(abilities.read).toBeTruthy();
|
|
expect(abilities.update).toBeTruthy();
|
|
expect(abilities.manageUsers).toEqual(false);
|
|
});
|
|
|
|
it("should be read-only when personal documents are turned off", async () => {
|
|
const { team, owner, doc } = await buildPersonal();
|
|
const collaborator = await buildUser({ teamId: team.id });
|
|
await UserMembership.create({
|
|
documentId: doc.id,
|
|
userId: collaborator.id,
|
|
permission: DocumentPermission.ReadWrite,
|
|
createdById: owner.id,
|
|
});
|
|
team.setPreference(TeamPreference.PersonalDocs, false);
|
|
await team.save();
|
|
owner.team = team;
|
|
collaborator.team = team;
|
|
|
|
const document = await Document.findByPk(doc.id, { userId: owner.id });
|
|
const abilities = serialize(owner, document);
|
|
expect(abilities.read).toBeTruthy();
|
|
expect(abilities.update).toEqual(false);
|
|
expect(abilities.createChildDocument).toEqual(false);
|
|
expect(abilities.move).toBeTruthy();
|
|
expect(abilities.archive).toBeTruthy();
|
|
expect(abilities.delete).toBeTruthy();
|
|
|
|
const collaboratorDocument = await Document.findByPk(doc.id, {
|
|
userId: collaborator.id,
|
|
});
|
|
const collaboratorAbilities = serialize(collaborator, collaboratorDocument);
|
|
expect(collaboratorAbilities.read).toBeTruthy();
|
|
expect(collaboratorAbilities.update).toEqual(false);
|
|
expect(collaboratorAbilities.move).toEqual(false);
|
|
});
|
|
});
|