mirror of
https://github.com/outline/outline.git
synced 2026-11-21 13:34:02 +03:00
* feat: Request document access Allow users without permission to a document to request access. Notifies document managers via in-app notification and email; managers can grant or dismiss the request. - Adds AccessRequest model, migration, policy, presenter - Adds accessRequests.create/info/approve/dismiss endpoints - Adds DocumentAccessRequestNotificationsTask + email - Adds Error403 request flow with loading state and pending indicator - Auto-opens notifications popover via ?notifications=true (used in email) - Adds SplitButton primitive for permission selection in notifications - Refactors useConsumeQueryParam hook * refactor * fix: Make approve/dismiss idempotent on access requests Return success when the access request has already been dismissed, or when the user already has document membership at approve time, instead of throwing 400. Avoids racy double-clicks on notification actions producing user-visible errors. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * Minor fixes --------- Co-authored-by: Tom Moor <tom@getoutline.com> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
138 lines
4.6 KiB
TypeScript
138 lines
4.6 KiB
TypeScript
import type {
|
|
AccessRequestEvent,
|
|
CollectionEvent,
|
|
RevisionEvent,
|
|
Event,
|
|
DocumentEvent,
|
|
CommentEvent,
|
|
CollectionUserEvent,
|
|
DocumentUserEvent,
|
|
DocumentGroupEvent,
|
|
CommentReactionEvent,
|
|
} from "@server/types";
|
|
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 DocumentAddUserNotificationsTask from "../tasks/DocumentAddUserNotificationsTask";
|
|
import DocumentPublishedNotificationsTask from "../tasks/DocumentPublishedNotificationsTask";
|
|
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_group",
|
|
"access_requests.create",
|
|
"revisions.create",
|
|
"collections.create",
|
|
"collections.add_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_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 "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 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 new RevisionCreatedNotificationsTask().schedule(event);
|
|
await 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 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);
|
|
}
|
|
}
|