Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add teamId to links and views
Marc Seitz18c6f3416573
diff --git a/pages/api/links/index.ts b/pages/api/links/index.tsindex 4a29a4ab..51ae9163 100644--- a/pages/api/links/index.ts+++ b/pages/api/links/index.ts@@ -29,6 +29,7 @@ export default async function handler(req.body;const userId = (session.user as CustomUser).id;+ let teamId: string | null = null;const dataroomLink = linkType === "DATAROOM_LINK";const documentLink = linkType === "DOCUMENT_LINK";@@ -36,7 +37,7 @@ export default async function handler(try {if (documentLink) {// check if the team that own the document has the current user- await getDocumentWithTeamAndUser({+ const { document } = await getDocumentWithTeamAndUser({docId: targetId,userId,options: {@@ -51,6 +52,9 @@ export default async function handler(},},});++ // set teamId to the teamId of the document+ teamId = document.teamId;}if (dataroomLink) {@@ -65,12 +69,15 @@ export default async function handler(},},},- select: { id: true },+ select: { id: true, teamId: true },});if (!dataroom) {return res.status(400).json({ error: "Dataroom not found." });}++ // set teamId to the teamId of the dataroom+ teamId = dataroom.teamId;}const hashedPassword =@@ -137,6 +144,7 @@ export default async function handler(documentId: documentLink ? targetId : null,dataroomId: dataroomLink ? targetId : null,linkType,+ teamId,password: hashedPassword,name: linkData.name || null,emailProtected:diff --git a/pages/api/views-dataroom.ts b/pages/api/views-dataroom.tsindex 372f5abf..7c136d24 100644--- a/pages/api/views-dataroom.ts+++ b/pages/api/views-dataroom.ts@@ -479,6 +479,7 @@ export default async function handle(dataroomId: dataroomId,viewType: "DATAROOM_VIEW",viewerId: viewer?.id ?? undefined,+ teamId: link.dataroom?.teamId,...(link.enableAgreement &&link.agreementId &&hasConfirmedAgreement && {@@ -540,6 +541,7 @@ export default async function handle(dataroomId: dataroomId,viewType: "DOCUMENT_VIEW",viewerId: viewer?.id ?? undefined,+ teamId: link.dataroom?.teamId,...(link.enableAgreement &&link.agreementId &&hasConfirmedAgreement && {diff --git a/pages/api/views.ts b/pages/api/views.tsindex 639222f8..8623f1e0 100644--- a/pages/api/views.ts+++ b/pages/api/views.ts@@ -97,6 +97,7 @@ export default async function handle(watermarkConfig: true,document: {select: {+ teamId: true,team: {select: {plan: true,@@ -397,6 +398,7 @@ export default async function handle(viewerEmail: email,viewerName: name,documentId: documentId,+ teamId: link.document?.teamId,verified: isEmailVerified,...(link.enableAgreement &&link.agreementId &&diff --git a/prisma/migrations/20241020000000_add_teamid_to_link_and_view/migration.sql b/prisma/migrations/20241020000000_add_teamid_to_link_and_view/migration.sqlnew file mode 100644index 00000000..012d1db4--- /dev/null+++ b/prisma/migrations/20241020000000_add_teamid_to_link_and_view/migration.sql@@ -0,0 +1,18 @@+-- AlterTable+ALTER TABLE "Link" ADD COLUMN "teamId" TEXT;++-- AlterTable+ALTER TABLE "View" ADD COLUMN "teamId" TEXT;++-- CreateIndex+CREATE INDEX "Link_teamId_idx" ON "Link"("teamId");++-- CreateIndex+CREATE INDEX "View_teamId_idx" ON "View"("teamId");++-- AddForeignKey+ALTER TABLE "Link" ADD CONSTRAINT "Link_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;++-- AddForeignKey+ALTER TABLE "View" ADD CONSTRAINT "View_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;+diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex eaeedd02..16070654 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -72,6 +72,9 @@ model Team {viewerGroups ViewerGroup[]viewers Viewer[]+ links Link[]+ views View[]+plan String @default("free")stripeId String? @unique // Stripe customer IDsubscriptionId String? @unique // Stripe subscription ID@@ -261,8 +264,12 @@ model Link {metaFavicon String? // This will be the meta favicon of the linkenableCustomMetatag Boolean? @default(false) // Optional give user a option to enable the custom metatag+ teamId String?+ team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)+@@unique([domainSlug, slug])@@index([documentId])+ @@index([teamId])}model LinkPreset {@@ -324,10 +331,14 @@ model View {feedbackResponse FeedbackResponse?agreementResponse AgreementResponse?+ teamId String?+ team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)+@@index([linkId])@@index([documentId])@@index([dataroomId])@@index([dataroomViewId])+ @@index([teamId])}enum ViewType {