From 2c2efe57dbfdf3b60b4ebcd31fb5fd76f0e68439 Mon Sep 17 00:00:00 2001 From: Salihu Date: Fri, 9 Jan 2026 18:53:21 +0100 Subject: [PATCH] track access requests --- .../Notifications/NotificationListItem.tsx | 53 ++-- app/models/Notification.ts | 7 + app/scenes/Errors/Error403.tsx | 35 ++- .../20260107213946-create-access-requests.js | 83 +++++++ ...000-add-access-request-to-notifications.js | 24 ++ server/models/AccessRequest.ts | 129 ++++++++++ server/models/Notification.ts | 9 + server/models/index.ts | 2 + server/policies/accessRequest.ts | 7 + server/policies/index.ts | 1 + server/presenters/accessRequests.ts | 20 ++ server/presenters/index.ts | 2 + server/presenters/notification.ts | 1 + .../DocumentAccessRequestNotificationsTask.ts | 15 +- .../api/accessRequests/accessRequests.test.ts | 233 ++++++++++++++++++ .../api/accessRequests/accessRequests.ts | 172 +++++++++++++ server/routes/api/accessRequests/index.ts | 1 + server/routes/api/accessRequests/schema.ts | 34 +++ server/routes/api/documents/schema.ts | 18 ++ server/routes/api/index.ts | 2 + shared/i18n/locales/en_US/translation.json | 3 + 21 files changed, 829 insertions(+), 22 deletions(-) create mode 100644 server/migrations/20260107213946-create-access-requests.js create mode 100644 server/migrations/20260107220000-add-access-request-to-notifications.js create mode 100644 server/models/AccessRequest.ts create mode 100644 server/policies/accessRequest.ts create mode 100644 server/presenters/accessRequests.ts create mode 100644 server/routes/api/accessRequests/accessRequests.test.ts create mode 100644 server/routes/api/accessRequests/accessRequests.ts create mode 100644 server/routes/api/accessRequests/index.ts create mode 100644 server/routes/api/accessRequests/schema.ts diff --git a/app/components/Notifications/NotificationListItem.tsx b/app/components/Notifications/NotificationListItem.tsx index 0faaa5fbba..80947f1e53 100644 --- a/app/components/Notifications/NotificationListItem.tsx +++ b/app/components/Notifications/NotificationListItem.tsx @@ -18,6 +18,7 @@ import Time from "../Time"; import { UnreadBadge } from "../UnreadBadge"; import { Permission } from "~/types"; import lazyWithRetry from "~/utils/lazyWithRetry"; +import { client } from "~/utils/ApiClient"; const CommentEditor = lazyWithRetry( () => import("~/scenes/Document/components/CommentEditor") @@ -30,7 +31,7 @@ type Props = { function NotificationListItem({ notification, onNavigate }: Props) { const { t } = useTranslation(); - const { collections, userMemberships } = useStores(); + const { collections } = useStores(); const collectionId = notification.document?.collectionId; const collection = collectionId ? collections.get(collectionId) : undefined; const [processing, setProcessing] = React.useState(false); @@ -76,13 +77,19 @@ function NotificationListItem({ notification, onNavigate }: Props) { event.preventDefault(); event.stopPropagation(); - if (!collection || !notification.actor || processing) {return;} + if ( + !collection || + !notification.actor || + processing || + !notification.accessRequestId + ) { + return; + } setProcessing(true); try { - await userMemberships.create({ - documentId: notification.documentId, - userId: notification.actor?.id, + await client.post("/access_requests.approve", { + id: notification.accessRequestId, permission: selectedPermission, }); toast.success( @@ -97,14 +104,32 @@ function NotificationListItem({ notification, onNavigate }: Props) { setProcessing(false); } }, - [ - notification, - processing, - selectedPermission, - t, - userMemberships, - collection, - ] + [notification, processing, selectedPermission, t, collection] + ); + + const handleDismiss = React.useCallback( + async (event: React.MouseEvent) => { + event.preventDefault(); + event.stopPropagation(); + + if (!notification.accessRequestId || processing) { + return; + } + + setProcessing(true); + try { + await client.post("/access_requests.dismiss", { + id: notification.accessRequestId, + }); + toast.success(t("Access request dismissed")); + void notification.markAsRead(); + } catch { + toast.error(t("Failed to dismiss access request")); + } finally { + setProcessing(false); + } + }, + [notification, processing, t] ); return ( @@ -148,7 +173,7 @@ function NotificationListItem({ notification, onNavigate }: Props) { {t("Approve")}