Files
outline/server/queues/tasks/CollectionSubscriptionAddOwnerTask.ts
T
Tom Moor 9666d8e825 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
2026-11-06 22:45:07 -05:00

31 lines
933 B
TypeScript

import { subscribeUserToCollection } from "@server/commands/subscriptionCreator";
import { Collection, User } from "@server/models";
import { can } from "@server/policies";
import type { CollectionOwnerEvent } from "@server/types";
import { BaseTask } from "./base/BaseTask";
/**
* Subscribes a user to the documents in a collection when they are made an
* owner of it.
*/
export default class CollectionSubscriptionAddOwnerTask extends BaseTask<CollectionOwnerEvent> {
public async perform(event: CollectionOwnerEvent) {
const user = await User.findByPk(event.userId);
if (!user || user.isSuspended) {
return;
}
const collection = await Collection.findByPk(event.collectionId, {
userId: user.id,
});
if (
!collection?.ownerIds?.includes(user.id) ||
!can(user, "read", collection)
) {
return;
}
await subscribeUserToCollection(user, collection, event);
}
}