Files
outline/server/queues/processors/NotificationsProcessor.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

180 lines
5.9 KiB
TypeScript

import type {
AccessRequestEvent,
CollectionEvent,
RevisionEvent,
Event,
DocumentEvent,
CommentEvent,
CollectionUserEvent,
CollectionOwnerEvent,
DocumentUserEvent,
DocumentOwnerEvent,
DocumentGroupEvent,
CommentReactionEvent,
GroupUserEvent,
} from "@server/types";
import CollectionAddOwnerNotificationsTask from "../tasks/CollectionAddOwnerNotificationsTask";
import CollectionAddUserNotificationsTask from "../tasks/CollectionAddUserNotificationsTask";
import CollectionCreatedNotificationsTask from "../tasks/CollectionCreatedNotificationsTask";
import CommentCreatedNotificationsTask from "../tasks/CommentCreatedNotificationsTask";
import CommentUpdatedNotificationsTask from "../tasks/CommentUpdatedNotificationsTask";
import ReactionCreatedNotificationsTask from "../tasks/ReactionCreatedNotificationsTask";
import ReactionRemovedNotificationsTask from "../tasks/ReactionRemovedNotificationsTask";
import DocumentAccessRequestNotificationsTask from "../tasks/DocumentAccessRequestNotificationsTask";
import DocumentAddGroupNotificationsTask from "../tasks/DocumentAddGroupNotificationsTask";
import DocumentAddOwnerNotificationsTask from "../tasks/DocumentAddOwnerNotificationsTask";
import DocumentAddUserNotificationsTask from "../tasks/DocumentAddUserNotificationsTask";
import DocumentPublishedNotificationsTask from "../tasks/DocumentPublishedNotificationsTask";
import GroupUserNotificationsTask from "../tasks/GroupUserNotificationsTask";
import RevisionCreatedNotificationsTask from "../tasks/RevisionCreatedNotificationsTask";
import ShareSubscriptionNotificationsTask from "../tasks/ShareSubscriptionNotificationsTask";
import BaseProcessor from "./BaseProcessor";
export default class NotificationsProcessor extends BaseProcessor {
static applicableEvents: Event["name"][] = [
"documents.publish",
"documents.add_user",
"documents.add_owner",
"documents.add_group",
"access_requests.create",
"revisions.create",
"collections.create",
"collections.add_user",
"collections.add_owner",
"groups.add_user",
"groups.remove_user",
"comments.create",
"comments.update",
"comments.add_reaction",
"comments.remove_reaction",
];
async perform(event: Event) {
switch (event.name) {
case "documents.publish":
return this.documentPublished(event);
case "documents.add_user":
return this.documentAddUser(event);
case "documents.add_owner":
return this.documentAddOwner(event);
case "documents.add_group":
return this.documentAddGroup(event);
case "access_requests.create":
return this.documentAccessRequest(event);
case "revisions.create":
return this.revisionCreated(event);
case "collections.create":
return this.collectionCreated(event);
case "collections.add_user":
return this.collectionAddUser(event);
case "collections.add_owner":
return this.collectionAddOwner(event);
case "groups.add_user":
case "groups.remove_user":
return this.groupUserChanged(event);
case "comments.create":
return this.commentCreated(event);
case "comments.update":
return this.commentUpdated(event);
case "comments.add_reaction":
return this.reactionCreated(event);
case "comments.remove_reaction":
return this.reactionRemoved(event);
default:
}
}
async documentPublished(event: DocumentEvent) {
// never send notifications when batch importing
if (event.name === "documents.publish" && event.data?.source === "import") {
return;
}
await new DocumentPublishedNotificationsTask().schedule(event);
}
async documentAddUser(event: DocumentUserEvent) {
if (!event.data?.isNew || event.userId === event.actorId) {
return;
}
await new DocumentAddUserNotificationsTask().schedule(event);
}
async documentAddOwner(event: DocumentOwnerEvent) {
if (event.userId === event.actorId) {
return;
}
await new DocumentAddOwnerNotificationsTask().schedule(event);
}
async documentAddGroup(event: DocumentGroupEvent) {
if (!event.data.isNew) {
return;
}
await new DocumentAddGroupNotificationsTask().schedule(event);
}
async documentAccessRequest(event: AccessRequestEvent) {
await new DocumentAccessRequestNotificationsTask().schedule(event);
}
async revisionCreated(event: RevisionEvent) {
await Promise.all([
new RevisionCreatedNotificationsTask().schedule(event),
new ShareSubscriptionNotificationsTask().schedule(event),
]);
}
async collectionCreated(event: CollectionEvent) {
// never send notifications when batch importing
if (
!!event.changes?.attributes.apiImportId ||
!!event.changes?.attributes.importId
) {
return;
}
await new CollectionCreatedNotificationsTask().schedule(event);
}
async collectionAddUser(event: CollectionUserEvent) {
if (!event.data?.isNew || event.userId === event.actorId) {
return;
}
await new CollectionAddUserNotificationsTask().schedule(event);
}
async collectionAddOwner(event: CollectionOwnerEvent) {
if (event.userId === event.actorId) {
return;
}
await new CollectionAddOwnerNotificationsTask().schedule(event);
}
async groupUserChanged(event: GroupUserEvent) {
if (event.userId === event.actorId) {
return;
}
await new GroupUserNotificationsTask().schedule(event);
}
async commentCreated(event: CommentEvent) {
await new CommentCreatedNotificationsTask().schedule(event);
}
async commentUpdated(event: CommentEvent) {
await new CommentUpdatedNotificationsTask().schedule(event);
}
async reactionCreated(event: CommentReactionEvent) {
await new ReactionCreatedNotificationsTask().schedule(event);
}
async reactionRemoved(event: CommentReactionEvent) {
await new ReactionRemovedNotificationsTask().schedule(event);
}
}