Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add owner to link
Marc Seitzffe9b0496c84
diff --git a/app/(ee)/api/scim/v2.0/[...directory]/route.ts b/app/(ee)/api/scim/v2.0/[...directory]/route.tsindex cc042f2b..762eb96f 100644--- a/app/(ee)/api/scim/v2.0/[...directory]/route.ts+++ b/app/(ee)/api/scim/v2.0/[...directory]/route.ts@@ -171,20 +171,37 @@ async function handleSCIMEvents(event: DirectorySyncEvent) {});if (user) {- await prisma.userTeam- .delete({- where: {- userId_teamId: {- userId: user.id,+ await Promise.all([+ prisma.link+ .updateMany({+ where: {teamId: tenant,+ ownerId: user.id,},- },- })- .catch(() => {- console.warn(- `[SCIM] Could not remove team membership for user_${hashEmail(email)}`,- );- });+ data: {+ ownerId: null,+ },+ })+ .catch(() => {+ console.warn(+ `[SCIM] Could not reset link ownership for user_${hashEmail(email)}`,+ );+ }),+ prisma.userTeam+ .delete({+ where: {+ userId_teamId: {+ userId: user.id,+ teamId: tenant,+ },+ },+ })+ .catch(() => {+ console.warn(+ `[SCIM] Could not remove team membership for user_${hashEmail(email)}`,+ );+ }),+ ]);}} else if (isActive) {// Reactivated — re-add to team@@ -243,25 +260,42 @@ async function handleSCIMEvents(event: DirectorySyncEvent) {`[SCIM] User deleted: user_${hashEmail(email)} for tenant ${tenant}`,);- const user = await prisma.user.findUnique({+ const deletedUser = await prisma.user.findUnique({where: { email },});- if (user) {- await prisma.userTeam- .delete({- where: {- userId_teamId: {- userId: user.id,+ if (deletedUser) {+ await Promise.all([+ prisma.link+ .updateMany({+ where: {teamId: tenant,+ ownerId: deletedUser.id,},- },- })- .catch(() => {- console.warn(- `[SCIM] Could not remove team membership for user_${hashEmail(email)}`,- );- });+ data: {+ ownerId: null,+ },+ })+ .catch(() => {+ console.warn(+ `[SCIM] Could not reset link ownership for user_${hashEmail(email)}`,+ );+ }),+ prisma.userTeam+ .delete({+ where: {+ userId_teamId: {+ userId: deletedUser.id,+ teamId: tenant,+ },+ },+ })+ .catch(() => {+ console.warn(+ `[SCIM] Could not remove team membership for user_${hashEmail(email)}`,+ );+ }),+ ]);}break;}diff --git a/app/(ee)/api/workflows/route.ts b/app/(ee)/api/workflows/route.tsindex 256e4fe0..f24d7f5a 100644--- a/app/(ee)/api/workflows/route.ts+++ b/app/(ee)/api/workflows/route.ts@@ -230,6 +230,7 @@ export async function POST(req: NextRequest) {data: {linkType: "WORKFLOW_LINK",teamId,+ ownerId: userId,name: `${name} - Entry Link`,slug: slug || null,domainId: domainId,diff --git a/lib/api/documents/process-document.ts b/lib/api/documents/process-document.tsindex a0371c8d..4ac35ff1 100644--- a/lib/api/documents/process-document.ts+++ b/lib/api/documents/process-document.ts@@ -138,6 +138,7 @@ export const processDocument = async ({links: {create: {teamId,+ ownerId: userId,},},}),diff --git a/pages/api/jobs/send-notification.ts b/pages/api/jobs/send-notification.tsindex 52115d8b..9a6a5413 100644--- a/pages/api/jobs/send-notification.ts+++ b/pages/api/jobs/send-notification.ts@@ -47,7 +47,7 @@ export default async function handle(viewType: "DOCUMENT_VIEW" | "DATAROOM_VIEW";viewerEmail: string | null;linkId: string;- link: { name: string | null } | null;+ link: { name: string | null; ownerId: string | null } | null;document: {teamId: string | null;id: string;@@ -79,6 +79,7 @@ export default async function handle(link: {select: {name: true,+ ownerId: true,},},document: {@@ -160,28 +161,51 @@ export default async function handle(},});- // Get the active owner of the document- let ownerEmail: string | null = null;- if (view.document?.ownerId) {- const ownerUser = await prisma.userTeam.findUnique({- where: {- userId_teamId: {- userId: view.document!.ownerId!,- teamId: teamId,- },- status: "ACTIVE",- },- select: {- user: {- select: {- email: true,- },- },- },- });-- ownerEmail = ownerUser?.user.email || null;- }+ // Fetch document owner and link owner emails in parallel (async-parallel best practice)+ const [ownerEmail, linkOwnerEmail] = await Promise.all([+ // Get the active owner of the document+ view.document?.ownerId+ ? prisma.userTeam+ .findUnique({+ where: {+ userId_teamId: {+ userId: view.document.ownerId,+ teamId: teamId,+ },+ status: "ACTIVE",+ },+ select: {+ user: {+ select: {+ email: true,+ },+ },+ },+ })+ .then((result) => result?.user.email || null)+ : null,+ // Get the active owner of the link+ view.link?.ownerId+ ? prisma.userTeam+ .findUnique({+ where: {+ userId_teamId: {+ userId: view.link.ownerId,+ teamId: teamId,+ },+ status: "ACTIVE",+ },+ select: {+ user: {+ select: {+ email: true,+ },+ },+ },+ })+ .then((result) => result?.user.email || null)+ : null,+ ]);const includeLocation =!view.team?.plan?.includes("free") &&@@ -223,6 +247,16 @@ export default async function handle(teamMembers.push(ownerEmail);}+ // Add linkOwnerEmail to teamMembers if it exists and isn't already included+ if (+ linkOwnerEmail &&+ linkOwnerEmail !== adminEmail &&+ linkOwnerEmail !== ownerEmail &&+ !teamMembers.includes(linkOwnerEmail)+ ) {+ teamMembers.push(linkOwnerEmail);+ }+// send appropriate email based on team pause statusif (teamIsPaused) {await sendViewedDocumentPausedEmail({@@ -243,15 +277,26 @@ export default async function handle(});}} else {+ const teamMembers = users+ .map((user) => user.user.email!)+ .filter((email) => email !== adminEmail);++ // Add linkOwnerEmail to teamMembers if it exists and isn't already included+ if (+ linkOwnerEmail &&+ linkOwnerEmail !== adminEmail &&+ !teamMembers.includes(linkOwnerEmail)+ ) {+ teamMembers.push(linkOwnerEmail);+ }+// send appropriate email based on team pause statusif (teamIsPaused) {await sendViewedDataroomPausedEmail({ownerEmail: adminEmail,dataroomName: view.dataroom!.name,linkName: view.link!.name || `Link #${view.linkId.slice(-5)}`,- teamMembers: users- .map((user) => user.user.email!)- .filter((email) => email !== adminEmail),+ teamMembers,});} else {await sendViewedDataroomEmail({@@ -260,9 +305,7 @@ export default async function handle(dataroomName: view.dataroom!.name,viewerEmail: view.viewerEmail,linkName: view.link!.name || `Link #${view.linkId.slice(-5)}`,- teamMembers: users- .map((user) => user.user.email!)- .filter((email) => email !== adminEmail),+ teamMembers,locationString: includeLocation ? locationString : undefined,});}diff --git a/pages/api/links/[id]/duplicate.ts b/pages/api/links/[id]/duplicate.tsindex 44ad48bc..ec71ac9e 100644--- a/pages/api/links/[id]/duplicate.ts+++ b/pages/api/links/[id]/duplicate.ts@@ -130,6 +130,7 @@ export default async function handle(createdAt: undefined,updatedAt: undefined,permissionGroupId: newPermissionGroupId,+ ownerId: userId,},});diff --git a/pages/api/links/index.ts b/pages/api/links/index.tsindex 73e751ee..536f421d 100644--- a/pages/api/links/index.ts+++ b/pages/api/links/index.ts@@ -164,6 +164,7 @@ export default async function handler(dataroomId: dataroomLink ? targetId : null,linkType,teamId,+ ownerId: userId,password: hashedPassword,name: linkData.name || null,emailProtected:diff --git a/pages/api/teams/[teamId]/remove-teammate.ts b/pages/api/teams/[teamId]/remove-teammate.tsindex 1d4aa53f..ca15b9f8 100644--- a/pages/api/teams/[teamId]/remove-teammate.ts+++ b/pages/api/teams/[teamId]/remove-teammate.ts@@ -50,6 +50,16 @@ export default async function handle(ownerId: null,},}),+ // update all links owned by the user to have no owner+ prisma.link.updateMany({+ where: {+ teamId,+ ownerId: userToBeDeleted,+ },+ data: {+ ownerId: null,+ },+ }),// delete the user from the teamprisma.userTeam.delete({where: {diff --git a/prisma/migrations/20260212000000_add_owner_to_link/migration.sql b/prisma/migrations/20260212000000_add_owner_to_link/migration.sqlnew file mode 100644index 00000000..02fac809--- /dev/null+++ b/prisma/migrations/20260212000000_add_owner_to_link/migration.sql@@ -0,0 +1,9 @@+-- AlterTable+ALTER TABLE "Link" ADD COLUMN "ownerId" TEXT;++-- CreateIndex+CREATE INDEX "Link_ownerId_idx" ON "Link"("ownerId" ASC);++-- AddForeignKey+ALTER TABLE "Link" ADD CONSTRAINT "Link_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;+diff --git a/prisma/schema/link.prisma b/prisma/schema/link.prismaindex cb956330..2fe7929c 100644--- a/prisma/schema/link.prisma+++ b/prisma/schema/link.prisma@@ -88,6 +88,9 @@ model Link {teamId String?team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)+ ownerId String?+ owner User? @relation("LinkOwner", fields: [ownerId], references: [id], onDelete: SetNull)+customFields CustomField[]tags TagItem[]@@ -102,6 +105,7 @@ model Link {@@index([documentId, isArchived]) // Performance optimization for active links filtering@@index([permissionGroupId]) // Performance optimization for permission group queries@@index([deletedAt]) // Performance optimization for filtering deleted links+ @@index([ownerId]) // Performance optimization for link owner queries}model LinkPreset {diff --git a/prisma/schema/schema.prisma b/prisma/schema/schema.prismaindex 785c95c1..02b6d14f 100644--- a/prisma/schema/schema.prisma+++ b/prisma/schema/schema.prisma@@ -68,6 +68,8 @@ model User {createdAnnotations DocumentAnnotation[] // Annotations created by this userinstalledIntegrations InstalledIntegration[]++ links Link[] @relation("LinkOwner")}model Brand {