mirror of
https://github.com/outline/outline.git
synced 2026-12-06 11:12:32 +03:00
* feat: Add document owners Documents can now have owners, stored as an array of user IDs. Owners must be active members or admins, and changing them requires the existing manage users permission on the document, gated behind a new DocumentOwners plan entitlement that is included in every plan. - ownerIds accepted by documents.create and documents.update and returned by the document presenter - ownerIds filter field (eq/in) for documents.list and documents.search - ownerIds on the MCP create_document and update_document tools, and an ownerId filter on list_documents - Owners section in the document Insights dialog to add and remove owners - Owner filter on the search page - In-app and email notification when a user is made an owner Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MJXFdSZ39ZGPf31jyGcYz * feat: Give document owners responsibility for their documents - Access requests are routed to owners that can manage the document before falling back to document, collection and workspace admins - Owners are subscribed to a document when they are added, respecting a previous unsubscribe - Owners that can edit a document can also manage its access, owners and archive it; ownership never grants access on its own - Owners are shown in the document byline, list items and search results, and document hover previews Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MJXFdSZ39ZGPf31jyGcYz * feat: Manage document owners from the share panel - Owner is a role in the share panel permission menu and invite picker for individual users, adding an owner gives them the manage permission - Lowering an owner's permission or removing their access removes the ownership - Owners are sorted to the top of the member list - Owners added through the API or MCP are given the manage permission - Owners do not also receive the "added to document" notification - Only added owners are validated, so suspended owners can still be removed - Deleted users are removed from document owners - Removes the owners section from Insights * fix: Address review feedback on document owners - Authorize owner changes before assigning owners on create - Lock the document when adding an owner so concurrent invitations are kept - Enforce the owner limit on every path - Run MCP document updates in a transaction - Broadcast owner removals to connected clients * feat: Add collection owners - Collections can have owners, who also own every document in the collection, shown first in document bylines - Owner is a role in the collection share panel and invite picker for individual users, adding an owner gives them the manage permission - Lowering an owner's permission or removing their access removes the ownership - ownerIds on collections.create, collections.update and the MCP collection tools - The document owner filter includes documents in owned collections - Access requests go to document and collection owners together - Collection owners are subscribed to the collection and notified when they are added - Deleted users are removed from collection owners - Renames the personal collection policy helper to isPersonalCollectionOwner * feat: Show profile cards on owner names, hide inherited owners in collection lists * fix: Allow adding yourself as a collection owner, include collection owners in MCP exact match * fix: Correct singular owner translations * feat: Allow users to make themselves a document owner - The share panel suggests the current user when they can manage owners, and only offers the Owner permission for them - documents.add_user accepts the actor's own ID when changing ownership, without changing their own access - An owner's own row offers "Remove as owner", which keeps their access - Hides the duplicate "You have full access" row when the current user is listed as a member * fix: Restore singular owner translations * fix: Limit owners to 5, use no key update locks when adding owners * refactor: Move owner logic into Document and Collection model methods - addOwner, removeOwner, grantOwnerAccess and setOwnerIds on both models, locking the row so concurrent owner changes are kept - Owner events are created by an update hook from the change in ownerIds - The manageOwners check runs at the route level when ownerIds is sent - Removes the documentOwners and collectionOwners command modules - Removes duplicate owner tests * fix: Owner selection and membership edge cases - Remove document owners from the legacy plan - Selecting yourself in the share picker only suggests other users that can be owners, and you are not suggested next to groups or guests - Users that make themselves an owner through the API get the manage permission, so they are listed in the share panel * perf: Scope the collection owner filter subquery to the team * chore: Drop redundant teamId UUID check --------- Co-authored-by: Claude <noreply@anthropic.com>
406 lines
9.4 KiB
TypeScript
406 lines
9.4 KiB
TypeScript
import invariant from "invariant";
|
|
import {
|
|
CollectionPermission,
|
|
PlanFeature,
|
|
TeamPreference,
|
|
} from "@shared/types";
|
|
import { Collection, User, Team } from "@server/models";
|
|
import { allow, can } from "./cancan";
|
|
import {
|
|
and,
|
|
isPersonalCollectionOwner,
|
|
isCollectionWritable,
|
|
isTeamAdmin,
|
|
isTeamModel,
|
|
isTeamMutable,
|
|
or,
|
|
teamHasEntitlement,
|
|
} from "./utils";
|
|
|
|
allow(User, "createCollection", Team, (actor, team) =>
|
|
and(
|
|
!actor.isGuest,
|
|
!actor.isViewer,
|
|
isTeamModel(actor, team),
|
|
isTeamMutable(actor),
|
|
or(actor.isAdmin, !!team?.memberCollectionCreate)
|
|
)
|
|
);
|
|
|
|
allow(User, "importCollection", Team, (actor, team) =>
|
|
and(
|
|
//
|
|
isTeamAdmin(actor, team),
|
|
isTeamMutable(actor)
|
|
)
|
|
);
|
|
|
|
allow(User, "createPersonalCollection", Team, (actor, team) =>
|
|
and(
|
|
!actor.isGuest,
|
|
!actor.isViewer,
|
|
isTeamModel(actor, team),
|
|
isTeamMutable(actor),
|
|
!!team?.getPreference(TeamPreference.PersonalDocs)
|
|
)
|
|
);
|
|
|
|
allow(User, "move", Collection, (actor, collection) =>
|
|
and(
|
|
!!collection?.isActive,
|
|
!collection?.isPersonal,
|
|
isTeamAdmin(actor, collection),
|
|
isTeamMutable(actor)
|
|
)
|
|
);
|
|
|
|
allow(User, "read", Collection, (user, collection) => {
|
|
if (!collection || user.teamId !== collection.teamId) {
|
|
return false;
|
|
}
|
|
if (collection.isPersonal) {
|
|
return isPersonalCollectionOwner(user, collection);
|
|
}
|
|
if (user.isAdmin) {
|
|
return true;
|
|
}
|
|
|
|
if (collection.isPrivate || user.isGuest) {
|
|
return includesMembership(collection, Object.values(CollectionPermission));
|
|
}
|
|
|
|
return true;
|
|
});
|
|
|
|
allow(User, "duplicate", Collection, (actor, collection) =>
|
|
and(
|
|
!!collection?.isActive,
|
|
!collection?.isPersonal,
|
|
can(actor, "read", collection),
|
|
can(actor, "createCollection", actor.team)
|
|
)
|
|
);
|
|
|
|
allow(User, "download", Collection, (actor, collection) =>
|
|
and(
|
|
can(actor, "read", collection),
|
|
or(
|
|
and(!actor.isGuest, !actor.isViewer),
|
|
!!actor.team.getPreference(TeamPreference.ViewersCanExport)
|
|
)
|
|
)
|
|
);
|
|
|
|
// A personal collection cannot be starred, as it has no page to link to.
|
|
allow(User, ["star", "unstar"], Collection, (user, collection) =>
|
|
and(
|
|
//
|
|
!collection?.isPersonal,
|
|
can(user, "readDocument", collection)
|
|
)
|
|
);
|
|
|
|
allow(
|
|
User,
|
|
["readDocument", "subscribe", "unsubscribe"],
|
|
Collection,
|
|
(user, collection) => {
|
|
if (!collection || user.teamId !== collection.teamId) {
|
|
return false;
|
|
}
|
|
|
|
if (collection.isPersonal) {
|
|
return isPersonalCollectionOwner(user, collection);
|
|
}
|
|
|
|
if (collection.isPrivate || user.isGuest) {
|
|
return includesMembership(
|
|
collection,
|
|
Object.values(CollectionPermission)
|
|
);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
);
|
|
|
|
allow(User, "share", Collection, (user, collection) =>
|
|
and(
|
|
//
|
|
!collection?.isPersonal,
|
|
can(user, "shareDocument", collection)
|
|
)
|
|
);
|
|
|
|
allow(User, "shareDocument", Collection, (user, collection) => {
|
|
if (
|
|
!collection ||
|
|
user.isGuest ||
|
|
user.teamId !== collection.teamId ||
|
|
!isTeamMutable(user)
|
|
) {
|
|
return false;
|
|
}
|
|
if (!collection.sharing) {
|
|
return false;
|
|
}
|
|
if (collection.isPersonal) {
|
|
return isPersonalCollectionOwner(user, collection);
|
|
}
|
|
if (!collection.isPrivate && user.isAdmin) {
|
|
return true;
|
|
}
|
|
|
|
if (
|
|
collection.permission !== CollectionPermission.ReadWrite ||
|
|
user.isViewer
|
|
) {
|
|
return includesMembership(collection, [
|
|
CollectionPermission.ReadWrite,
|
|
CollectionPermission.Admin,
|
|
]);
|
|
}
|
|
|
|
return true;
|
|
});
|
|
|
|
allow(User, "updateDocument", Collection, (user, collection) => {
|
|
if (
|
|
!collection ||
|
|
!isTeamModel(user, collection) ||
|
|
!isTeamMutable(user) ||
|
|
!isCollectionWritable(user, collection)
|
|
) {
|
|
return false;
|
|
}
|
|
if (collection.isPersonal) {
|
|
return isPersonalCollectionOwner(user, collection);
|
|
}
|
|
|
|
if (
|
|
collection.permission !== CollectionPermission.ReadWrite ||
|
|
user.isViewer ||
|
|
user.isGuest
|
|
) {
|
|
return includesMembership(collection, [
|
|
CollectionPermission.ReadWrite,
|
|
CollectionPermission.Admin,
|
|
]);
|
|
}
|
|
|
|
return true;
|
|
});
|
|
|
|
allow(
|
|
User,
|
|
["createDocument", "deleteDocument"],
|
|
Collection,
|
|
(user, collection) => {
|
|
if (
|
|
!collection ||
|
|
!collection.isActive ||
|
|
!isTeamModel(user, collection) ||
|
|
!isTeamMutable(user) ||
|
|
!isCollectionWritable(user, collection)
|
|
) {
|
|
return false;
|
|
}
|
|
if (collection.isPersonal) {
|
|
return isPersonalCollectionOwner(user, collection);
|
|
}
|
|
|
|
if (
|
|
collection.permission !== CollectionPermission.ReadWrite ||
|
|
user.isViewer ||
|
|
user.isGuest
|
|
) {
|
|
return includesMembership(collection, [
|
|
CollectionPermission.ReadWrite,
|
|
CollectionPermission.Admin,
|
|
]);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
);
|
|
|
|
allow(
|
|
User,
|
|
["createTemplate", "manageTemplate"],
|
|
Collection,
|
|
(user, collection) =>
|
|
and(
|
|
!!collection,
|
|
!!collection?.isActive,
|
|
isTeamModel(user, collection),
|
|
isTeamMutable(user),
|
|
// Templates in a personal collection would only be visible to its owner.
|
|
!collection?.isPersonal,
|
|
or(
|
|
isTeamAdmin(user, collection),
|
|
includesMembership(collection, [CollectionPermission.Admin]),
|
|
and(
|
|
collection?.templateManagement === CollectionPermission.ReadWrite,
|
|
!user.isGuest,
|
|
or(
|
|
and(
|
|
collection?.permission === CollectionPermission.ReadWrite,
|
|
!user.isViewer
|
|
),
|
|
includesMembership(collection, [
|
|
CollectionPermission.ReadWrite,
|
|
CollectionPermission.Admin,
|
|
])
|
|
)
|
|
)
|
|
)
|
|
)
|
|
);
|
|
|
|
allow(User, "update", Collection, (user, collection) =>
|
|
and(
|
|
isTeamModel(user, collection),
|
|
!!collection?.isActive,
|
|
isOwnerIfPersonal(user, collection),
|
|
or(
|
|
isPersonalCollectionOwner(user, collection),
|
|
isTeamAdmin(user, collection),
|
|
includesMembership(collection, [CollectionPermission.Admin])
|
|
)
|
|
)
|
|
);
|
|
|
|
// A personal collection cannot be archived or deleted, so that its owner always
|
|
// has exactly one.
|
|
allow(User, "archive", Collection, (user, collection) =>
|
|
and(
|
|
//
|
|
!collection?.isPersonal,
|
|
can(user, "update", collection)
|
|
)
|
|
);
|
|
|
|
// Pins are shown on the collection page, which a personal collection does not
|
|
// have.
|
|
allow(User, "pin", Collection, (user, collection) =>
|
|
and(
|
|
//
|
|
!collection?.isPersonal,
|
|
can(user, "update", collection)
|
|
)
|
|
);
|
|
|
|
// Only the owner is a member of a personal collection, documents in it are
|
|
// shared through document memberships instead.
|
|
allow(User, "manageUsers", Collection, (user, collection) =>
|
|
and(
|
|
//
|
|
!collection?.isPersonal,
|
|
can(user, "update", collection)
|
|
)
|
|
);
|
|
|
|
allow(User, "manageOwners", Collection, (user, collection) =>
|
|
and(
|
|
!!collection?.isActive,
|
|
teamHasEntitlement(user.team, PlanFeature.DocumentOwners),
|
|
can(user, "manageUsers", collection)
|
|
)
|
|
);
|
|
|
|
allow(User, "export", Collection, (user, collection) =>
|
|
and(
|
|
!!collection,
|
|
!!collection?.isActive,
|
|
can(user, "download", collection),
|
|
isOwnerIfPersonal(user, collection),
|
|
or(
|
|
isPersonalCollectionOwner(user, collection),
|
|
isTeamAdmin(user, collection),
|
|
includesMembership(collection, [CollectionPermission.Admin])
|
|
)
|
|
)
|
|
);
|
|
|
|
allow(User, "delete", Collection, (user, collection) =>
|
|
and(
|
|
isTeamModel(user, collection),
|
|
!collection?.deletedAt,
|
|
!collection?.isPersonal,
|
|
or(
|
|
isTeamAdmin(user, collection),
|
|
includesMembership(collection, [CollectionPermission.Admin])
|
|
)
|
|
)
|
|
);
|
|
|
|
allow(User, "restore", Collection, (user, collection) =>
|
|
and(
|
|
isTeamModel(user, collection),
|
|
!collection?.isActive,
|
|
isOwnerIfPersonal(user, collection),
|
|
or(
|
|
isPersonalCollectionOwner(user, collection),
|
|
isTeamAdmin(user, collection),
|
|
includesMembership(collection, [CollectionPermission.Admin])
|
|
)
|
|
)
|
|
);
|
|
|
|
allow(User, "updateDeprecatedReason", Collection, (actor, collection) =>
|
|
and(
|
|
!!collection?.archivedAt,
|
|
!collection?.deletedAt,
|
|
isTeamModel(actor, collection),
|
|
isTeamMutable(actor),
|
|
can(actor, "restore", collection)
|
|
)
|
|
);
|
|
|
|
/**
|
|
* Check that the actor owns the collection when it is a personal collection.
|
|
* Admins have no access to the personal collections of other users.
|
|
*
|
|
* @param user The actor to check.
|
|
* @param collection The collection to check.
|
|
* @returns True if the collection is not personal or the actor owns it.
|
|
*/
|
|
function isOwnerIfPersonal(user: User, collection: Collection | null) {
|
|
return !collection?.isPersonal || isPersonalCollectionOwner(user, collection);
|
|
}
|
|
|
|
function includesMembership(
|
|
collection: Collection | null,
|
|
permissions: CollectionPermission[]
|
|
) {
|
|
if (!collection) {
|
|
return false;
|
|
}
|
|
|
|
invariant(
|
|
collection.memberships,
|
|
"Development: collection memberships not preloaded, did you forget `withMembership` scope?"
|
|
);
|
|
invariant(
|
|
collection.groupMemberships,
|
|
"Development: collection groupMemberships not preloaded, did you forget `withMembership` scope?"
|
|
);
|
|
|
|
const permissionSet = new Set(permissions);
|
|
const membershipIds: string[] = [];
|
|
|
|
for (const membership of collection.memberships) {
|
|
if (permissionSet.has(membership.permission as CollectionPermission)) {
|
|
membershipIds.push(membership.id);
|
|
}
|
|
}
|
|
|
|
for (const membership of collection.groupMemberships) {
|
|
if (permissionSet.has(membership.permission as CollectionPermission)) {
|
|
membershipIds.push(membership.id);
|
|
}
|
|
}
|
|
|
|
return membershipIds.length > 0 ? membershipIds : false;
|
|
}
|