Skip to content

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

Merge branch 'main' into 172/tags

Marc Seitzdd4ab7e3bd10
diff --cc components/links/link-sheet/index.tsx
index d895827b,587a4978..b6da5489
--- a/components/links/link-sheet/index.tsx
+++ b/components/links/link-sheet/index.tsx
@@@ -78,7 -81,11 +82,12 @@@ export const DEFAULT_LINK_PROPS =
audienceType: groupId ? LinkAudienceType.GROUP : LinkAudienceType.GENERAL,
groupId: groupId,
customFields: [],
+ tags: [],
+ enableConversation: false,
+ enableUpload: false,
+ isFileRequestOnly: false,
+ uploadFolderId: null,
+ uploadFolderName: "Home",
});
export type DEFAULT_LINK_TYPE = {
@@@ -112,7 -119,11 +121,12 @@@
audienceType: LinkAudienceType;
groupId: string | null;
customFields: CustomFieldData[];
+ tags: string[];
+ enableConversation: boolean;
+ enableUpload: boolean;
+ isFileRequestOnly: boolean;
+ uploadFolderId: string | null;
+ uploadFolderName: string;
};
export default function LinkSheet({
@@@ -437,14 -503,47 +507,54 @@@
editLink={!!currentLink}
/>
</div>
+ <div className="space-y-2">
+ <TagSection
+ {...{ data, setData }}
+ editLink={!!currentLink}
+ teamId={teamInfo?.currentTeam?.id as string}
+ />
+ </div>
+ {/* Preset Selector - only show when creating a new link */}
+ {!currentLink &&
+ isPresetsAllowed &&
+ presets &&
+ presets.length > 0 && (
+ <div className="space-y-2">
+ <div className="flex items-center justify-between">
+ <Label htmlFor="preset">Link Preset</Label>
+ <Link href="/settings/presets">
+ <Button
+ variant="link"
+ size="sm"
+ className="text-xs"
+ >
+ Manage Presets
+ </Button>
+ </Link>
+ </div>
+ <Select onValueChange={applyPreset}>
+ <SelectTrigger className="w-full">
+ <SelectValue placeholder="Select a preset" />
+ </SelectTrigger>
+ <SelectContent>
+ {presets.map((preset) => (
+ <SelectItem
+ key={preset.id}
+ value={preset.id}
+ >
+ {preset.name}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ <p className="text-xs text-muted-foreground">
+ Apply a preset to quickly configure link
+ settings
+ </p>
+ </div>
+ )}
+
<div className="relative flex items-center">
<Separator className="absolute bg-muted-foreground" />
<div className="relative mx-auto">
@@@ -555,14 -656,48 +667,55 @@@
editLink={!!currentLink}
/>
</div>
+ <div className="space-y-2">
+ <TagSection
+ {...{ data, setData }}
+ editLink={!!currentLink}
+ teamId={teamInfo?.currentTeam?.id as string}
+ />
+ </div>
+ {/* Preset Selector for Group links - only show when creating a new link */}
+ {!currentLink &&
+ isPresetsAllowed &&
+ presets &&
+ presets.length > 0 && (
+ <div className="space-y-2">
+ <div className="flex items-center justify-between">
+ <Label htmlFor="preset">Link Preset</Label>
+ <Button
+ variant="link"
+ size="sm"
+ className="text-xs"
+ onClick={() =>
+ router.push("/settings/presets")
+ }
+ >
+ Manage Presets
+ </Button>
+ </div>
+ <Select onValueChange={applyPreset}>
+ <SelectTrigger className="w-full">
+ <SelectValue placeholder="Select a preset" />
+ </SelectTrigger>
+ <SelectContent>
+ {presets.map((preset) => (
+ <SelectItem
+ key={preset.id}
+ value={preset.id}
+ >
+ {preset.name}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ <p className="text-xs text-muted-foreground">
+ Apply a preset to quickly configure link
+ settings
+ </p>
+ </div>
+ )}
+
<div className="relative flex items-center">
<Separator className="absolute bg-muted-foreground" />
<div className="relative mx-auto">
diff --cc components/links/links-table.tsx
index 3ccc1554,92a21713..98b20c64
--- a/components/links/links-table.tsx
+++ b/components/links/links-table.tsx
@@@ -185,7 -170,11 +185,12 @@@ export default function LinksTable(
audienceType: link.audienceType,
groupId: link.groupId,
customFields: link.customFields || [],
+ tags: link.tags.map((tag) => tag.id) || [],
+ enableConversation: link.enableConversation ?? false,
+ enableUpload: link.enableUpload ?? false,
+ isFileRequestOnly: link.isFileRequestOnly ?? false,
+ uploadFolderId: link.uploadFolderId ?? null,
+ uploadFolderName: link.uploadFolderName ?? "Home",
});
//wait for dropdown to close before opening the link sheet
setTimeout(() => {
diff --cc lib/types.ts
index bfbf7969,d59fef27..1eee0308
--- a/lib/types.ts
+++ b/lib/types.ts
@@@ -49,7 -61,7 +61,8 @@@ export interface LinkWithViews extends
views: View[];
feedback: { id: true; data: { question: string; type: string } } | null;
customFields: CustomField[];
+ tags: TagProps[];
+ uploadFolderName: string | undefined;
}
export interface LinkWithDocument extends Link {
diff --cc pages/api/links/[id]/index.ts
index d51434db,82e3d253..bcab9649
--- a/pages/api/links/[id]/index.ts
+++ b/pages/api/links/[id]/index.ts
@@@ -311,70 -312,30 +316,74 @@@ export default async function handle
},
},
},
+ }),
+ enableAgreement: linkData.enableAgreement,
+ agreementId: linkData.agreementId || null,
+ showBanner: linkData.showBanner,
+ enableWatermark: linkData.enableWatermark || false,
+ watermarkConfig: linkData.watermarkConfig || null,
+ groupId: linkData.groupId || null,
+ audienceType: linkData.audienceType || LinkAudienceType.GENERAL,
++ enableConversation: linkData.enableConversation || false,
++ enableUpload: linkData.enableUpload || false,
++ isFileRequestOnly: linkData.isFileRequestOnly || false,
++ uploadFolderId: linkData.uploadFolderId || null,
+ },
+ include: {
+ views: {
+ orderBy: {
+ viewedAt: "desc",
+ },
},
- }),
- enableAgreement: linkData.enableAgreement,
- agreementId: linkData.agreementId || null,
- showBanner: linkData.showBanner,
- enableWatermark: linkData.enableWatermark || false,
- watermarkConfig: linkData.watermarkConfig || null,
- groupId: linkData.groupId || null,
- audienceType: linkData.audienceType || LinkAudienceType.GENERAL,
- enableConversation: linkData.enableConversation || false,
- enableUpload: linkData.enableUpload || false,
- isFileRequestOnly: linkData.isFileRequestOnly || false,
- uploadFolderId: linkData.uploadFolderId || null,
- },
- include: {
- views: {
- orderBy: {
- viewedAt: "desc",
+ _count: {
+ select: { views: true },
},
},
- _count: {
- select: { views: true },
+ });
+ if (linkData.tags?.length) {
+ // Remove only tags that are not in the new list
+ await tx.taggedItem.deleteMany({
+ where: {
+ linkId: id,
+ itemType: "LINK",
+ tagId: { notIn: linkData.tags },
+ },
+ });
+
+ // Add new tags while avoiding duplicates
+ await tx.taggedItem.createMany({
+ data: linkData.tags.map((tagId: string) => ({
+ tagId,
+ itemType: "LINK",
+ linkId: id,
+ taggedBy: userId,
+ })),
+ skipDuplicates: true,
+ });
+ } else {
+ // If all tags are removed, delete all tagged items for this link
+ await tx.taggedItem.deleteMany({
+ where: {
+ linkId: id,
+ itemType: "LINK",
+ },
+ });
+ }
+ const tags = await tx.tag.findMany({
+ where: {
+ taggedItems: {
+ some: { linkId: link.id },
+ },
+ },
+ select: {
+ id: true,
+ name: true,
+ color: true,
+ description: true,
},
- },
+ });
+
+ return { ...link, tags };
});
if (!updatedLink) {
diff --cc pages/api/links/index.ts
index e5190bcb,b6a09215..197e72f6
--- a/pages/api/links/index.ts
+++ b/pages/api/links/index.ts
@@@ -13,11 -15,11 +15,16 @@@ import { sendLinkCreatedWebhook } from
import { authOptions } from "../auth/[...nextauth]";
+ export const config = {
+ // in order to enable `waitUntil` function
+ supportsResponseStreaming: true,
+ };
+
+export interface DomainObject {
+ id: string;
+ slug: string;
+}
+
export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
@@@ -116,100 -118,86 +123,108 @@@
}
// Fetch the link and its related document from the database
- const link = await prisma.link.create({
- data: {
- documentId: documentLink ? targetId : null,
- dataroomId: dataroomLink ? targetId : null,
- linkType,
- teamId,
- password: hashedPassword,
- name: linkData.name || null,
- emailProtected:
- linkData.audienceType === LinkAudienceType.GROUP
- ? true
- : linkData.emailProtected,
- emailAuthenticated: linkData.emailAuthenticated,
- expiresAt: exat,
- allowDownload: linkData.allowDownload,
- domainId: domainObj?.id || null,
- domainSlug: domain || null,
- slug: slug || null,
- enableNotification: linkData.enableNotification,
- enableFeedback: linkData.enableFeedback,
- enableScreenshotProtection: linkData.enableScreenshotProtection,
- enableCustomMetatag: linkData.enableCustomMetatag,
- metaTitle: linkData.metaTitle || null,
- metaDescription: linkData.metaDescription || null,
- metaImage: linkData.metaImage || null,
- metaFavicon: linkData.metaFavicon || null,
- allowList: linkData.allowList,
- denyList: linkData.denyList,
- enableConversation: linkData.enableConversation,
- audienceType: linkData.audienceType,
- groupId:
- linkData.audienceType === LinkAudienceType.GROUP
- ? linkData.groupId
- : null,
- ...(linkData.enableQuestion && {
- enableQuestion: linkData.enableQuestion,
- feedback: {
- create: {
- data: {
- question: linkData.questionText,
- type: linkData.questionType,
+ const updatedLink = await prisma.$transaction(async (tx) => {
+ const link = await tx.link.create({
+ data: {
+ documentId: documentLink ? targetId : null,
+ dataroomId: dataroomLink ? targetId : null,
+ linkType,
+ teamId,
+ password: hashedPassword,
+ name: linkData.name || null,
+ emailProtected:
+ linkData.audienceType === LinkAudienceType.GROUP
+ ? true
+ : linkData.emailProtected,
+ emailAuthenticated: linkData.emailAuthenticated,
+ expiresAt: exat,
+ allowDownload: linkData.allowDownload,
+ domainId: domainObj?.id || null,
+ domainSlug: domain || null,
+ slug: slug || null,
+ enableNotification: linkData.enableNotification,
+ enableFeedback: linkData.enableFeedback,
+ enableScreenshotProtection: linkData.enableScreenshotProtection,
+ enableCustomMetatag: linkData.enableCustomMetatag,
+ metaTitle: linkData.metaTitle || null,
+ metaDescription: linkData.metaDescription || null,
+ metaImage: linkData.metaImage || null,
+ metaFavicon: linkData.metaFavicon || null,
+ allowList: linkData.allowList,
+ denyList: linkData.denyList,
+ audienceType: linkData.audienceType,
+ groupId:
+ linkData.audienceType === LinkAudienceType.GROUP
+ ? linkData.groupId
+ : null,
+ ...(linkData.enableQuestion && {
+ enableQuestion: linkData.enableQuestion,
+ feedback: {
+ create: {
+ data: {
+ question: linkData.questionText,
+ type: linkData.questionType,
+ },
},
},
- },
- }),
- ...(linkData.enableAgreement && {
- enableAgreement: linkData.enableAgreement,
- agreementId: linkData.agreementId,
- }),
- ...(linkData.enableWatermark && {
- enableWatermark: linkData.enableWatermark,
- watermarkConfig: linkData.watermarkConfig,
- }),
- showBanner: linkData.showBanner,
- ...(linkData.customFields && {
- customFields: {
- createMany: {
- data: linkData.customFields.map(
- (field: any, index: number) => ({
- type: field.type,
- identifier: field.identifier,
- label: field.label,
- placeholder: field.placeholder,
- required: field.required,
- disabled: field.disabled,
- orderIndex: index,
- }),
- ),
+ }),
+ ...(linkData.enableAgreement && {
+ enableAgreement: linkData.enableAgreement,
+ agreementId: linkData.agreementId,
+ }),
+ ...(linkData.enableWatermark && {
+ enableWatermark: linkData.enableWatermark,
+ watermarkConfig: linkData.watermarkConfig,
+ }),
++ ...(linkData.enableUpload && {
++ enableUpload: linkData.enableUpload,
++ isFileRequestOnly: linkData.isFileRequestOnly,
++ uploadFolderId: linkData.uploadFolderId,
++ }),
+ showBanner: linkData.showBanner,
+ ...(linkData.customFields && {
+ customFields: {
+ createMany: {
+ data: linkData.customFields.map(
+ (field: any, index: number) => ({
+ type: field.type,
+ identifier: field.identifier,
+ label: field.label,
+ placeholder: field.placeholder,
+ required: field.required,
+ disabled: field.disabled,
+ orderIndex: index,
+ }),
+ ),
+ },
},
- },
- }),
- ...(linkData.enableUpload && {
- enableUpload: linkData.enableUpload,
- isFileRequestOnly: linkData.isFileRequestOnly,
- uploadFolderId: linkData.uploadFolderId,
- }),
- },
- include: {
- customFields: true,
- },
+ }),
+ },
++ include: {
++ customFields: true,
++ },
+ });
+
+ if (linkData.tags?.length) {
+ await tx.taggedItem.createMany({
+ data: linkData.tags.map((tagId: string) => ({
+ tagId,
+ itemType: "LINK",
+ linkId: link.id,
+ taggedBy: userId,
+ })),
+ skipDuplicates: true,
+ });
+ }
+
+ const tags = linkData.tags?.length
+ ? await tx.tag.findMany({
+ where: { id: { in: linkData.tags } },
+ select: { id: true, name: true, color: true, description: true },
+ })
+ : [];
+
+ return { ...link, tags };
});
const linkWithView = {
diff --cc pages/api/teams/[teamId]/datarooms/[id]/links.ts
index ccc8c69d,bff6c7f1..98cdf56d
--- a/pages/api/teams/[teamId]/datarooms/[id]/links.ts
+++ b/pages/api/teams/[teamId]/datarooms/[id]/links.ts
@@@ -68,39 -71,28 +71,52 @@@ export default async function handle
},
});
++ let extendedLinks: LinkWithViews[] = links as LinkWithViews[];
// Decrypt the password for each link
- if (links && links.length > 0) {
- links = await Promise.all(
- links.map(async (link) => {
- const extendedLinks: LinkWithViews[] = links as LinkWithViews[];
++ if (extendedLinks && extendedLinks.length > 0) {
++ extendedLinks = await Promise.all(
++ extendedLinks.map(async (link) => {
+ // Decrypt the password if it exists
+ if (link.password !== null) {
+ link.password = decryptEncrpytedPassword(link.password);
+ }
++ if (link.enableUpload && link.uploadFolderId !== null) {
++ const folder = await prisma.dataroomFolder.findUnique({
++ where: {
++ id: link.uploadFolderId,
++ },
++ select: {
++ name: true,
++ },
++ });
++ link.uploadFolderName = folder?.name;
++ }
+ const tags = await prisma.tag.findMany({
+ where: {
+ taggedItems: {
+ some: {
+ linkId: link.id,
+ },
+ },
+ },
+ select: {
+ id: true,
+ name: true,
+ color: true,
+ description: true,
+ },
+ });
- for (const link of extendedLinks) {
- if (link.password !== null) {
- link.password = decryptEncrpytedPassword(link.password);
- }
- if (link.enableUpload && link.uploadFolderId !== null) {
- const folder = await prisma.dataroomFolder.findUnique({
- where: {
- id: link.uploadFolderId,
- },
- select: {
- name: true,
- },
- });
- link.uploadFolderName = folder?.name;
- }
+ return {
+ ...link,
+ ["tags"]: tags,
+ };
+ }),
+ );
}
- return res.status(200).json(links);
+ // console.log("links", links);
+ return res.status(200).json(extendedLinks);
} catch (error) {
log({
message: `Failed to get links for dataroom: _${dataroomId}_. \n\n ${error} \n\n*Metadata*: \`{teamId: ${teamId}, userId: ${userId}}\``,
diff --cc prisma/schema/schema.prisma
index 85655a1e,6710baa4..34550cf7
--- a/prisma/schema/schema.prisma
+++ b/prisma/schema/schema.prisma
@@@ -92,9 -96,12 +96,13 @@@ model Team
restrictedTokens RestrictedToken[]
webhooks Webhook[]
+ conversations Conversation[]
+
+ uploadedDocuments DocumentUpload[]
+
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
+ Tag Tag[]
}
model Brand {
@@@ -164,9 -171,12 +172,13 @@@ model Document
folderId String? // Optional Folder ID for documents in folders
folder Folder? @relation(fields: [folderId], references: [id], onDelete: SetNull)
- datarooms DataroomDocument[] // Datarooms associated with this document
+ datarooms DataroomDocument[] // Datarooms associated with this document
+ taggedItems TaggedItem[]
+ // upload external documents
+ uploadedDocument DocumentUpload[]
+ isExternalUpload Boolean @default(false) // Indicates if the document is an external upload
+
@@index([ownerId])
@@index([teamId])
@@index([folderId])
@@@ -219,143 -229,6 +231,57 @@@ enum DocumentStorageType
VERCEL_BLOB
}
- enum LinkType {
- DOCUMENT_LINK
- DATAROOM_LINK
- }
-
- enum LinkAudienceType {
- GENERAL
- GROUP
- TEAM
- }
-
- model Link {
- id String @id @default(cuid())
- document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade)
- documentId String? // This can be nullable, representing links without documents
- dataroom Dataroom? @relation(fields: [dataroomId], references: [id], onDelete: Cascade)
- dataroomId String? // This can be nullable, representing links without datarooms
- linkType LinkType @default(DOCUMENT_LINK) // This will store the type of the link
- url String? @unique
- name String? // Link name
- slug String? // Link slug for pretty URLs
- expiresAt DateTime? // Optional expiration date
- password String? // Optional password for link protection
- allowList String[] // Array of emails and domains allowed to view the document
- denyList String[] // Array of emails and domains denied to view the document
- emailProtected Boolean @default(true) // Optional email protection
- emailAuthenticated Boolean @default(false) // Optional email authentication flag
- allowDownload Boolean? @default(false) // Optional give user a option to allow to download the document
- isArchived Boolean @default(false) // Indicates if the link is archived
- views View[]
- domain Domain? @relation(fields: [domainId], references: [id], onDelete: SetNull)
- domainId String? // This can be nullable, representing links without custom domains
- domainSlug String? // This will store the domain's slug even if the domain is deleted
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
- enableNotification Boolean? @default(true) // Optional give user a option to pause/resume the notifications
- enableFeedback Boolean? @default(false) // Optional give user a option to enable the reactions toolbar
- enableQuestion Boolean? @default(false) // Optional give user a option to enable the question feedback
- enableScreenshotProtection Boolean? @default(false) // Optional give user a option to enable the screenshot protection
- feedback Feedback?
- enableAgreement Boolean? @default(false) // Optional give user a option to enable the terms and conditions
- agreement Agreement? @relation(fields: [agreementId], references: [id], onDelete: SetNull)
- agreementId String? // This can be nullable, representing links without agreements
- showBanner Boolean? @default(false) // Optional give user a option to show the banner and end of document signup form
- enableWatermark Boolean? @default(false) // Optional give user a option to enable the watermark
- watermarkConfig Json? // This will store the watermark configuration: {text: "Confidential", isTiled: false, color: "#000000", fontSize: 12, opacity: 0.5, rotation: 30, position: "top-right"}
-
- // group links
- audienceType LinkAudienceType @default(GENERAL) // This will store the audience type of the link
- groupId String?
- group ViewerGroup? @relation(fields: [groupId], references: [id], onDelete: SetNull)
-
- // custom metatags
- metaTitle String? // This will be the meta title of the link
- metaDescription String? // This will be the meta description of the link
- metaImage String? // This will be the meta image of the link
- metaFavicon String? // This will be the meta favicon of the link
- enableCustomMetatag Boolean? @default(false) // Optional give user a option to enable the custom metatag
-
- teamId String?
- team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)
-
- customFields CustomField[]
- taggedItems TaggedItem[]
-
- @@unique([domainSlug, slug])
- @@index([documentId])
- @@index([teamId])
- }
-
+enum TaggableItemType {
+ LINK
+ DOCUMENT
+ DATAROOM
+}
+
+model Tag {
+ id String @id @default(uuid())
+ name String
+ color String
+ description String?
+ teamId String
+ team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+ createdBy String?
+ taggedItems TaggedItem[]
+
+ @@unique([teamId, name])
+ @@index([teamId])
+ @@index([name])
+ @@index([id])
+}
+
+model TaggedItem {
+ id String @id @default(uuid())
+ tagId String
+ tag Tag @relation(fields: [tagId], references: [id], onDelete: Cascade)
+ itemType TaggableItemType
+ createdAt DateTime @default(now())
+ taggedBy String?
+
+ linkId String?
+ link Link? @relation(fields: [linkId], references: [id], onDelete: Cascade)
+
+ documentId String?
+ document Document? @relation(fields: [documentId], references: [id])
+
+ dataroomId String?
+ dataroom Dataroom? @relation(fields: [dataroomId], references: [id])
+
+ @@index([itemType, linkId])
+ @@index([itemType, documentId])
+ @@index([itemType, dataroomId])
+ @@index([tagId, linkId])
+ @@index([tagId, documentId])
+ @@index([tagId, dataroomId])
+}
+
- model LinkPreset {
- id String @id @default(cuid())
- name String
- teamId String
- team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
+
- enableCustomMetaTag Boolean? @default(false) // Optional give user a option to enable the custom metatag
- metaTitle String? // This will be the meta title of the link
- metaDescription String? // This will be the meta description of the link
- metaImage String? // This will be the meta image of the link
- metaFavicon String? // This will be the meta favicon of the link
-
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
-
- @@index([teamId])
- }
+
model Domain {
id String @id @default(cuid())
slug String @unique