Skip to content

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

feat: send notifications to ADMIN and MANAGER

Marc Seitz2776a595b234
diff --git a/lib/emails/send-viewed-document.ts b/lib/emails/send-viewed-document.ts
index ef05c0db..05bd52c0 100644
--- a/lib/emails/send-viewed-document.ts
+++ b/lib/emails/send-viewed-document.ts
@@ -7,11 +7,13 @@ export const sendViewedDocumentEmail = async ({
documentId,
documentName,
viewerEmail,
+ teamMembers,
}: {
ownerEmail: string | null;
documentId: string;
documentName: string;
viewerEmail: string | null;
+ teamMembers?: string[];
}) => {
const emailTemplate = ViewedDocumentEmail({
documentId,
@@ -25,6 +27,7 @@ export const sendViewedDocumentEmail = async ({
const data = await sendEmail({
to: ownerEmail,
+ cc: teamMembers,
subject: `Your document has been viewed: ${documentName}`,
react: emailTemplate,
test: process.env.NODE_ENV === "development",
diff --git a/lib/resend.ts b/lib/resend.ts
index c4dfc55e..08f7beab 100644
--- a/lib/resend.ts
+++ b/lib/resend.ts
@@ -15,6 +15,7 @@ export const sendEmail = async ({
marketing,
system,
test,
+ cc,
}: {
to: string;
subject: string;
@@ -22,6 +23,7 @@ export const sendEmail = async ({
marketing?: boolean;
system?: boolean;
test?: boolean;
+ cc?: string | string[];
}) => {
if (!resend) {
// Throw an error if resend is not initialized
@@ -36,6 +38,7 @@ export const sendEmail = async ({
? "Papermark <[email protected]>"
: "Marc from Papermark <[email protected]>",
to: test ? "[email protected]" : to,
+ cc: cc,
reply_to: marketing ? "[email protected]" : undefined,
subject,
react,
diff --git a/lib/types.ts b/lib/types.ts
index 00579501..348a3d21 100644
--- a/lib/types.ts
+++ b/lib/types.ts
@@ -227,7 +227,7 @@ export interface TeamDetail {
};
}[];
users: {
- role: "ADMIN" | "MEMBER";
+ role: "ADMIN" | "MANAGER" | "MEMBER";
teamId: string;
user: {
email: string;
diff --git a/pages/api/jobs/send-notification.ts b/pages/api/jobs/send-notification.ts
index 8884506d..438fe829 100644
--- a/pages/api/jobs/send-notification.ts
+++ b/pages/api/jobs/send-notification.ts
@@ -36,6 +36,7 @@ export default async function handle(
viewerEmail: string | null;
linkId: string;
document: {
+ teamId: string;
id: string;
name: string;
owner: {
@@ -56,6 +57,7 @@ export default async function handle(
linkId: true,
document: {
select: {
+ teamId: true,
id: true,
name: true,
owner: {
@@ -83,6 +85,21 @@ export default async function handle(
return;
}
+ // Update the view to mark it as viewed
+ const users = await prisma.userTeam.findMany({
+ where: {
+ role: "MANAGER",
+ teamId: view.document!.teamId,
+ },
+ select: {
+ user: {
+ select: {
+ email: true,
+ },
+ },
+ },
+ });
+
// POST /api/jobs/send-notification
try {
// send email to document owner that document
@@ -91,6 +108,9 @@ export default async function handle(
documentId: view.document!.id,
documentName: view.document!.name,
viewerEmail: view.viewerEmail,
+ teamMembers: users
+ .map((user) => user.user.email!)
+ .filter((email) => email !== view.document!.owner.email),
});
res.status(200).json({ message: "Successfully sent notification", viewId });
diff --git a/prisma/migrations/20240521000000_add_manager_role/migration.sql b/prisma/migrations/20240521000000_add_manager_role/migration.sql
new file mode 100644
index 00000000..83d4b02c
--- /dev/null
+++ b/prisma/migrations/20240521000000_add_manager_role/migration.sql
@@ -0,0 +1,3 @@
+-- AlterEnum
+ALTER TYPE "Role" ADD VALUE 'MANAGER';
+
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index a7553a0d..93fd700a 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -95,6 +95,7 @@ model Brand {
enum Role {
ADMIN
+ MANAGER
MEMBER
}