Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: updates to pause

Marc Seitzfd88a0ba79da
diff --git a/app/api/views-dataroom/route.ts b/app/api/views-dataroom/route.ts
index efc6e04c..6a01bdff 100644
--- a/app/api/views-dataroom/route.ts
+++ b/app/api/views-dataroom/route.ts
@@ -684,7 +684,7 @@ export async function POST(request: NextRequest) {
}),
);
- if (link.teamId && !isPreview && !isPaused) {
+ if (link.teamId && !isPreview) {
waitUntil(
(async () => {
try {
@@ -694,6 +694,7 @@ export async function POST(request: NextRequest) {
linkId,
viewerEmail: verifiedEmail ?? email,
viewerId: viewer?.id,
+ teamIsPaused: isPaused,
});
} catch (error) {
console.error("Error sending Slack notification:", error);
@@ -816,7 +817,7 @@ export async function POST(request: NextRequest) {
});
console.timeEnd("create-view");
// Only send Slack notifications for non-preview views
- if (link.teamId && !isPreview && !isPaused) {
+ if (link.teamId && !isPreview) {
waitUntil(
(async () => {
try {
@@ -827,6 +828,7 @@ export async function POST(request: NextRequest) {
linkId,
viewerEmail: verifiedEmail ?? email,
viewerId: viewer?.id,
+ teamIsPaused: isPaused,
});
} catch (error) {
console.error("Error sending Slack notification:", error);
diff --git a/app/api/views/route.ts b/app/api/views/route.ts
index d8c76418..66212e28 100644
--- a/app/api/views/route.ts
+++ b/app/api/views/route.ts
@@ -658,7 +658,7 @@ export async function POST(request: NextRequest) {
isPaused,
}),
);
- if (!isPreview && !isPaused) {
+ if (!isPreview) {
waitUntil(
notifyDocumentView({
teamId: link.teamId!,
@@ -666,6 +666,7 @@ export async function POST(request: NextRequest) {
linkId,
viewerEmail: email ?? undefined,
viewerId: viewer?.id ?? undefined,
+ teamIsPaused: isPaused,
}).catch((error) => {
console.error("Error sending Slack notification:", error);
}),
diff --git a/components/billing/upgrade-plan-container.tsx b/components/billing/upgrade-plan-container.tsx
index ec916bb4..1a8e0be7 100644
--- a/components/billing/upgrade-plan-container.tsx
+++ b/components/billing/upgrade-plan-container.tsx
@@ -206,24 +206,6 @@ export default function UpgradePlanContainer() {
useModal={false}
onClick={() => router.push("/settings/upgrade")}
/>
- {isCustomer && (
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button variant="outline" size="sm" className="h-9 w-9 p-0">
- <MoreVertical className="h-4 w-4" />
- <span className="sr-only">More options</span>
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <DropdownMenuItem
- onClick={() => manageSubscription({ type: "invoices" })}
- >
- <ReceiptTextIcon className="h-4 w-4" />
- View invoices
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- )}
</div>
);
} else if (isCancelled) {
@@ -293,12 +275,6 @@ export default function UpgradePlanContainer() {
<CreditCardIcon className="h-4 w-4" />
Change billing information
</DropdownMenuItem>
- <DropdownMenuItem
- onClick={() => router.push("/settings/billing/invoices")}
- >
- <ReceiptTextIcon className="h-4 w-4" />
- View invoices
- </DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</>
diff --git a/components/documents/add-document-modal.tsx b/components/documents/add-document-modal.tsx
index b1215d64..4d2ba1bd 100644
--- a/components/documents/add-document-modal.tsx
+++ b/components/documents/add-document-modal.tsx
@@ -84,7 +84,7 @@ export function AddDocumentModal({
>([]);
const teamInfo = useTeam();
const { canAddDocuments } = useLimits();
- const { plan, isFree, isTrial } = usePlan();
+ const { plan, isFree, isTrial, isPaused } = usePlan();
const { dataroom } = useDataroom();
const teamId = teamInfo?.currentTeam?.id as string;
@@ -206,6 +206,20 @@ export function AddDocumentModal({
): Promise<void> => {
event.preventDefault();
+ // Check if team is paused
+ if (isPaused) {
+ toast.error(
+ "Your subscription is paused. Resume your subscription to upload documents.",
+ {
+ action: {
+ label: "Go to Billing",
+ onClick: () => router.push("/settings/billing"),
+ },
+ },
+ );
+ return;
+ }
+
// Check if the file is chosen
if (!currentFile) {
toast.error("Please select a file to upload.");
@@ -384,6 +398,20 @@ export function AddDocumentModal({
): Promise<void> => {
event.preventDefault();
+ // Check if team is paused
+ if (isPaused) {
+ toast.error(
+ "Your subscription is paused. Resume your subscription to upload documents.",
+ {
+ action: {
+ label: "Go to Billing",
+ onClick: () => router.push("/settings/billing"),
+ },
+ },
+ );
+ return;
+ }
+
if (!canAddDocuments) {
toast.error("You have reached the maximum number of documents.");
return;
diff --git a/components/links/links-visitors.tsx b/components/links/links-visitors.tsx
index 1cdc5680..0dd34b94 100644
--- a/components/links/links-visitors.tsx
+++ b/components/links/links-visitors.tsx
@@ -1,11 +1,14 @@
+import { AlertTriangleIcon } from "lucide-react";
+
+import { usePlan } from "@/lib/swr/use-billing";
+import { useLinkVisits } from "@/lib/swr/use-link";
+import { durationFormat, timeAgo } from "@/lib/utils";
+
import { Gauge } from "@/components/ui/gauge";
import { Skeleton } from "@/components/ui/skeleton";
import { TableCell, TableRow } from "@/components/ui/table";
import { VisitorAvatar } from "@/components/visitors/visitor-avatar";
-import { useLinkVisits } from "@/lib/swr/use-link";
-import { durationFormat, timeAgo } from "@/lib/utils";
-
export default function LinksVisitors({
linkId,
linkName,
@@ -13,10 +16,32 @@ export default function LinksVisitors({
linkId: string;
linkName: string;
}) {
- const { views } = useLinkVisits(linkId);
+ const { views, hiddenFromPause } = useLinkVisits(linkId);
+ const { isPaused } = usePlan();
return (
<>
+ {views && isPaused && hiddenFromPause > 0 && (
+ <TableRow>
+ <TableCell colSpan={5} className="text-left sm:text-center">
+ <div className="flex flex-col items-start justify-center gap-2 sm:flex-row sm:items-center">
+ <span className="flex items-center gap-x-1">
+ <AlertTriangleIcon className="inline-block h-4 w-4 text-orange-500" />
+ {hiddenFromPause} visit
+ {hiddenFromPause !== 1 ? "s" : ""} occurred while your
+ subscription was paused and{" "}
+ {hiddenFromPause !== 1 ? "are" : "is"} hidden.
+ </span>
+ <a
+ href="/settings/billing"
+ className="font-medium text-orange-600 underline hover:text-orange-700"
+ >
+ Unpause subscription to see all visits
+ </a>
+ </div>
+ </TableCell>
+ </TableRow>
+ )}
{views ? (
views.map((view) => (
<TableRow key={view.id}>
diff --git a/components/sidebar/app-sidebar.tsx b/components/sidebar/app-sidebar.tsx
index 737d5d36..5b25987f 100644
--- a/components/sidebar/app-sidebar.tsx
+++ b/components/sidebar/app-sidebar.tsx
@@ -16,9 +16,10 @@ import {
FolderIcon,
HouseIcon,
Loader,
+ PauseCircleIcon,
ServerIcon,
- WorkflowIcon,
Sparkles as SparklesIcon,
+ WorkflowIcon,
} from "lucide-react";
import { useFeatureFlags } from "@/lib/hooks/use-feature-flags";
@@ -43,6 +44,7 @@ import {
import ProAnnualBanner from "../billing/pro-annual-banner";
import ProBanner from "../billing/pro-banner";
import { Progress } from "../ui/progress";
+import { BadgeTooltip } from "../ui/tooltip";
import SlackBanner from "./banners/slack-banner";
export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
@@ -64,6 +66,7 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
isDataroomsPremium,
isFree,
isTrial,
+ isPaused,
} = usePlan();
const { limits } = useLimits();
@@ -248,18 +251,33 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
<p className="ml-2 flex items-center text-2xl font-bold tracking-tighter text-black group-data-[collapsible=icon]:hidden dark:text-white">
<Link href="/dashboard">Papermark</Link>
{userPlan && !isFree && !isDataroomsPlus && !isDataroomsPremium ? (
- <span className="ml-4 rounded-full bg-background px-2.5 py-1 text-xs tracking-normal text-foreground ring-1 ring-gray-800">
+ <span className="relative ml-4 inline-flex items-center rounded-full bg-background px-2.5 py-1 text-xs tracking-normal text-foreground ring-1 ring-gray-800">
{userPlan.charAt(0).toUpperCase() + userPlan.slice(1)}
+ {isPaused ? (
+ <BadgeTooltip content="Subscription paused">
+ <PauseCircleIcon className="absolute -right-1.5 -top-1.5 h-5 w-5 rounded-full bg-background text-amber-500" />
+ </BadgeTooltip>
+ ) : null}
</span>
) : null}
{isDataroomsPlus ? (
- <span className="ml-4 rounded-full bg-background px-2.5 py-1 text-xs tracking-normal text-foreground ring-1 ring-gray-800">
+ <span className="relative ml-4 inline-flex items-center rounded-full bg-background px-2.5 py-1 text-xs tracking-normal text-foreground ring-1 ring-gray-800">
Datarooms+
+ {isPaused ? (
+ <BadgeTooltip content="Subscription paused">
+ <PauseCircleIcon className="absolute -right-1.5 -top-1.5 h-5 w-5 rounded-full bg-background text-amber-500" />
+ </BadgeTooltip>
+ ) : null}
</span>
) : null}
{isDataroomsPremium ? (
- <span className="ml-4 rounded-full bg-background px-2.5 py-1 text-xs tracking-normal text-foreground ring-1 ring-gray-800">
+ <span className="relative ml-4 inline-flex items-center rounded-full bg-background px-2.5 py-1 text-xs tracking-normal text-foreground ring-1 ring-gray-800">
Premium
+ {isPaused ? (
+ <BadgeTooltip content="Subscription paused">
+ <PauseCircleIcon className="absolute -right-1.5 -top-1.5 h-5 w-5 rounded-full bg-background text-amber-500" />
+ </BadgeTooltip>
+ ) : null}
</span>
) : null}
{isTrial ? (
diff --git a/components/upload-zone.tsx b/components/upload-zone.tsx
index 2f0f1bb0..777c3350 100644
--- a/components/upload-zone.tsx
+++ b/components/upload-zone.tsx
@@ -99,7 +99,7 @@ export default function UploadZone({
const router = useRouter();
const teamInfo = useTeam();
const { data: session } = useSession();
- const { limits, canAddDocuments } = useLimits();
+ const { limits, canAddDocuments, isPaused } = useLimits();
const remainingDocuments = limits?.documents
? limits?.documents - limits?.usage?.documents
: 0;
@@ -242,6 +242,20 @@ export default function UploadZone({
const onDrop = useCallback(
async (acceptedFiles: FileWithPaths[]) => {
+ // Check if team is paused
+ if (isPaused) {
+ toast.error(
+ "Your subscription is paused. Resume your subscription to upload documents.",
+ {
+ action: {
+ label: "Go to Billing",
+ onClick: () => router.push("/settings/billing"),
+ },
+ },
+ );
+ return;
+ }
+
if (!canAddDocuments && acceptedFiles.length > remainingDocuments) {
toast.error("You have reached the maximum number of documents.");
return;
@@ -515,6 +529,7 @@ export default function UploadZone({
fileSizeLimits,
isFree,
isTrial,
+ isPaused,
],
);
diff --git a/lib/team/is-team-paused.ts b/ee/features/billing/cancellation/lib/is-team-paused.ts
similarity index 100%
rename from lib/team/is-team-paused.ts
rename to ee/features/billing/cancellation/lib/is-team-paused.ts
diff --git a/ee/limits/swr-handler.ts b/ee/limits/swr-handler.ts
index 60a16d6e..2b0e11ad 100644
--- a/ee/limits/swr-handler.ts
+++ b/ee/limits/swr-handler.ts
@@ -18,7 +18,7 @@ export type LimitProps = z.infer<typeof configSchema> & {
export function useLimits() {
const teamInfo = useTeam();
- const { isFree, isTrial } = usePlan();
+ const { isFree, isTrial, isPaused } = usePlan();
const teamId = teamInfo?.currentTeam?.id;
const { data, error } = useSWR<LimitProps | null>(
@@ -43,6 +43,7 @@ export function useLimits() {
canAddDocuments,
canAddLinks,
canAddUsers,
+ isPaused,
error,
loading: !data && !error,
};
diff --git a/lib/api/views/send-webhook-event.ts b/lib/api/views/send-webhook-event.ts
index 832ea6cd..1843037e 100644
--- a/lib/api/views/send-webhook-event.ts
+++ b/lib/api/views/send-webhook-event.ts
@@ -1,5 +1,6 @@
+import { isTeamPausedById } from "@/ee/features/billing/cancellation/lib/is-team-paused";
+
import prisma from "@/lib/prisma";
-import { isTeamPausedById } from "@/lib/team/is-team-paused";
import { log } from "@/lib/utils";
import { sendWebhooks } from "@/lib/webhook/send-webhooks";
diff --git a/lib/integrations/slack/templates.ts b/lib/integrations/slack/templates.ts
index eb2231ef..59d365c3 100644
--- a/lib/integrations/slack/templates.ts
+++ b/lib/integrations/slack/templates.ts
@@ -20,6 +20,21 @@ export async function createSlackMessage(
eventData: SlackEventData,
): Promise<SlackMessage | null> {
try {
+ // If team is paused, return paused message templates
+ if (eventData.teamIsPaused) {
+ switch (eventData.eventType) {
+ case "document_view":
+ return await createDocumentViewPausedMessage(eventData);
+ case "dataroom_access":
+ return await createDataroomAccessPausedMessage(eventData);
+ case "document_download":
+ // Downloads are blocked when paused, so no message needed
+ return null;
+ default:
+ return null;
+ }
+ }
+
switch (eventData.eventType) {
case "document_view":
return await createDocumentViewMessage(eventData);
@@ -350,6 +365,158 @@ async function createDocumentDownloadMessage(
};
}
+/**
+ * Document View Paused Message Template
+ */
+async function createDocumentViewPausedMessage(
+ eventData: SlackEventData,
+): Promise<SlackMessage> {
+ const document = eventData.documentId
+ ? await getDocumentInfo(eventData.documentId)
+ : null;
+ const link = eventData.linkId ? await getLinkInfo(eventData.linkId) : null;
+
+ return {
+ text: `Your document has been viewed: ${document?.name || "Unknown document"} by someone`,
+ blocks: [
+ {
+ type: "header",
+ text: {
+ type: "plain_text",
+ text: "New Document Visitor",
+ emoji: false,
+ },
+ },
+ {
+ type: "section",
+ fields: [
+ {
+ type: "mrkdwn",
+ text: `*Document:*\n${document?.name || "Unknown"}`,
+ },
+ {
+ type: "mrkdwn",
+ text: `*Viewer:*\nSomeone`,
+ },
+ ],
+ },
+ {
+ type: "section",
+ fields: [
+ {
+ type: "mrkdwn",
+ text: link?.name
+ ? `*Shared Link:*\n${link.name}`
+ : `*Access:*\nDirect access`,
+ },
+ {
+ type: "mrkdwn",
+ text: `*Time:*\n${new Date().toLocaleString()}`,
+ },
+ ],
+ },
+ {
+ type: "section",
+ text: {
+ type: "mrkdwn",
+ text: "⏸️ Your team is currently paused, so detailed visitor information is not available. To see who visited your documents and access full analytics, please unpause your subscription.",
+ },
+ },
+ {
+ type: "actions",
+ elements: [
+ {
+ type: "button",
+ text: {
+ type: "plain_text",
+ text: "Manage Subscription",
+ emoji: true,
+ },
+ style: "primary",
+ url: `${process.env.NEXTAUTH_URL}/settings/billing`,
+ },
+ ],
+ },
+ ],
+ };
+}
+
+/**
+ * Dataroom Access Paused Message Template
+ */
+async function createDataroomAccessPausedMessage(
+ eventData: SlackEventData,
+): Promise<SlackMessage> {
+ const dataroom = eventData.dataroomId
+ ? await getDataroomInfo(eventData.dataroomId)
+ : null;
+ const link = eventData.linkId ? await getLinkInfo(eventData.linkId) : null;
+
+ return {
+ text: `Your dataroom has been viewed: ${dataroom?.name || "Unknown dataroom"} by someone`,
+ blocks: [
+ {
+ type: "header",
+ text: {
+ type: "plain_text",
+ text: "New Dataroom Visitor",
+ emoji: false,
+ },
+ },
+ {
+ type: "section",
+ fields: [
+ {
+ type: "mrkdwn",
+ text: `*Dataroom:*\n${dataroom?.name || "Unknown"}`,
+ },
+ {
+ type: "mrkdwn",
+ text: `*Viewer:*\nSomeone`,
+ },
+ ],
+ },
+ {
+ type: "section",
+ fields: [
+ {
+ type: "mrkdwn",
+ text: link?.name
+ ? `*Shared Link:*\n${link.name}`
+ : `*Access:*\nDirect access`,
+ },
+ {
+ type: "mrkdwn",
+ text: `*Time:*\n${new Date().toLocaleString()}`,
+ },
+ ],
+ },
+ {
+ type: "section",
+ text: {
+ type: "mrkdwn",
+ text: "⏸️ Your team is currently paused, so detailed visitor information is not available. To see who visited your dataroom and access full analytics, please unpause your subscription.",
+ },
+ },
+ {
+ type: "actions",
+ elements: [
+ {
+ type: "button",
+ text: {
+ type: "plain_text",
+ text: "Manage Subscription",
+ emoji: true,
+ },
+ style: "primary",
+ url: `${process.env.NEXTAUTH_URL}/settings/billing`,
+ },
+ ],
+ },
+ ],
+ };
+}
+
// Helper functions
async function getDocumentInfo(documentId: string) {
try {
diff --git a/lib/integrations/slack/types.ts b/lib/integrations/slack/types.ts
index e484389e..b29bee4a 100644
--- a/lib/integrations/slack/types.ts
+++ b/lib/integrations/slack/types.ts
@@ -63,6 +63,7 @@ export interface SlackEventData {
viewerId?: string;
userId?: string;
metadata?: Record<string, any>;
+ teamIsPaused?: boolean;
}
export type SlackNotificationType =
diff --git a/lib/swr/use-link.ts b/lib/swr/use-link.ts
index 1f3ed5c0..143ef6f9 100644
--- a/lib/swr/use-link.ts
+++ b/lib/swr/use-link.ts
@@ -1,5 +1,6 @@
import { useRouter } from "next/router";
+import { useTeam } from "@/context/team-context";
import { View } from "@prisma/client";
import useSWR from "swr";
@@ -65,9 +66,18 @@ interface ViewWithDuration extends View {
completionRate: number;
}
+interface LinkVisitsResponse {
+ views: ViewWithDuration[];
+ hiddenFromPause: number;
+}
+
export function useLinkVisits(linkId: string) {
- const { data: views, error } = useSWR<ViewWithDuration[]>(
- linkId && `/api/links/${encodeURIComponent(linkId)}/visits`,
+ const teamInfo = useTeam();
+ const teamId = teamInfo?.currentTeam?.id;
+ const { data, error } = useSWR<LinkVisitsResponse>(
+ linkId &&
+ teamId &&
+ `/api/teams/${teamId}/links/${encodeURIComponent(linkId)}/visits`,
fetcher,
{
dedupingInterval: 10000,
@@ -75,8 +85,9 @@ export function useLinkVisits(linkId: string) {
);
return {
- views,
- loading: !error && !views,
+ views: data?.views,
+ hiddenFromPause: data?.hiddenFromPause ?? 0,
+ loading: !error && !data,
error,
};
}
diff --git a/lib/trigger/export-visits.ts b/lib/trigger/export-visits.ts
index 0afb4a97..d9109b82 100644
--- a/lib/trigger/export-visits.ts
+++ b/lib/trigger/export-visits.ts
@@ -180,6 +180,18 @@ export const exportVisitsTask = task({
},
});
+// Helper function to check if a view occurred during a pause period
+function isViewDuringPause(
+ viewedAt: Date,
+ pauseStartsAt: Date | null,
+ pauseEndsAt: Date | null,
+): boolean {
+ if (!pauseStartsAt || !pauseEndsAt) {
+ return false;
+ }
+ return viewedAt >= pauseStartsAt && viewedAt <= pauseEndsAt;
+}
+
async function exportDocumentVisits(
docId: string,
teamId: string,
@@ -187,7 +199,7 @@ async function exportDocumentVisits(
csvData: string;
resourceName: string;
}> {
- // Fetch Document
+ // Fetch Document with team pause information
const document = await prisma.document.findUnique({
where: { id: docId, teamId: teamId },
select: {
@@ -205,6 +217,8 @@ async function exportDocumentVisits(
team: {
select: {
plan: true,
+ pauseStartsAt: true,
+ pauseEndsAt: true,
},
},
},
@@ -214,8 +228,10 @@ async function exportDocumentVisits(
throw new Error("Document not found");
}
+ const { pauseStartsAt, pauseEndsAt } = document.team;
+
// Fetch views
- const views = await prisma.view.findMany({
+ const allViews = await prisma.view.findMany({
where: { documentId: docId },
include: {
link: { select: { name: true } },
@@ -240,6 +256,11 @@ async function exportDocumentVisits(
},
});
+ // Filter out views that occurred during the pause period
+ const views = allViews.filter(
+ (view) => !isViewDuringPause(view.viewedAt, pauseStartsAt, pauseEndsAt),
+ );
+
if (!views || views.length === 0) {
throw new Error("Document has no views");
}
@@ -477,7 +498,7 @@ async function exportDataroomVisits(
csvData: string;
resourceName: string;
}> {
- // Fetch Dataroom
+ // Fetch Dataroom with team pause information
const dataroom = await prisma.dataroom.findUnique({
where: { id: dataroomId, teamId: teamId },
select: {
@@ -502,6 +523,12 @@ async function exportDataroomVisits(
},
},
},
+ team: {
+ select: {
+ pauseStartsAt: true,
+ pauseEndsAt: true,
+ },
+ },
},
});
@@ -509,8 +536,10 @@ async function exportDataroomVisits(
throw new Error("Dataroom not found");
}
+ const { pauseStartsAt, pauseEndsAt } = dataroom.team;
+
// Fetch views
- const views = await prisma.view.findMany({
+ const allViews = await prisma.view.findMany({
where: {
dataroomId: dataroomId,
...(groupId && { groupId }),
@@ -553,6 +582,11 @@ async function exportDataroomVisits(
},
});
+ // Filter out views that occurred during the pause period
+ const views = allViews.filter(
+ (view) => !isViewDuringPause(view.viewedAt, pauseStartsAt, pauseEndsAt),
+ );
+
if (!views || views.length === 0) {
throw new Error("Dataroom has no views");
}
diff --git a/lib/webhook/triggers/document-created.ts b/lib/webhook/triggers/document-created.ts
index 3e54580a..5e9d18db 100644
--- a/lib/webhook/triggers/document-created.ts
+++ b/lib/webhook/triggers/document-created.ts
@@ -1,5 +1,6 @@
+import { isTeamPausedById } from "@/ee/features/billing/cancellation/lib/is-team-paused";
+
import prisma from "@/lib/prisma";
-import { isTeamPausedById } from "@/lib/team/is-team-paused";
import { log } from "@/lib/utils";
import { sendWebhooks } from "@/lib/webhook/send-webhooks";
diff --git a/lib/webhook/triggers/link-created.ts b/lib/webhook/triggers/link-created.ts
index cea2527c..4eaaeee3 100644
--- a/lib/webhook/triggers/link-created.ts
+++ b/lib/webhook/triggers/link-created.ts
@@ -1,5 +1,6 @@
+import { isTeamPausedById } from "@/ee/features/billing/cancellation/lib/is-team-paused";
+
import prisma from "@/lib/prisma";
-import { isTeamPausedById } from "@/lib/team/is-team-paused";
import { log } from "@/lib/utils";
import { sendWebhooks } from "@/lib/webhook/send-webhooks";
diff --git a/pages/api/jobs/send-notification.ts b/pages/api/jobs/send-notification.ts
index f467d6c0..5f5a3ed5 100644
--- a/pages/api/jobs/send-notification.ts
+++ b/pages/api/jobs/send-notification.ts
@@ -1,11 +1,12 @@
import { NextApiRequest, NextApiResponse } from "next";
+import { isTeamPausedById } from "@/ee/features/billing/cancellation/lib/is-team-paused";
+
import { sendViewedDataroomEmail } from "@/lib/emails/send-viewed-dataroom";
import { sendViewedDataroomPausedEmail } from "@/lib/emails/send-viewed-dataroom-paused";
import { sendViewedDocumentEmail } from "@/lib/emails/send-viewed-document";
import { sendViewedDocumentPausedEmail } from "@/lib/emails/send-viewed-document-paused";
import prisma from "@/lib/prisma";
-import { isTeamPausedById } from "@/lib/team/is-team-paused";
import { log } from "@/lib/utils";
export const config = {
diff --git a/pages/api/links/[id]/duplicate.ts b/pages/api/links/[id]/duplicate.ts
index a4064aeb..44ad48bc 100644
--- a/pages/api/links/[id]/duplicate.ts
+++ b/pages/api/links/[id]/duplicate.ts
@@ -1,5 +1,6 @@
import { NextApiRequest, NextApiResponse } from "next";
+import { isTeamPausedById } from "@/ee/features/billing/cancellation/lib/is-team-paused";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { Prisma } from "@prisma/client";
import { waitUntil } from "@vercel/functions";
@@ -44,6 +45,15 @@ export default async function handle(
return res.status(401).end("Unauthorized");
}
+ // Check if team is paused
+ const teamIsPaused = await isTeamPausedById(teamId);
+ if (teamIsPaused) {
+ return res.status(403).json({
+ error:
+ "Team is currently paused. New link creation is not available.",
+ });
+ }
+
const link = await prisma.link.findUnique({
where: { id, teamId },
include: {
diff --git a/pages/api/links/index.ts b/pages/api/links/index.ts
index 5b4c7217..20c3310e 100644
--- a/pages/api/links/index.ts
+++ b/pages/api/links/index.ts
@@ -1,12 +1,12 @@
import { NextApiRequest, NextApiResponse } from "next";
+import { isTeamPausedById } from "@/ee/features/billing/cancellation/lib/is-team-paused";
import { LinkAudienceType, Tag } from "@prisma/client";
import { waitUntil } from "@vercel/functions";
import { getServerSession } from "next-auth/next";
import { errorhandler } from "@/lib/errorHandler";
import prisma from "@/lib/prisma";
-import { isTeamPausedById } from "@/lib/team/is-team-paused";
import { CustomUser, WatermarkConfigSchema } from "@/lib/types";
import {
decryptEncrpytedPassword,
diff --git a/pages/api/teams/[teamId]/billing/plan.ts b/pages/api/teams/[teamId]/billing/plan.ts
index 140e8acd..50f217dc 100644
--- a/pages/api/teams/[teamId]/billing/plan.ts
+++ b/pages/api/teams/[teamId]/billing/plan.ts
@@ -1,5 +1,6 @@
import { NextApiRequest, NextApiResponse } from "next";
+import { isTeamPaused } from "@/ee/features/billing/cancellation/lib/is-team-paused";
import getSubscriptionItem, {
SubscriptionDiscount,
} from "@/ee/stripe/functions/get-subscription-item";
@@ -8,7 +9,6 @@ import { getServerSession } from "next-auth/next";
import { errorhandler } from "@/lib/errorHandler";
import prisma from "@/lib/prisma";
-import { isTeamPaused } from "@/lib/team/is-team-paused";
import { CustomUser } from "@/lib/types";
import { authOptions } from "../../../auth/[...nextauth]";
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/documents/index.ts b/pages/api/teams/[teamId]/datarooms/[id]/documents/index.ts
index e25b8ddd..70f13952 100644
--- a/pages/api/teams/[teamId]/datarooms/[id]/documents/index.ts
+++ b/pages/api/teams/[teamId]/datarooms/[id]/documents/index.ts
@@ -1,5 +1,6 @@
import { NextApiRequest, NextApiResponse } from "next";
+import { isTeamPausedById } from "@/ee/features/billing/cancellation/lib/is-team-paused";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { runs } from "@trigger.dev/sdk/v3";
import { waitUntil } from "@vercel/functions";
@@ -133,12 +134,24 @@ export default async function handle(
},
},
},
+ select: {
+ id: true,
+ },
});
if (!team) {
return res.status(401).end("Unauthorized");
}
+ // Check if team is paused
+ const teamIsPaused = await isTeamPausedById(teamId);
+ if (teamIsPaused) {
+ return res.status(403).json({
+ error:
+ "Team is currently paused. Adding documents to dataroom is not available.",
+ });
+ }
+
const folder = await prisma.dataroomFolder.findUnique({
where: {
dataroomId_path: {
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/duplicate.ts b/pages/api/teams/[teamId]/datarooms/[id]/duplicate.ts
index 2be7cec7..20672463 100644
--- a/pages/api/teams/[teamId]/datarooms/[id]/duplicate.ts
+++ b/pages/api/teams/[teamId]/datarooms/[id]/duplicate.ts
@@ -1,5 +1,6 @@
import { NextApiRequest, NextApiResponse } from "next";
+import { isTeamPausedById } from "@/ee/features/billing/cancellation/lib/is-team-paused";
import { getLimits } from "@/ee/limits/server";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import {
@@ -175,6 +176,15 @@ export default async function handle(
});
}
+ // Check if team is paused
+ const teamIsPaused = await isTeamPausedById(teamId);
+ if (teamIsPaused) {
+ return res.status(403).json({
+ error:
+ "Team is currently paused. Duplicating dataroom is not available.",
+ });
+ }
+
const dataroom = await prisma.dataroom.findUnique({
where: {
id: dataroomId,
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/groups/index.ts b/pages/api/teams/[teamId]/datarooms/[id]/groups/index.ts
index a7b7306b..4c875bd6 100644
--- a/pages/api/teams/[teamId]/datarooms/[id]/groups/index.ts
+++ b/pages/api/teams/[teamId]/datarooms/[id]/groups/index.ts
@@ -1,5 +1,6 @@
import { NextApiRequest, NextApiResponse } from "next";
+import { isTeamPausedById } from "@/ee/features/billing/cancellation/lib/is-team-paused";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { ItemType } from "@prisma/client";
import { getServerSession } from "next-auth/next";
@@ -162,6 +163,14 @@ export default async function handle(
return res.status(401).end("Unauthorized");
}
+ // Check if team is paused
+ const teamIsPaused = await isTeamPausedById(teamId);
+ if (teamIsPaused) {
+ return res.status(403).json({
+ error: "Team is currently paused. Creating groups is not available.",
+ });
+ }
+
const group = await prisma.viewerGroup.create({
data: {
name: name,
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/stats.ts b/pages/api/teams/[teamId]/datarooms/[id]/stats.ts
index eb404b37..c6ca97f0 100644
--- a/pages/api/teams/[teamId]/datarooms/[id]/stats.ts
+++ b/pages/api/teams/[teamId]/datarooms/[id]/stats.ts
@@ -10,6 +10,10 @@ import { CustomUser } from "@/lib/types";
import { authOptions } from "../../../../auth/[...nextauth]";
+export const config = {
+ maxDuration: 120,
+};
+
export default async function handle(
req: NextApiRequest,
res: NextApiResponse,
diff --git a/pages/api/teams/[teamId]/datarooms/index.ts b/pages/api/teams/[teamId]/datarooms/index.ts
index ba211571..b3942816 100644
--- a/pages/api/teams/[teamId]/datarooms/index.ts
+++ b/pages/api/teams/[teamId]/datarooms/index.ts
@@ -1,5 +1,6 @@
import { NextApiRequest, NextApiResponse } from "next";
+import { isTeamPausedById } from "@/ee/features/billing/cancellation/lib/is-team-paused";
import { getLimits } from "@/ee/limits/server";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import slugify from "@sindresorhus/slugify";
@@ -189,6 +190,7 @@ export default async function handle(
"datarooms+drtrial",
"business+drtrial",
"datarooms-plus+drtrial",
+ "datarooms-premium",
],
},
users: {
@@ -203,6 +205,15 @@ export default async function handle(
return res.status(401).end("Unauthorized");
}
+ // Check if team is paused
+ const teamIsPaused = await isTeamPausedById(teamId);
+ if (teamIsPaused) {
+ return res.status(403).json({
+ error:
+ "Team is currently paused. New dataroom creation is not available.",
+ });
+ }
+
// Limits: Check if the user has reached the limit of datarooms in the team
const dataroomCount = await prisma.dataroom.count({
where: {
diff --git a/pages/api/teams/[teamId]/documents/[id]/duplicate.ts b/pages/api/teams/[teamId]/documents/[id]/duplicate.ts
index 7e43db41..e2090dd6 100644
--- a/pages/api/teams/[teamId]/documents/[id]/duplicate.ts
+++ b/pages/api/teams/[teamId]/documents/[id]/duplicate.ts
@@ -1,5 +1,6 @@
import { NextApiRequest, NextApiResponse } from "next";
+import { isTeamPausedById } from "@/ee/features/billing/cancellation/lib/is-team-paused";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { DocumentVersion } from "@prisma/client";
import { getServerSession } from "next-auth/next";
@@ -50,6 +51,15 @@ export default async function handle(
return res.status(401).end("Unauthorized");
}
+ // Check if team is paused
+ const teamIsPaused = await isTeamPausedById(teamId);
+ if (teamIsPaused) {
+ return res.status(403).json({
+ error:
+ "Team is currently paused. New document creation is not available.",
+ });
+ }
+
const document = await prisma.document.findUnique({
where: {
id: docId,
diff --git a/pages/api/teams/[teamId]/documents/[id]/versions/index.ts b/pages/api/teams/[teamId]/documents/[id]/versions/index.ts
index 03ba4184..bd4826dc 100644
--- a/pages/api/teams/[teamId]/documents/[id]/versions/index.ts
+++ b/pages/api/teams/[teamId]/documents/[id]/versions/index.ts
@@ -1,5 +1,6 @@
import { NextApiRequest, NextApiResponse } from "next";
+import { isTeamPausedById } from "@/ee/features/billing/cancellation/lib/is-team-paused";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { getServerSession } from "next-auth/next";
@@ -70,6 +71,15 @@ export default async function handle(
return res.status(401).end("Unauthorized");
}
+ // Check if team is paused
+ const teamIsPaused = await isTeamPausedById(teamId);
+ if (teamIsPaused) {
+ return res.status(403).json({
+ error:
+ "Team is currently paused. New document uploads are not available.",
+ });
+ }
+
const document = await prisma.document.findUnique({
where: {
id: documentId,
diff --git a/pages/api/teams/[teamId]/documents/[id]/views/index.ts b/pages/api/teams/[teamId]/documents/[id]/views/index.ts
index 4854bac4..e8f7cbf3 100644
--- a/pages/api/teams/[teamId]/documents/[id]/views/index.ts
+++ b/pages/api/teams/[teamId]/documents/[id]/views/index.ts
@@ -1,5 +1,6 @@
import { NextApiRequest, NextApiResponse } from "next";
+import { isTeamPaused } from "@/ee/features/billing/cancellation/lib/is-team-paused";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { View } from "@prisma/client";
import { JsonValue } from "@prisma/client/runtime/library";
@@ -8,7 +9,6 @@ import { getServerSession } from "next-auth/next";
import { LIMITS } from "@/lib/constants";
import { errorhandler } from "@/lib/errorHandler";
import prisma from "@/lib/prisma";
-import { isTeamPaused } from "@/lib/team/is-team-paused";
import { getViewPageDuration } from "@/lib/tinybird";
import { getVideoEventsByDocument } from "@/lib/tinybird/pipes";
import { CustomUser } from "@/lib/types";
diff --git a/pages/api/teams/[teamId]/documents/index.ts b/pages/api/teams/[teamId]/documents/index.ts
index 60085a5f..365b047e 100644
--- a/pages/api/teams/[teamId]/documents/index.ts
+++ b/pages/api/teams/[teamId]/documents/index.ts
@@ -1,5 +1,6 @@
import { NextApiRequest, NextApiResponse } from "next";
+import { isTeamPausedById } from "@/ee/features/billing/cancellation/lib/is-team-paused";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { Prisma } from "@prisma/client";
import { getServerSession } from "next-auth/next";
@@ -8,7 +9,6 @@ import { hashToken } from "@/lib/api/auth/token";
import { processDocument } from "@/lib/api/documents/process-document";
import { errorhandler } from "@/lib/errorHandler";
import prisma from "@/lib/prisma";
-import { isTeamPausedById } from "@/lib/team/is-team-paused";
import { CustomUser } from "@/lib/types";
import { log, serializeFileSize } from "@/lib/utils";
import { supportsAdvancedExcelMode } from "@/lib/utils/get-content-type";
diff --git a/pages/api/links/[id]/visits.ts b/pages/api/teams/[teamId]/links/[id]/visits.ts
similarity index 74%
rename from pages/api/links/[id]/visits.ts
rename to pages/api/teams/[teamId]/links/[id]/visits.ts
index 66fdaab2..95f775e3 100644
--- a/pages/api/links/[id]/visits.ts
+++ b/pages/api/teams/[teamId]/links/[id]/visits.ts
@@ -10,25 +10,37 @@ import { getViewPageDuration } from "@/lib/tinybird";
import { CustomUser } from "@/lib/types";
import { log } from "@/lib/utils";
-import { authOptions } from "../../auth/[...nextauth]";
+import { authOptions } from "../../../../auth/[...nextauth]";
export default async function handle(
req: NextApiRequest,
res: NextApiResponse,
) {
if (req.method === "GET") {
- // GET /api/links/:id/visits
+ // GET /api/teams/:teamId/links/:id/visits
const session = await getServerSession(req, res, authOptions);
if (!session) {
return res.status(401).end("Unauthorized");
}
// get link id from query params
- const { id } = req.query as { id: string };
+ const { teamId, id } = req.query as { teamId: string; id: string };
const userId = (session.user as CustomUser).id;
try {
+ const teamAccess = await prisma.userTeam.findUnique({
+ where: {
+ userId_teamId: {
+ userId: userId,
+ teamId: teamId,
+ },
+ },
+ });
+ if (!teamAccess) {
+ return res.status(401).end("Unauthorized");
+ }
+
// get the numPages from document
const result = await prisma.link.findUnique({
where: {
@@ -50,6 +62,8 @@ export default async function handle(
select: {
id: true,
plan: true,
+ pauseStartsAt: true,
+ pauseEndsAt: true,
},
},
},
@@ -86,15 +100,34 @@ export default async function handle(
result?.document?.numPages ||
0;
- const views = await prisma.view.findMany({
+ const pauseStartsAt = result?.document?.team?.pauseStartsAt;
+ const pauseEndsAt = result?.document?.team?.pauseEndsAt;
+
+ const allViews = await prisma.view.findMany({
where: {
linkId: id,
+ teamId: teamId,
},
orderBy: {
viewedAt: "desc",
},
});
+ // Filter out views that occurred during the pause period and count hidden views
+ let hiddenFromPause = 0;
+ const views =
+ pauseStartsAt && pauseEndsAt
+ ? allViews.filter((view) => {
+ const viewedAt = new Date(view.viewedAt);
+ const isDuringPause =
+ viewedAt >= pauseStartsAt && viewedAt <= pauseEndsAt;
+ if (isDuringPause) {
+ hiddenFromPause++;
+ }
+ return !isDuringPause;
+ })
+ : allViews;
+
// limit the number of views to 20 on free plan
const limitedViews =
result?.document?.team?.plan === "free"
@@ -136,7 +169,10 @@ export default async function handle(
// TODO: Check that the user is owner of the links, otherwise return 401
- return res.status(200).json(viewsWithDuration);
+ return res.status(200).json({
+ views: viewsWithDuration,
+ hiddenFromPause,
+ });
} catch (error) {
log({
message: `Failed to get views for link: _${id}_. \n\n ${error} \n\n*Metadata*: \`{userId: ${userId}}\``,
diff --git a/pages/api/webhooks/services/[...path]/index.ts b/pages/api/webhooks/services/[...path]/index.ts
index f888c319..e0467900 100644
--- a/pages/api/webhooks/services/[...path]/index.ts
+++ b/pages/api/webhooks/services/[...path]/index.ts
@@ -1,5 +1,6 @@
import { NextApiRequest, NextApiResponse } from "next";
+import { isTeamPausedById } from "@/ee/features/billing/cancellation/lib/is-team-paused";
import { LinkPreset } from "@prisma/client";
import slugify from "@sindresorhus/slugify";
import { put } from "@vercel/blob";
@@ -13,7 +14,6 @@ import { newId } from "@/lib/id-helper";
import { extractTeamId, isValidWebhookId } from "@/lib/incoming-webhooks";
import prisma from "@/lib/prisma";
import { ratelimit } from "@/lib/redis";
-import { isTeamPausedById } from "@/lib/team/is-team-paused";
import {
convertDataUrlToBuffer,
generateEncrpytedPassword,