mirror of
https://github.com/outline/outline.git
synced 2026-11-29 16:40:27 +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>
142 lines
4.2 KiB
TypeScript
142 lines
4.2 KiB
TypeScript
import { toJS } from "mobx";
|
|
import { observer } from "mobx-react";
|
|
import * as React from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { Link } from "react-router-dom";
|
|
import styled from "styled-components";
|
|
import { s, hover, truncateMultiline } from "@shared/styles";
|
|
import { NotificationEventType } from "@shared/types";
|
|
import type Notification from "~/models/Notification";
|
|
import useStores from "~/hooks/useStores";
|
|
import { Avatar, AvatarSize, AvatarVariant } from "../Avatar";
|
|
import Flex from "../Flex";
|
|
import Text from "../Text";
|
|
import Time from "../Time";
|
|
import { UnreadBadge } from "../UnreadBadge";
|
|
import lazyWithRetry from "~/utils/lazyWithRetry";
|
|
import { ContextMenu } from "../Menu/ContextMenu";
|
|
import { createActionWithChildren } from "~/actions";
|
|
import {
|
|
notificationMarkRead,
|
|
notificationMarkUnread,
|
|
notificationArchive,
|
|
} from "~/actions/definitions/notifications";
|
|
import { NotificationSection } from "~/actions/sections";
|
|
import AccessRequestActions from "./AccessRequestActions";
|
|
|
|
const CommentEditor = lazyWithRetry(
|
|
() => import("~/scenes/Document/components/Comments/CommentEditor")
|
|
);
|
|
|
|
type Props = {
|
|
notification: Notification;
|
|
onNavigate: () => void;
|
|
};
|
|
|
|
function NotificationListItem({ notification, onNavigate }: Props) {
|
|
const { t } = useTranslation();
|
|
const { collections } = useStores();
|
|
const collectionId = notification.document?.collectionId;
|
|
const collection = collectionId ? collections.get(collectionId) : undefined;
|
|
|
|
const isAccessRequestPending =
|
|
notification.event === NotificationEventType.RequestDocumentAccess &&
|
|
notification.accessRequestStatus === "pending";
|
|
|
|
const handleClick: React.MouseEventHandler<HTMLAnchorElement> = (event) => {
|
|
if (event.altKey) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
void notification.toggleRead();
|
|
return;
|
|
}
|
|
|
|
void notification.markAsRead();
|
|
|
|
onNavigate();
|
|
};
|
|
|
|
const menuAction = React.useMemo(
|
|
() =>
|
|
createActionWithChildren({
|
|
name: ({ t }) => t("Notification options"),
|
|
section: NotificationSection,
|
|
children: [
|
|
notificationMarkRead(notification),
|
|
notificationMarkUnread(notification),
|
|
notificationArchive(notification),
|
|
],
|
|
}),
|
|
[notification]
|
|
);
|
|
|
|
return (
|
|
<ContextMenu action={menuAction} ariaLabel={t("Notification options")}>
|
|
<StyledLink to={notification.path ?? ""} onClick={handleClick}>
|
|
<Container gap={8} $unread={!notification.viewedAt}>
|
|
<StyledAvatar model={notification.actor} />
|
|
<Flex column>
|
|
<Text as="div" size="small">
|
|
<Text weight="bold">
|
|
{notification.actor?.name ?? t("Unknown")}
|
|
</Text>{" "}
|
|
{notification.eventText(t)}{" "}
|
|
<Text weight="bold">{notification.subject}</Text>
|
|
</Text>
|
|
<Text type="tertiary" size="xsmall">
|
|
<Time dateTime={notification.createdAt} addSuffix />{" "}
|
|
{collection && <>· {collection.name}</>}
|
|
</Text>
|
|
{notification.comment && (
|
|
<StyledCommentEditor
|
|
defaultValue={toJS(notification.comment.data)}
|
|
/>
|
|
)}
|
|
{isAccessRequestPending && (
|
|
<AccessRequestActions notification={notification} />
|
|
)}
|
|
</Flex>
|
|
{notification.viewedAt ? null : <UnreadBadge />}
|
|
</Container>
|
|
</StyledLink>
|
|
</ContextMenu>
|
|
);
|
|
}
|
|
|
|
const StyledLink = styled(Link)`
|
|
display: block;
|
|
margin: 0 8px;
|
|
cursor: var(--pointer);
|
|
`;
|
|
|
|
const StyledCommentEditor = styled(CommentEditor)`
|
|
font-size: 0.9em;
|
|
margin-top: 4px;
|
|
pointer-events: none;
|
|
|
|
${truncateMultiline(3)}
|
|
`;
|
|
|
|
const StyledAvatar = styled(Avatar).attrs({
|
|
variant: AvatarVariant.Round,
|
|
size: AvatarSize.Medium,
|
|
})`
|
|
margin-top: 4px;
|
|
`;
|
|
|
|
const Container = styled(Flex)<{ $unread: boolean }>`
|
|
position: relative;
|
|
padding-block: 8px;
|
|
padding-inline: 12px 40px;
|
|
border-radius: 4px;
|
|
|
|
${StyledLink}[data-state=open] &,
|
|
&:has([data-state="open"]),
|
|
&:${hover},
|
|
&:active {
|
|
background: ${s("listItemHoverBackground")};
|
|
}
|
|
`;
|
|
|
|
export default observer(NotificationListItem);
|