mirror of
https://github.com/outline/outline.git
synced 2026-11-30 09:00:18 +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>
95 lines
2.5 KiB
TypeScript
95 lines
2.5 KiB
TypeScript
import * as React from "react";
|
|
import { Document, User } from "@server/models";
|
|
import type { EmailProps } from "./BaseEmail";
|
|
import BaseEmail, { EmailMessageCategory } from "./BaseEmail";
|
|
import Body from "./components/Body";
|
|
import Button from "./components/Button";
|
|
import EmailTemplate from "./components/EmailLayout";
|
|
import Header from "./components/Header";
|
|
import Heading from "./components/Heading";
|
|
|
|
type InputProps = EmailProps & {
|
|
documentId: string;
|
|
actorId: string;
|
|
teamUrl: string;
|
|
};
|
|
|
|
type BeforeSend = {
|
|
document: Document;
|
|
actor: User;
|
|
};
|
|
|
|
type Props = InputProps & BeforeSend;
|
|
|
|
/**
|
|
* Email sent to users who can manage a document when someone requests access.
|
|
*/
|
|
export default class DocumentAccessRequestEmail extends BaseEmail<
|
|
InputProps,
|
|
BeforeSend
|
|
> {
|
|
protected get category() {
|
|
return EmailMessageCategory.Notification;
|
|
}
|
|
|
|
protected async beforeSend({ documentId, actorId }: InputProps) {
|
|
const document = await Document.unscoped().findByPk(documentId);
|
|
if (!document) {
|
|
return false;
|
|
}
|
|
|
|
const actor = await User.findByPk(actorId);
|
|
if (!actor) {
|
|
return false;
|
|
}
|
|
|
|
return { document, actor };
|
|
}
|
|
|
|
protected subject({ actor, document }: Props) {
|
|
return `${actor.name} is requesting access to "${document.titleWithDefault}"`;
|
|
}
|
|
|
|
protected preview({ actor }: Props): string {
|
|
return `${actor.name} is requesting access to a document`;
|
|
}
|
|
|
|
protected fromName({ actor }: Props) {
|
|
return actor.name;
|
|
}
|
|
|
|
protected renderAsText({ actor, teamUrl, document }: Props): string {
|
|
return `
|
|
${actor.name} is requesting access to "${document.titleWithDefault}".
|
|
|
|
Open the document to share it with them: ${teamUrl}${document.path}
|
|
`;
|
|
}
|
|
|
|
protected render(props: Props) {
|
|
const { document, actor, teamUrl } = props;
|
|
const documentUrl = `${teamUrl}${document.path}?ref=notification-email¬ifications=true`;
|
|
|
|
return (
|
|
<EmailTemplate
|
|
previewText={this.preview(props)}
|
|
goToAction={{ url: documentUrl, name: "View Document" }}
|
|
>
|
|
<Header />
|
|
|
|
<Body>
|
|
<Heading>{document.titleWithDefault}</Heading>
|
|
<p>
|
|
{actor.name} is requesting access to the{" "}
|
|
<a href={documentUrl}>{document.titleWithDefault}</a> document.
|
|
</p>
|
|
<p>Open the document to share it with them.</p>
|
|
<p>
|
|
<Button href={documentUrl}>View Document</Button>
|
|
</p>
|
|
</Body>
|
|
</EmailTemplate>
|
|
);
|
|
}
|
|
}
|