Files
outline/server/queues/processors/DocumentSubscriptionProcessor.ts
T
Claude 212fd15966 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
2026-11-01 03:16:45 +00:00

102 lines
2.7 KiB
TypeScript

import { GroupUser } from "@server/models";
import type {
CollectionGroupEvent,
CollectionUserEvent,
DocumentGroupEvent,
DocumentOwnerEvent,
DocumentUserEvent,
Event,
} from "@server/types";
import CollectionSubscriptionRemoveUserTask from "../tasks/CollectionSubscriptionRemoveUserTask";
import DocumentSubscriptionAddOwnerTask from "../tasks/DocumentSubscriptionAddOwnerTask";
import DocumentSubscriptionRemoveUserTask from "../tasks/DocumentSubscriptionRemoveUserTask";
import BaseProcessor from "./BaseProcessor";
type ReceivedEvent =
| CollectionUserEvent
| CollectionGroupEvent
| DocumentUserEvent
| DocumentGroupEvent
| DocumentOwnerEvent;
export default class DocumentSubscriptionProcessor extends BaseProcessor {
static applicableEvents: Event["name"][] = [
"collections.remove_user",
"collections.remove_group",
"documents.remove_user",
"documents.remove_group",
"documents.add_owner",
];
async perform(event: ReceivedEvent) {
switch (event.name) {
case "collections.remove_user": {
await new CollectionSubscriptionRemoveUserTask().schedule(event);
return;
}
case "collections.remove_group":
return this.handleRemoveGroupFromCollection(event);
case "documents.remove_user": {
await new DocumentSubscriptionRemoveUserTask().schedule(event);
return;
}
case "documents.remove_group":
return this.handleRemoveGroupFromDocument(event);
case "documents.add_owner": {
await new DocumentSubscriptionAddOwnerTask().schedule(event);
return;
}
default:
}
}
private async handleRemoveGroupFromCollection(event: CollectionGroupEvent) {
await GroupUser.findAllInBatches<GroupUser>(
{
where: {
groupId: event.modelId,
},
batchLimit: 10,
},
async (groupUsers) => {
await Promise.all(
groupUsers.map((groupUser) =>
new CollectionSubscriptionRemoveUserTask().schedule({
...event,
name: "collections.remove_user",
userId: groupUser.userId,
} as CollectionUserEvent)
)
);
}
);
}
private async handleRemoveGroupFromDocument(event: DocumentGroupEvent) {
await GroupUser.findAllInBatches<GroupUser>(
{
where: {
groupId: event.modelId,
},
batchLimit: 10,
},
async (groupUsers) => {
await Promise.all(
groupUsers.map((groupUser) =>
new DocumentSubscriptionRemoveUserTask().schedule({
...event,
name: "documents.remove_user",
userId: groupUser.userId,
} as DocumentUserEvent)
)
);
}
);
}
}