Skip to content

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

feat: add team paused block

Marc Seitzb23308be1e73
diff --git a/lib/api/views/send-webhook-event.ts b/lib/api/views/send-webhook-event.ts
index d68e59b2..832ea6cd 100644
--- a/lib/api/views/send-webhook-event.ts
+++ b/lib/api/views/send-webhook-event.ts
@@ -1,4 +1,5 @@
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";
@@ -36,6 +37,13 @@ export async function sendLinkViewWebhook({
return;
}
+ // check if team is paused
+ const teamIsPaused = await isTeamPausedById(teamId);
+ if (teamIsPaused) {
+ // team is paused, so we don't send webhooks
+ return;
+ }
+
// Get webhooks for team
const webhooks = await prisma.webhook.findMany({
where: {
diff --git a/lib/team/is-team-paused.ts b/lib/team/is-team-paused.ts
new file mode 100644
index 00000000..ae2c0b0b
--- /dev/null
+++ b/lib/team/is-team-paused.ts
@@ -0,0 +1,44 @@
+import { Team } from "@prisma/client";
+
+import prisma from "@/lib/prisma";
+
+/**
+ * Check if a team is currently paused
+ * A team is considered paused if:
+ * 1. pausedAt is set (team was paused)
+ * 2. Current time is within the pause period (between pauseStartsAt and pauseEndsAt)
+ */
+export function isTeamPaused(
+ team: Pick<Team, "pausedAt" | "pauseStartsAt" | "pauseEndsAt">,
+): boolean {
+ if (!team.pausedAt || !team.pauseStartsAt || !team.pauseEndsAt) {
+ return false;
+ }
+
+ const now = new Date();
+ const pauseStartsAt = new Date(team.pauseStartsAt);
+ const pauseEndsAt = new Date(team.pauseEndsAt);
+
+ // Team is paused if current time is within the pause period
+ return now >= pauseStartsAt && now <= pauseEndsAt;
+}
+
+/**
+ * Check if a team is currently paused (async version that fetches team data)
+ */
+export async function isTeamPausedById(teamId: string): Promise<boolean> {
+ const team = await prisma.team.findUnique({
+ where: { id: teamId },
+ select: {
+ pausedAt: true,
+ pauseStartsAt: true,
+ pauseEndsAt: true,
+ },
+ });
+
+ if (!team) {
+ return false;
+ }
+
+ return isTeamPaused(team);
+}
diff --git a/lib/webhook/triggers/document-created.ts b/lib/webhook/triggers/document-created.ts
index c750c5ef..3e54580a 100644
--- a/lib/webhook/triggers/document-created.ts
+++ b/lib/webhook/triggers/document-created.ts
@@ -1,4 +1,5 @@
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";
@@ -22,14 +23,18 @@ export async function sendDocumentCreatedWebhook({
select: { plan: true },
});
- if (
- team?.plan === "free" ||
- team?.plan === "pro"
- ) {
+ if (team?.plan === "free" || team?.plan === "pro") {
// team is not on paid plan, so we don't need to send webhooks
return;
}
+ // check if team is paused
+ const teamIsPaused = await isTeamPausedById(teamId);
+ if (teamIsPaused) {
+ // team is paused, so we don't send webhooks
+ return;
+ }
+
// Get webhooks for team
const webhooks = await prisma.webhook.findMany({
where: {
diff --git a/lib/webhook/triggers/link-created.ts b/lib/webhook/triggers/link-created.ts
index 378778ed..cea2527c 100644
--- a/lib/webhook/triggers/link-created.ts
+++ b/lib/webhook/triggers/link-created.ts
@@ -1,4 +1,5 @@
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";
@@ -35,6 +36,13 @@ export async function sendLinkCreatedWebhook({
return;
}
+ // check if team is paused
+ const teamIsPaused = await isTeamPausedById(teamId);
+ if (teamIsPaused) {
+ // team is paused, so we don't send webhooks
+ return;
+ }
+
// Get webhooks for team
const webhooks = await prisma.webhook.findMany({
where: {
diff --git a/pages/api/links/index.ts b/pages/api/links/index.ts
index c503fae7..9501d960 100644
--- a/pages/api/links/index.ts
+++ b/pages/api/links/index.ts
@@ -6,6 +6,7 @@ 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,
@@ -52,17 +53,27 @@ export default async function handler(
const documentLink = linkType === "DOCUMENT_LINK";
try {
- const team = await prisma.team.findUnique({
+ const teamAccess = await prisma.userTeam.findUnique({
where: {
- id: teamId,
- users: {
- some: { userId },
+ userId_teamId: {
+ userId,
+ teamId,
},
},
+ select: { teamId: true },
});
- if (!team) {
- return res.status(400).json({ error: "Team not found." });
+ if (!teamAccess) {
+ return res.status(401).json({ error: "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 hashedPassword =
diff --git a/pages/api/teams/[teamId]/documents/index.ts b/pages/api/teams/[teamId]/documents/index.ts
index 4b0b8c71..7aee8839 100644
--- a/pages/api/teams/[teamId]/documents/index.ts
+++ b/pages/api/teams/[teamId]/documents/index.ts
@@ -8,6 +8,7 @@ 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";
@@ -336,6 +337,15 @@ export default async function handle(
return res.status(404).end("Team not found");
}
+ // 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 processDocument({
documentData: {
name,
diff --git a/pages/api/webhooks/services/[...path]/index.ts b/pages/api/webhooks/services/[...path]/index.ts
index 1777fa6d..46515223 100644
--- a/pages/api/webhooks/services/[...path]/index.ts
+++ b/pages/api/webhooks/services/[...path]/index.ts
@@ -11,6 +11,7 @@ import { putFileServer } from "@/lib/files/put-file-server";
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,
@@ -233,6 +234,15 @@ async function handleDocumentCreate(
const { fileUrl, name, contentType, dataroomId, createLink, link, folderId } =
data;
+ // 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.",
+ });
+ }
+
// Check if the content type is supported
const supportedContentType = getSupportedContentType(contentType);
if (!supportedContentType) {
@@ -555,6 +565,14 @@ async function handleLinkCreate(
) {
const { targetId, linkType, link } = data;
+ // 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.",
+ });
+ }
+
// Validate target exists and belongs to the team
if (linkType === "DOCUMENT_LINK") {
const document = await prisma.document.findUnique({