Files
zeekayandHanzo Dev f77d5010d8 ee: delete the relocated upstream commercial code and its paywall
Papermark dual-licenses: AGPL-3.0 for the tree, a separate commercial
licence for ee/. We hold the first and not the second, so none of the
second may live here.

ee/ was already absent from main, but it was never deleted. 98f0da7fa
("ci: amd64-only build") renamed 150 files out of ee/ byte-identical
into features/, lib/billing/legacy/ (ee/stripe), lib/billing/limits/
(ee/limits), and flattened app/(ee)/ into app/ — putting commercially
licensed code under our AGPL root LICENSE. A rename is not a deletion.
Every path that commit moved is now gone, edited-since or not.

Deleted, with their routes and UI entry points: features/ai and
app/api/ai, features/workflows and app/api/{workflows,workflow-entry},
features/conversations and the Q&A/FAQ surface, features/security/sso
with app/api/auth/saml + app/api/scim + lib/jackson.ts (we use Hanzo
IAM OIDC natively), features/dataroom-invitations, features/templates,
features/access-notifications, features/conversions, features/
permissions. Five of these were gated by lib/featureFlags, which reads
@vercel/edge-config and returns false for every flag when EDGE_CONFIG
is unset — every non-Vercel deployment we run. Those flags are gone too.

Deleted the commercial gating outright rather than reimplementing it:
lib/billing/legacy (ee/stripe) and lib/billing/limits (ee/limits), the
upgrade modals and banners, UpgradeButton, FeaturePreview, PlanBadge,
the trial and blocking modals, /settings/upgrade, /settings/billing and
the billing checkout/seat/pause/cancel API. usePlan() no longer returns
capability booleans — the plan tag describes provisioning, it is not a
permission — and useLimits() is gone with every quota check it fed.
Subscription pause went the same way. Also dropped the npm dependencies
that existed only for the removed features (@boxyhq/saml-jackson, the
@ai-sdk packages, openai, streamdown, use-stick-to-bottom,
@trigger.dev/python) and the Jackson-specific next.config webpack shims.

Rewritten as original Hanzo code where a capability was load-bearing:
- lib/utils/get-file-size-limits.ts — one UPLOAD_LIMITS set plus
  getFileSizeLimit(contentType), env-overridable. Operational limits,
  not commercial ones, so the tus and browser-upload paths still refuse
  oversized files without consulting a plan matrix.
- components/links/link-sheet/permissions-sheet.tsx — a flat, depth
  annotated item list with view/download switches over the same
  /permission-groups API. Two states, not three. ItemPermission now has
  a single definition in lib/types.ts.
- app/api/links/[id]/upload/route.ts — visitor uploads, built around one
  authorize() helper shared by GET and POST, and a notification debounce
  keyed per (link, viewer) instead of listing and cancelling runs.

There is now exactly one link sheet: the ee DataroomLinkSheet duplicated
the AGPL LinkSheet, which already handled DATAROOM_LINK. Replaced
upstream's Omit<LinkType, "WORKFLOW_LINK"> — Omit on a string union
yields an object type and never narrowed anything — with a real union.

Verified: the S3/tus upload+download harness passes 13/13 against MinIO
after the deletions, and tsc goes from 257 pre-existing errors on
origin/main to 192 with zero files worse than baseline.

Reasoning recorded in LLM.md. LICENSE untouched.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-03 20:19:21 -07:00

276 lines
7.4 KiB
TypeScript

import { NextApiRequest, NextApiResponse } from "next";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { DefaultPermissionStrategy } from "@prisma/client";
import { getServerSession } from "next-auth/next";
import { errorhandler } from "@/lib/errorHandler";
import prisma from "@/lib/prisma";
import { CustomUser } from "@/lib/types";
export default async function handle(
req: NextApiRequest,
res: NextApiResponse,
) {
if (req.method === "GET") {
// GET /api/teams/:teamId/datarooms/:id
const session = await getServerSession(req, res, authOptions);
if (!session) {
return res.status(401).end("Unauthorized");
}
const { teamId, id: dataroomId } = 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");
}
const dataroom = await prisma.dataroom.findUnique({
where: {
id: dataroomId,
teamId,
},
include: {
_count: { select: { viewerGroups: true, permissionGroups: true } },
tags: {
include: {
tag: {
select: {
id: true,
name: true,
color: true,
description: true,
},
},
},
},
},
});
if (!dataroom) {
return res.status(404).json({
error: "Not Found",
message: "The requested dataroom does not exist",
});
}
return res.status(200).json(dataroom);
} catch (error) {
errorhandler(error, res);
}
} else if (req.method === "PATCH") {
// PATCH /api/teams/:teamId/datarooms/:id
const session = await getServerSession(req, res, authOptions);
if (!session) {
return res.status(401).end("Unauthorized");
}
const { teamId, id: dataroomId } = req.query as {
teamId: string;
id: string;
};
const userId = (session.user as CustomUser).id;
try {
// Check if the user is part of the team
const team = await prisma.team.findUnique({
where: {
id: teamId,
users: {
some: {
userId: userId,
},
},
},
select: {
id: true,
plan: true,
},
});
if (!team) {
return res.status(401).end("Unauthorized");
}
const {
name,
internalName,
enableChangeNotifications,
defaultPermissionStrategy,
allowBulkDownload,
showLastUpdated,
tags,
introductionEnabled,
introductionContent,
} = req.body as {
name?: string;
internalName?: string | null;
enableChangeNotifications?: boolean;
defaultPermissionStrategy?: DefaultPermissionStrategy;
allowBulkDownload?: boolean;
showLastUpdated?: boolean;
tags?: string[];
introductionEnabled?: boolean;
introductionContent?: any;
};
const updatedDataroom = await prisma.$transaction(async (tx) => {
const dataroom = await tx.dataroom.update({
where: {
id: dataroomId,
},
data: {
...(name && { name }),
...(internalName !== undefined && {
internalName: internalName === null || internalName === "" ? null : internalName.trim()
}),
...(typeof enableChangeNotifications === "boolean" && {
enableChangeNotifications,
}),
...(defaultPermissionStrategy && { defaultPermissionStrategy }),
...(typeof allowBulkDownload === "boolean" && {
allowBulkDownload,
}),
...(typeof showLastUpdated === "boolean" && {
showLastUpdated,
}),
...(typeof introductionEnabled === "boolean" && {
introductionEnabled,
}),
...(introductionContent !== undefined && {
introductionContent,
}),
},
});
// Handle tags if provided
if (tags !== undefined) {
// Validate that all tags exist and belong to the same team
if (tags.length > 0) {
const validTags = await tx.tag.findMany({
where: {
id: { in: tags },
teamId: teamId,
},
select: { id: true },
});
const validTagIds = new Set(validTags.map((t) => t.id));
const invalidTags = tags.filter((id) => !validTagIds.has(id));
if (invalidTags.length > 0) {
throw new Error(`Invalid tag IDs: ${invalidTags.join(", ")}`);
}
}
// First, delete all existing tags for this dataroom
await tx.tagItem.deleteMany({
where: {
dataroomId: dataroomId,
itemType: "DATAROOM_TAG",
},
});
// Then create the new tags (if any)
if (tags.length > 0) {
await tx.tagItem.createMany({
data: tags.map((tagId: string) => ({
tagId,
itemType: "DATAROOM_TAG",
dataroomId: dataroomId,
taggedBy: userId,
})),
});
}
}
// Fetch the updated dataroom with tags
const dataroomTags = await tx.tag.findMany({
where: {
items: {
some: { dataroomId: dataroom.id },
},
},
select: {
id: true,
name: true,
color: true,
description: true,
},
});
return { ...dataroom, tags: dataroomTags };
});
return res.status(200).json(updatedDataroom);
} catch (error) {
errorhandler(error, res);
}
} else if (req.method === "DELETE") {
// DELETE /api/teams/:teamId/datarooms/:id
const session = await getServerSession(req, res, authOptions);
if (!session) {
return res.status(401).end("Unauthorized");
}
const userId = (session.user as CustomUser).id;
const { teamId, id: dataroomId } = req.query as {
teamId: string;
id: string;
};
try {
const teamAccess = await prisma.userTeam.findUnique({
where: {
userId_teamId: {
userId: userId,
teamId: teamId,
},
},
select: {
role: true,
},
});
if (!teamAccess) {
return res.status(401).end("Unauthorized");
}
if (teamAccess.role !== "ADMIN" && teamAccess.role !== "MANAGER") {
return res.status(403).json({
message:
"You are not permitted to perform this action. Only admin and managers can delete datarooms.",
});
}
await prisma.dataroom.delete({
where: {
id: dataroomId,
teamId,
},
});
return res.status(204).end();
} catch (error) {
errorhandler(error, res);
}
} else {
// We only allow GET, and PATCH requests
res.setHeader("Allow", ["GET", "PATCH"]);
return res.status(405).end(`Method ${req.method} Not Allowed`);
}
}