Compare commits

..

15 Commits

Author SHA1 Message Date
Ephraim Atta-Duncan
ce94cf0051 fix: build errors 2025-02-06 11:55:29 +00:00
Ephraim Atta-Duncan
bccf4cd368 fix: merge conflicts 2025-02-06 11:47:44 +00:00
Ephraim Atta-Duncan
c13988bb8f chore: remove conflicting translations 2025-02-06 11:41:29 +00:00
Ephraim Duncan
9f1831afcb Merge branch 'main' into experiment/self-sign 2024-11-21 17:50:07 +00:00
Ephraim Atta-Duncan
574a7449fa chore: merge with main 2024-11-18 07:30:44 +00:00
Ephraim Duncan
1aee1bb4cd Merge branch 'main' into experiment/self-sign 2024-11-15 20:33:34 +00:00
Ephraim Atta-Duncan
634dc2afd0 fix: self sign team documents 2024-11-15 20:25:09 +00:00
Ephraim Atta-Duncan
21d68f3275 fix: merge conflicts 2024-11-15 11:03:52 +00:00
Ephraim Atta-Duncan
63c98949bb chore: merge main 2024-10-25 14:20:29 +00:00
Ephraim Atta-Duncan
4348a949dd chore: changes based on review 2024-10-18 01:12:43 +00:00
Ephraim Atta-Duncan
2a098f89fa chore: add tests for self signing 2024-10-17 13:17:44 +00:00
Ephraim Atta-Duncan
bb805ea93b fix: audit logs 2024-10-16 23:29:40 +00:00
Ephraim Atta-Duncan
cc8b972fbc fix: recipient status stuck on uncompleted 2024-10-16 19:32:46 +00:00
Ephraim Atta-Duncan
b55c419074 chore: minor changes 2024-10-16 19:03:14 +00:00
Ephraim Atta-Duncan
f9e3993519 feat: avoid sending document if the owner is the only recipient 2024-10-16 17:10:01 +00:00
38 changed files with 681 additions and 1651 deletions

View File

@@ -6,6 +6,7 @@ import { useRouter, useSearchParams } from 'next/navigation';
import { msg } from '@lingui/macro';
import { useLingui } from '@lingui/react';
import { useSession } from 'next-auth/react';
import { isValidLanguageCode } from '@documenso/lib/constants/i18n';
import {
@@ -55,6 +56,7 @@ export const EditDocumentForm = ({
const router = useRouter();
const searchParams = useSearchParams();
const team = useOptionalCurrentTeam();
const { data: session } = useSession();
const [isDocumentPdfLoaded, setIsDocumentPdfLoaded] = useState(false);
@@ -134,6 +136,18 @@ export const EditDocumentForm = ({
},
});
const { mutateAsync: selfSignDocument } = trpc.document.selfSignDocument.useMutation({
...DO_NOT_INVALIDATE_QUERY_ON_MUTATION,
onSuccess: (newData) => {
utils.document.getDocumentWithDetailsById.setData(
{
documentId: initialDocument.id,
},
(oldData) => ({ ...(oldData || initialDocument), ...newData }),
);
},
});
const { mutateAsync: setPasswordForDocument } =
trpc.document.setPasswordForDocument.useMutation();
@@ -269,10 +283,22 @@ export const EditDocumentForm = ({
}
}
// Router refresh is here to clear the router cache for when navigating to /documents.
router.refresh();
const hasSameOwnerAsRecipient =
recipients.length === 1 && recipients[0].email === session?.user?.email;
setStep('subject');
if (hasSameOwnerAsRecipient) {
await selfSignDocument({
documentId: document.id,
teamId: team?.id,
});
router.push(`/sign/${recipients[0].token}`);
} else {
// Router refresh is here to clear the router cache for when navigating to /documents.
router.refresh();
setStep('subject');
}
} catch (err) {
console.error(err);

View File

@@ -47,22 +47,50 @@ import { Tooltip, TooltipContent, TooltipTrigger } from '@documenso/ui/primitive
import type { Toast } from '@documenso/ui/primitives/use-toast';
import { useToast } from '@documenso/ui/primitives/use-toast';
const ZAddRecipientsForNewDocumentSchema = z.object({
distributeDocument: z.boolean(),
useCustomDocument: z.boolean().default(false),
customDocumentData: z
.any()
.refine((data) => data instanceof File || data === undefined)
.optional(),
recipients: z.array(
z.object({
id: z.number(),
email: z.string().email(),
name: z.string(),
signingOrder: z.number().optional(),
}),
),
});
const ZAddRecipientsForNewDocumentSchema = z
.object({
distributeDocument: z.boolean(),
useCustomDocument: z.boolean().default(false),
customDocumentData: z
.any()
.refine((data) => data instanceof File || data === undefined)
.optional(),
recipients: z.array(
z.object({
id: z.number(),
email: z.string().email(),
name: z.string(),
signingOrder: z.number().optional(),
}),
),
})
// Display exactly which rows are duplicates.
.superRefine((items, ctx) => {
const uniqueEmails = new Map<string, number>();
for (const [index, recipients] of items.recipients.entries()) {
const email = recipients.email.toLowerCase();
const firstFoundIndex = uniqueEmails.get(email);
if (firstFoundIndex === undefined) {
uniqueEmails.set(email, index);
continue;
}
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Emails must be unique',
path: ['recipients', index, 'email'],
});
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Emails must be unique',
path: ['recipients', firstFoundIndex, 'email'],
});
}
});
type TAddRecipientsForNewDocumentSchema = z.infer<typeof ZAddRecipientsForNewDocumentSchema>;

View File

@@ -336,6 +336,16 @@ export const DocumentHistorySheet = ({
]}
/>
))
.with({ type: DOCUMENT_AUDIT_LOG_TYPE.SELF_SIGN }, ({ data }) => (
<DocumentHistorySheetChanges
values={[
{
key: 'Signed by',
value: data.recipientEmail,
},
]}
/>
))
.with(
{ type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_VISIBILITY_UPDATED },
({ data }) => (

View File

@@ -270,11 +270,12 @@ export const ZGenerateDocumentFromTemplateMutationSchema = z.object({
)
.refine(
(schema) => {
const emails = schema.map((signer) => signer.email.toLowerCase());
const ids = schema.map((signer) => signer.id);
return new Set(ids).size === ids.length;
return new Set(emails).size === emails.length && new Set(ids).size === ids.length;
},
{ message: 'Recipient IDs must be unique' },
{ message: 'Recipient IDs and emails must be unique' },
),
meta: z
.object({

View File

@@ -1,304 +0,0 @@
import { expect, test } from '@playwright/test';
import { seedBlankDocument } from '@documenso/prisma/seed/documents';
import { seedUser } from '@documenso/prisma/seed/users';
import { apiSignin } from '../fixtures/authentication';
test.describe.configure({ mode: 'parallel' });
test('[DOCUMENT_FLOW]: add signature fields for unique recipients', async ({ page }) => {
const user = await seedUser();
const document = await seedBlankDocument(user);
await apiSignin({
page,
email: user.email,
redirectPath: `/documents/${document.id}/edit`,
});
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Signers' })).toBeVisible();
// Add 2 signers.
await page.getByPlaceholder('Email').fill('recipient1@documenso.com');
await page.getByPlaceholder('Name').fill('Recipient 1');
await page.getByRole('button', { name: 'Add Signer' }).click();
await page.getByLabel('Email').nth(1).fill('recipient2@documenso.com');
await page.getByLabel('Name').nth(1).fill('Recipient 2');
// Advanced settings should not be visible for non EE users.
await expect(page.getByLabel('Show advanced settings')).toBeHidden();
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Fields' })).toBeVisible();
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 100,
y: 100,
},
});
await page.getByRole('combobox').click();
await page.getByRole('option', { name: 'Recipient 2 (recipient2@documenso.com)' }).click();
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 200,
y: 100,
},
});
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Distribute Document' })).toBeVisible();
await page.getByRole('button', { name: 'Send' }).click();
await page.waitForURL('**/documents');
await expect(page.getByRole('link', { name: document.title })).toBeVisible();
});
test('[DOCUMENT_FLOW]: add signature fields for duplicate recipients', async ({ page }) => {
const user = await seedUser();
const document = await seedBlankDocument(user);
await apiSignin({
page,
email: user.email,
redirectPath: `/documents/${document.id}/edit`,
});
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Signers' })).toBeVisible();
await page.getByPlaceholder('Email').fill('recipient@documenso.com');
await page.getByPlaceholder('Name').fill('Recipient');
await page.getByRole('button', { name: 'Add Signer' }).click();
await page.getByLabel('Email').nth(1).fill('recipient@documenso.com');
await page.getByLabel('Name').nth(1).fill('Recipient');
await page.getByRole('button', { name: 'Add Signer' }).click();
await page.getByLabel('Email').nth(2).fill('recipient@documenso.com');
await page.getByLabel('Name').nth(2).fill('Recipient');
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Fields' })).toBeVisible();
// Add signature fields for each recipient
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 100,
y: 100,
},
});
await page.getByRole('combobox').click();
await page.getByRole('option', { name: 'Recipient (recipient@documenso.com)' }).nth(1).click();
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 200,
y: 100,
},
});
await page.getByRole('combobox').click();
await page.getByRole('option', { name: 'Recipient (recipient@documenso.com)' }).nth(2).click();
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 300,
y: 100,
},
});
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Distribute Document' })).toBeVisible();
await page.getByRole('button', { name: 'Send' }).click();
await page.waitForURL('**/documents');
await expect(page.getByRole('link', { name: document.title })).toBeVisible();
});
test('[DOCUMENT_FLOW]: add signature fields for recipients with different roles', async ({
page,
}) => {
const user = await seedUser();
const document = await seedBlankDocument(user);
await apiSignin({
page,
email: user.email,
redirectPath: `/documents/${document.id}/edit`,
});
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Signers' })).toBeVisible();
// Add a signer
await page.getByPlaceholder('Email').fill('recipient@documenso.com');
await page.getByPlaceholder('Name').fill('Documenso Recipient');
await page.getByRole('combobox').click();
await page.getByLabel('Needs to sign').click();
await page.getByRole('button', { name: 'Add Signer' }).click();
// Add an approver
await page.getByLabel('Email').nth(1).fill('recipient@documenso.com');
await page.getByLabel('Name').nth(1).fill('Documenso Recipient');
await page.getByRole('combobox').nth(1).click();
await page.getByLabel('Needs to approve').click();
await page.getByRole('button', { name: 'Add Signer' }).click();
// Add a viewer
await page.getByLabel('Email').nth(2).fill('recipient@documenso.com');
await page.getByLabel('Name').nth(2).fill('Documenso Recipient');
await page.getByRole('combobox').nth(2).click();
await page.getByLabel('Needs to view').click();
await page.getByRole('button', { name: 'Add Signer' }).click();
// Add a CC
await page.getByLabel('Email').nth(3).fill('recipient@documenso.com');
await page.getByLabel('Name').nth(3).fill('Documenso Recipient');
await page.getByRole('combobox').nth(3).click();
await page.getByLabel('Receives copy').click();
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Fields' })).toBeVisible();
// Add signature fields for signer and approver
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 100,
y: 100,
},
});
await page.getByRole('combobox').click();
await page
.getByRole('option', { name: 'Documenso Recipient (recipient@documenso.com)' })
.nth(1)
.click();
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 200,
y: 100,
},
});
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Distribute Document' })).toBeVisible();
await page.getByRole('button', { name: 'Send' }).click();
await page.waitForURL('**/documents');
await expect(page.getByRole('link', { name: document.title })).toBeVisible();
});
test('[DOCUMENT_FLOW]: add signature fields for mixed recipients', async ({ page }) => {
const user = await seedUser();
const document = await seedBlankDocument(user);
await apiSignin({
page,
email: user.email,
redirectPath: `/documents/${document.id}/edit`,
});
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Signers' })).toBeVisible();
// First recipient (unique)
await page.getByPlaceholder('Email').fill('recipient1@documenso.com');
await page.getByPlaceholder('Name').fill('First Recipient');
await page.getByRole('combobox').click();
await page.getByLabel('Needs to approve').click();
await page.getByRole('button', { name: 'Add Signer' }).click();
// Second recipient (duplicate of first)
await page.getByLabel('Email').nth(1).fill('recipient1@documenso.com');
await page.getByLabel('Name').nth(1).fill('First Recipient');
await page.getByRole('combobox').nth(1).click();
await page.getByLabel('Needs to view').click();
await page.getByRole('button', { name: 'Add Signer' }).click();
// Third recipient (unique)
await page.getByLabel('Email').nth(2).fill('recipient2@documenso.com');
await page.getByLabel('Name').nth(2).fill('Second Recipient');
await page.getByRole('combobox').nth(2).click();
await page.getByLabel('Needs to sign').click();
await page.getByRole('button', { name: 'Add Signer' }).click();
// Fourth recipient (duplicate of first)
await page.getByLabel('Email').nth(3).fill('recipient1@documenso.com');
await page.getByLabel('Name').nth(3).fill('First Recipient');
await page.getByRole('combobox').nth(3).click();
await page.getByLabel('Receives copy').click();
await page.getByRole('button', { name: 'Add Signer' }).click();
// Fifth recipient (unique)
await page.getByLabel('Email').nth(4).fill('recipient3@documenso.com');
await page.getByLabel('Name').nth(4).fill('Third Recipient');
await page.getByRole('combobox').nth(4).click();
await page.getByLabel('Needs to sign').click();
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Fields' })).toBeVisible();
// Add signature fields for approver and signers
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 100,
y: 100,
},
});
await page.getByRole('combobox').click();
await page.getByRole('option', { name: 'Second Recipient (recipient2@documenso.com)' }).click();
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 200,
y: 100,
},
});
await page.getByRole('combobox').click();
await page.getByRole('option', { name: 'Third Recipient (recipient3@documenso.com)' }).click();
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 300,
y: 100,
},
});
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Distribute Document' })).toBeVisible();
await page.getByRole('button', { name: 'Send' }).click();
await page.waitForURL('**/documents');
await expect(page.getByRole('link', { name: document.title })).toBeVisible();
});

View File

@@ -91,191 +91,3 @@ test('[DOCUMENT_FLOW]: add signers', async ({ page }) => {
await page.getByRole('button', { name: 'Go Back' }).click();
await expect(page.getByRole('heading', { name: 'Add Signers' })).toBeVisible();
});
test('[DOCUMENT_FLOW]: add only recipients with the same email address', async ({ page }) => {
const user = await seedUser();
const document = await seedBlankDocument(user);
await apiSignin({
page,
email: user.email,
redirectPath: `/documents/${document.id}/edit`,
});
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Signers' })).toBeVisible();
await page.getByPlaceholder('Email').fill('recipient@documenso.com');
await page.getByPlaceholder('Name').fill('Recipient');
await page.getByRole('button', { name: 'Add Signer' }).click();
await page.getByLabel('Email').nth(1).fill('recipient@documenso.com');
await page.getByLabel('Name').nth(1).fill('Recipient');
await page.getByRole('button', { name: 'Add Signer' }).click();
await page.getByLabel('Email').nth(2).fill('recipient@documenso.com');
await page.getByLabel('Name').nth(2).fill('Recipient');
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Fields' })).toBeVisible();
await page.getByRole('button', { name: 'Go Back' }).click();
await expect(page.getByRole('heading', { name: 'Add Signers' })).toBeVisible();
});
test('[DOCUMENT_FLOW]: duplicate email recipients', async ({ page }) => {
const user = await seedUser();
const document = await seedBlankDocument(user);
await apiSignin({
page,
email: user.email,
redirectPath: `/documents/${document.id}/edit`,
});
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Signers' })).toBeVisible();
// Add a signer
await page.getByPlaceholder('Email').fill('recipient@documenso.com');
await page.getByPlaceholder('Name').fill('Documenso Recipient');
await page.getByRole('combobox').click();
await page.getByLabel('Needs to sign').click();
await page.getByRole('button', { name: 'Add Signer' }).click();
// Add an approver
await page.getByLabel('Email').nth(1).fill('recipient@documenso.com');
await page.getByLabel('Name').nth(1).fill('Documenso Recipient');
await page.getByRole('combobox').nth(1).click();
await page.getByLabel('Needs to approve').click();
await page.getByRole('button', { name: 'Add Signer' }).click();
// Add a viewer
await page.getByLabel('Email').nth(2).fill('recipient@documenso.com');
await page.getByLabel('Name').nth(2).fill('Documenso Recipient');
await page.getByRole('combobox').nth(2).click();
await page.getByLabel('Needs to view').click();
await page.getByRole('button', { name: 'Add Signer' }).click();
// Add a CC
await page.getByLabel('Email').nth(3).fill('recipient@documenso.com');
await page.getByLabel('Name').nth(3).fill('Documenso Recipient');
await page.getByRole('combobox').nth(3).click();
await page.getByLabel('Receives copy').click();
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Fields' })).toBeVisible();
await page.getByRole('button', { name: 'Go Back' }).click();
await expect(page.getByRole('heading', { name: 'Add Signers' })).toBeVisible();
});
test('[DOCUMENT_FLOW]: same email with different roles', async ({ page }) => {
const user = await seedUser();
const document = await seedBlankDocument(user);
await apiSignin({
page,
email: user.email,
redirectPath: `/documents/${document.id}/edit`,
});
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Signers' })).toBeVisible();
// First recipient (unique)
await page.getByPlaceholder('Email').fill('recipient1@documenso.com');
await page.getByPlaceholder('Name').fill('First Recipient');
await page.getByRole('combobox').click();
await page.getByLabel('Needs to approve').click();
await page.getByRole('button', { name: 'Add Signer' }).click();
// Second recipient (duplicate of first)
await page.getByLabel('Email').nth(1).fill('recipient1@documenso.com');
await page.getByLabel('Name').nth(1).fill('First Recipient');
await page.getByRole('combobox').nth(1).click();
await page.getByLabel('Needs to view').click();
await page.getByRole('button', { name: 'Add Signer' }).click();
// Third recipient (unique)
await page.getByLabel('Email').nth(2).fill('recipient2@documenso.com');
await page.getByLabel('Name').nth(2).fill('Second Recipient');
await page.getByRole('combobox').nth(2).click();
await page.getByLabel('Needs to sign').click();
await page.getByRole('button', { name: 'Add Signer' }).click();
// Fourth recipient (duplicate of first)
await page.getByLabel('Email').nth(3).fill('recipient1@documenso.com');
await page.getByLabel('Name').nth(3).fill('First Recipient');
await page.getByRole('combobox').nth(3).click();
await page.getByLabel('Receives copy').click();
await page.getByRole('button', { name: 'Add Signer' }).click();
// Fifth recipient (unique)
await page.getByLabel('Email').nth(4).fill('recipient3@documenso.com');
await page.getByLabel('Name').nth(4).fill('Third Recipient');
await page.getByRole('combobox').nth(4).click();
await page.getByLabel('Needs to sign').click();
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Fields' })).toBeVisible();
await page.getByRole('button', { name: 'Go Back' }).click();
await expect(page.getByRole('heading', { name: 'Add Signers' })).toBeVisible();
});
test('[DOCUMENT_FLOW]: mixed unique and duplicate recipients', async ({ page }) => {
const user = await seedUser();
const document = await seedBlankDocument(user);
await apiSignin({
page,
email: user.email,
redirectPath: `/documents/${document.id}/edit`,
});
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Signers' })).toBeVisible();
// First recipient (unique)
await page.getByPlaceholder('Email').fill('recipient1@documenso.com');
await page.getByPlaceholder('Name').fill('First Recipient');
await page.getByRole('combobox').click();
await page.getByLabel('Needs to approve').click();
await page.getByRole('button', { name: 'Add Signer' }).click();
// Second recipient (duplicate of first)
await page.getByLabel('Email').nth(1).fill('recipient1@documenso.com');
await page.getByLabel('Name').nth(1).fill('First Recipient');
await page.getByRole('combobox').nth(1).click();
await page.getByLabel('Needs to view').click();
await page.getByRole('button', { name: 'Add Signer' }).click();
// Third recipient (unique)
await page.getByLabel('Email').nth(2).fill('recipient2@documenso.com');
await page.getByLabel('Name').nth(2).fill('Second Recipient');
await page.getByRole('combobox').nth(2).click();
await page.getByLabel('Needs to sign').click();
await page.getByRole('button', { name: 'Add Signer' }).click();
// Fourth recipient (duplicate of first)
await page.getByLabel('Email').nth(3).fill('recipient1@documenso.com');
await page.getByLabel('Name').nth(3).fill('First Recipient');
await page.getByRole('combobox').nth(3).click();
await page.getByLabel('Receives copy').click();
await page.getByRole('button', { name: 'Add Signer' }).click();
// Fifth recipient (unique)
await page.getByLabel('Email').nth(4).fill('recipient3@documenso.com');
await page.getByLabel('Name').nth(4).fill('Third Recipient');
await page.getByRole('combobox').nth(4).click();
await page.getByLabel('Needs to sign').click();
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Fields' })).toBeVisible();
await page.getByRole('button', { name: 'Go Back' }).click();
await expect(page.getByRole('heading', { name: 'Add Signers' })).toBeVisible();
});

View File

@@ -2,7 +2,9 @@ import { expect, test } from '@playwright/test';
import { DateTime } from 'luxon';
import path from 'node:path';
import { getDocumentById } from '@documenso/lib/server-only/document/get-document-by-id';
import { getRecipientByEmail } from '@documenso/lib/server-only/recipient/get-recipient-by-email';
import { getRecipientById } from '@documenso/lib/server-only/recipient/get-recipient-by-id';
import { prisma } from '@documenso/prisma';
import {
DocumentSigningOrder,
@@ -612,7 +614,7 @@ test('[DOCUMENT_FLOW]: should be able to create and sign a document with 3 recip
expect(previousRecipient?.signingStatus).toBe(SigningStatus.SIGNED);
}
await page.goto(`/sign/${recipient?.token}`);
await page.goto(`/sign/${recipient!.token}`);
await expect(page.getByRole('heading', { name: 'Sign Document' })).toBeVisible();
await page.locator(`#field-${recipientField.id}`).getByRole('button').click();
@@ -630,24 +632,22 @@ test('[DOCUMENT_FLOW]: should be able to create and sign a document with 3 recip
await page.getByRole('button', { name: 'Complete' }).click();
await page.getByRole('button', { name: 'Sign' }).click();
await page.waitForURL(`/sign/${recipient?.token}/complete`);
await page.waitForURL(`/sign/${recipient!.token}/complete`);
await expect(page.getByText('Document Signed')).toBeVisible();
const updatedRecipient = await prisma.recipient.findFirst({
where: { id: recipient?.id },
const updatedRecipient = await getRecipientById({
documentId: document.id,
id: recipient!.id,
});
expect(updatedRecipient?.signingStatus).toBe(SigningStatus.SIGNED);
}
// Wait for the document to be signed.
await page.waitForTimeout(5000);
const finalDocument = await prisma.document.findFirst({
where: { id: createdDocument?.id },
});
expect(finalDocument?.status).toBe(DocumentStatus.COMPLETED);
await expect(async () => {
const signedDocument = await getDocumentById({ id: document.id, userId: user.id });
expect(signedDocument?.status).toBe(DocumentStatus.COMPLETED);
}).toPass();
});
test('[DOCUMENT_FLOW]: should prevent out-of-order signing in sequential mode', async ({
@@ -655,7 +655,7 @@ test('[DOCUMENT_FLOW]: should prevent out-of-order signing in sequential mode',
}) => {
const user = await seedUser();
const { document, recipients } = await seedPendingDocumentWithFullFields({
const { recipients } = await seedPendingDocumentWithFullFields({
owner: user,
recipients: ['user1@example.com', 'user2@example.com', 'user3@example.com'],
fields: [FieldType.SIGNATURE],
@@ -682,3 +682,85 @@ test('[DOCUMENT_FLOW]: should prevent out-of-order signing in sequential mode',
await expect(page).not.toHaveURL(`/sign/${activeRecipient?.token}/waiting`);
await expect(page.getByRole('heading', { name: 'Sign Document' })).toBeVisible();
});
test('[DOCUMENT_FLOW]: should be able to self sign a document', async ({ page }) => {
const user = await seedUser();
const document = await seedBlankDocument(user);
await apiSignin({
page,
email: user.email,
redirectPath: `/documents/${document.id}/edit`,
});
const documentTitle = `Self-Signing-${Date.now()}.pdf`;
await expect(page.getByRole('heading', { name: 'General' })).toBeVisible();
await page.getByLabel('Title').fill(documentTitle);
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Signers' })).toBeVisible();
await page.getByRole('button', { name: 'Add myself' }).click();
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Fields' })).toBeVisible();
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 100,
y: 100,
},
});
await page.getByRole('button', { name: 'Sign', exact: true }).click();
const documentRecipients = await prisma.recipient.findMany({
where: {
documentId: document.id,
},
});
const { token, email, id: recipientId } = documentRecipients[0];
expect(documentRecipients.length).toBe(1);
expect(email).toBe(user.email);
await page.waitForURL(`/sign/${token}`);
await expect(page.getByRole('heading', { name: documentTitle })).toBeVisible();
const { status } = await getDocumentByToken(token);
expect(status).toBe(DocumentStatus.PENDING);
const fields = await prisma.field.findMany({
where: { recipientId, documentId: document.id },
});
const recipientField = fields[0];
expect(recipientField).not.toBeNull();
await page.locator(`#field-${recipientField.id}`).getByRole('button').click();
const canvas = page.locator('canvas#signature');
const box = await canvas.boundingBox();
if (box) {
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
await page.mouse.down();
await page.mouse.move(box.x + box.width / 4, box.y + box.height / 4);
await page.mouse.up();
}
await page.getByRole('button', { name: 'Sign', exact: true }).click();
await page.getByRole('button', { name: 'Complete' }).click();
await page.getByRole('button', { name: 'Sign' }).click();
await page.waitForURL(`/sign/${token}/complete`);
await expect(page.getByText('Document Signed')).toBeVisible();
const updatedRecipient = await getRecipientById({ documentId: document.id, id: recipientId });
expect(updatedRecipient?.signingStatus).toBe(SigningStatus.SIGNED);
await expect(async () => {
const signedDocument = await getDocumentById({ id: document.id, userId: user.id });
expect(signedDocument?.status).toBe(DocumentStatus.COMPLETED);
}).toPass();
});

View File

@@ -1,292 +0,0 @@
import { expect, test } from '@playwright/test';
import { seedBlankTemplate } from '@documenso/prisma/seed/templates';
import { seedUser } from '@documenso/prisma/seed/users';
import { apiSignin } from '../fixtures/authentication';
test.describe.configure({ mode: 'parallel' });
test('[TEMPLATE_FLOW]: add signature fields for unique recipients', async ({ page }) => {
const user = await seedUser();
const template = await seedBlankTemplate(user);
await apiSignin({
page,
email: user.email,
redirectPath: `/templates/${template.id}/edit`,
});
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Placeholders' })).toBeVisible();
// Add 2 placeholder recipients.
await page.getByPlaceholder('Email').fill('recipient1@documenso.com');
await page.getByPlaceholder('Name').fill('Recipient 1');
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
await page.getByPlaceholder('Email').nth(1).fill('recipient2@documenso.com');
await page.getByPlaceholder('Name').nth(1).fill('Recipient 2');
// Advanced settings should not be visible for non EE users.
await expect(page.getByLabel('Show advanced settings')).toBeHidden();
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Fields' })).toBeVisible();
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 100,
y: 100,
},
});
await page.getByRole('combobox').click();
await page.getByRole('option', { name: 'Recipient 2 (recipient2@documenso.com)' }).click();
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 200,
y: 100,
},
});
await page.getByRole('button', { name: 'Save Template' }).click();
await page.waitForURL('**/templates');
await expect(page.getByRole('link', { name: template.title })).toBeVisible();
});
test('[TEMPLATE_FLOW]: add signature fields for duplicate recipients', async ({ page }) => {
const user = await seedUser();
const template = await seedBlankTemplate(user);
await apiSignin({
page,
email: user.email,
redirectPath: `/templates/${template.id}/edit`,
});
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Placeholders' })).toBeVisible();
await page.getByPlaceholder('Email').fill('recipient@documenso.com');
await page.getByPlaceholder('Name').fill('Recipient');
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
await page.getByPlaceholder('Email').nth(1).fill('recipient@documenso.com');
await page.getByPlaceholder('Name').nth(1).fill('Recipient');
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
await page.getByPlaceholder('Email').nth(2).fill('recipient@documenso.com');
await page.getByPlaceholder('Name').nth(2).fill('Recipient');
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Fields' })).toBeVisible();
// Add signature fields for each recipient
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 100,
y: 100,
},
});
await page.getByRole('combobox').click();
await page.getByRole('option', { name: 'Recipient (recipient@documenso.com)' }).nth(1).click();
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 200,
y: 100,
},
});
await page.getByRole('combobox').click();
await page.getByRole('option', { name: 'Recipient (recipient@documenso.com)' }).nth(2).click();
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 300,
y: 100,
},
});
await page.getByRole('button', { name: 'Save Template' }).click();
await page.waitForURL('**/templates');
await expect(page.getByRole('link', { name: template.title })).toBeVisible();
});
test('[TEMPLATE_FLOW]: add signature fields for recipients with different roles', async ({
page,
}) => {
const user = await seedUser();
const template = await seedBlankTemplate(user);
await apiSignin({
page,
email: user.email,
redirectPath: `/templates/${template.id}/edit`,
});
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Placeholders' })).toBeVisible();
// Add a placeholder recipient
await page.getByPlaceholder('Email').fill('recipient@documenso.com');
await page.getByPlaceholder('Name').fill('Documenso Recipient');
await page.getByRole('combobox').click();
await page.getByLabel('Needs to sign').click();
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
// Add an approver
await page.getByPlaceholder('Email').nth(1).fill('recipient@documenso.com');
await page.getByPlaceholder('Name').nth(1).fill('Documenso Recipient');
await page.getByRole('combobox').nth(1).click();
await page.getByLabel('Needs to approve').click();
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
// Add a viewer
await page.getByPlaceholder('Email').nth(2).fill('recipient@documenso.com');
await page.getByPlaceholder('Name').nth(2).fill('Documenso Recipient');
await page.getByRole('combobox').nth(2).click();
await page.getByLabel('Needs to view').click();
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
// Add a CC
await page.getByPlaceholder('Email').nth(3).fill('recipient@documenso.com');
await page.getByPlaceholder('Name').nth(3).fill('Documenso Recipient');
await page.getByRole('combobox').nth(3).click();
await page.getByLabel('Receives copy').click();
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Fields' })).toBeVisible();
// Add signature fields for signer and approver
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 100,
y: 100,
},
});
await page.getByRole('combobox').click();
await page
.getByRole('option', { name: 'Documenso Recipient (recipient@documenso.com)' })
.nth(1)
.click();
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 200,
y: 100,
},
});
await page.getByRole('button', { name: 'Save Template' }).click();
await page.waitForURL('**/templates');
await expect(page.getByRole('link', { name: template.title })).toBeVisible();
});
test('[TEMPLATE_FLOW]: add signature fields for mixed recipients', async ({ page }) => {
const user = await seedUser();
const template = await seedBlankTemplate(user);
await apiSignin({
page,
email: user.email,
redirectPath: `/templates/${template.id}/edit`,
});
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Placeholders' })).toBeVisible();
// First placeholder recipient (unique)
await page.getByPlaceholder('Email').fill('recipient1@documenso.com');
await page.getByPlaceholder('Name').fill('First Recipient');
await page.getByRole('combobox').click();
await page.getByLabel('Needs to approve').click();
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
// Second placeholder recipient (duplicate of first)
await page.getByPlaceholder('Email').nth(1).fill('recipient1@documenso.com');
await page.getByPlaceholder('Name').nth(1).fill('First Recipient');
await page.getByRole('combobox').nth(1).click();
await page.getByLabel('Needs to view').click();
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
// Third placeholder recipient (unique)
await page.getByPlaceholder('Email').nth(2).fill('recipient2@documenso.com');
await page.getByPlaceholder('Name').nth(2).fill('Second Recipient');
await page.getByRole('combobox').nth(2).click();
await page.getByLabel('Needs to sign').click();
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
// Fourth placeholder recipient (duplicate of first)
await page.getByPlaceholder('Email').nth(3).fill('recipient1@documenso.com');
await page.getByPlaceholder('Name').nth(3).fill('First Recipient');
await page.getByRole('combobox').nth(3).click();
await page.getByLabel('Receives copy').click();
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
// Fifth placeholder recipient (unique)
await page.getByPlaceholder('Email').nth(4).fill('recipient3@documenso.com');
await page.getByPlaceholder('Name').nth(4).fill('Third Recipient');
await page.getByRole('combobox').nth(4).click();
await page.getByLabel('Needs to sign').click();
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Fields' })).toBeVisible();
// Add signature fields for approver and signers
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 100,
y: 100,
},
});
await page.getByRole('combobox').click();
await page.getByRole('option', { name: 'Second Recipient (recipient2@documenso.com)' }).click();
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 200,
y: 100,
},
});
await page.getByRole('combobox').click();
await page.getByRole('option', { name: 'Third Recipient (recipient3@documenso.com)' }).click();
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 300,
y: 100,
},
});
await page.getByRole('button', { name: 'Save Template' }).click();
await page.waitForURL('**/templates');
await expect(page.getByRole('link', { name: template.title })).toBeVisible();
});

View File

@@ -98,135 +98,3 @@ test('[TEMPLATE_FLOW]: add placeholder', async ({ page }) => {
// Advanced settings should not be visible for non EE users.
await expect(page.getByLabel('Show advanced settings')).toBeHidden();
});
test('[TEMPLATE_FLOW]: duplicate recipients', async ({ page }) => {
const user = await seedUser();
const template = await seedBlankTemplate(user);
await apiSignin({
page,
email: user.email,
redirectPath: `/templates/${template.id}/edit`,
});
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Placeholder' })).toBeVisible();
await page.getByPlaceholder('Email').fill('recipient@documenso.com');
await page.getByPlaceholder('Name').fill('Recipient');
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
await page.getByPlaceholder('Email').nth(1).fill('recipient@documenso.com');
await page.getByPlaceholder('Name').nth(1).fill('Recipient');
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
await page.getByPlaceholder('Email').nth(2).fill('recipient@documenso.com');
await page.getByPlaceholder('Name').nth(2).fill('Recipient');
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Fields' })).toBeVisible();
await page.getByRole('button', { name: 'Go Back' }).click();
await expect(page.getByRole('heading', { name: 'Add Placeholder' })).toBeVisible();
});
test('[TEMPLATE_FLOW]: same email different roles', async ({ page }) => {
const user = await seedUser();
const template = await seedBlankTemplate(user);
await apiSignin({
page,
email: user.email,
redirectPath: `/templates/${template.id}/edit`,
});
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Placeholder' })).toBeVisible();
// Add a signer
await page.getByPlaceholder('Email').fill('recipient@documenso.com');
await page.getByPlaceholder('Name').fill('Documenso Recipient');
await page.getByRole('combobox').click();
await page.getByLabel('Needs to sign').click();
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
// Add an approver
await page.getByPlaceholder('Email').nth(1).fill('recipient@documenso.com');
await page.getByPlaceholder('Name').nth(1).fill('Documenso Recipient');
await page.getByRole('combobox').nth(1).click();
await page.getByLabel('Needs to approve').click();
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
// Add a viewer
await page.getByPlaceholder('Email').nth(2).fill('recipient@documenso.com');
await page.getByPlaceholder('Name').nth(2).fill('Documenso Recipient');
await page.getByRole('combobox').nth(2).click();
await page.getByLabel('Needs to view').click();
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
// Add a CC
await page.getByPlaceholder('Email').nth(3).fill('recipient@documenso.com');
await page.getByPlaceholder('Name').nth(3).fill('Documenso Recipient');
await page.getByRole('combobox').nth(3).click();
await page.getByLabel('Receives copy').click();
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Fields' })).toBeVisible();
await page.getByRole('button', { name: 'Go Back' }).click();
await expect(page.getByRole('heading', { name: 'Add Placeholder' })).toBeVisible();
});
test('[TEMPLATE_FLOW]: mixed recipients', async ({ page }) => {
const user = await seedUser();
const template = await seedBlankTemplate(user);
await apiSignin({
page,
email: user.email,
redirectPath: `/templates/${template.id}/edit`,
});
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Placeholder' })).toBeVisible();
// First recipient (unique)
await page.getByPlaceholder('Email').fill('recipient1@documenso.com');
await page.getByPlaceholder('Name').fill('First Recipient');
await page.getByRole('combobox').click();
await page.getByLabel('Needs to approve').click();
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
// Second recipient (duplicate of first)
await page.getByPlaceholder('Email').nth(1).fill('recipient1@documenso.com');
await page.getByPlaceholder('Name').nth(1).fill('First Recipient');
await page.getByRole('combobox').nth(1).click();
await page.getByLabel('Needs to view').click();
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
// Third recipient (unique)
await page.getByPlaceholder('Email').nth(2).fill('recipient2@documenso.com');
await page.getByPlaceholder('Name').nth(2).fill('Second Recipient');
await page.getByRole('combobox').nth(2).click();
await page.getByLabel('Needs to sign').click();
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
// Fourth recipient (duplicate of first)
await page.getByPlaceholder('Email').nth(3).fill('recipient1@documenso.com');
await page.getByPlaceholder('Name').nth(3).fill('First Recipient');
await page.getByRole('combobox').nth(3).click();
await page.getByLabel('Receives copy').click();
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
// Fifth recipient (unique)
await page.getByPlaceholder('Email').nth(4).fill('recipient3@documenso.com');
await page.getByPlaceholder('Name').nth(4).fill('Third Recipient');
await page.getByRole('combobox').nth(4).click();
await page.getByLabel('Needs to sign').click();
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Fields' })).toBeVisible();
await page.getByRole('button', { name: 'Go Back' }).click();
await expect(page.getByRole('heading', { name: 'Add Placeholder' })).toBeVisible();
});

View File

@@ -110,13 +110,14 @@ test('[TEMPLATE]: should create a document from a template', async ({ page }) =>
await page.getByRole('button', { name: 'Save template' }).click();
// Use template
await page.waitForURL('**/templates');
await page.waitForURL('/templates');
await page.getByRole('button', { name: 'Use Template' }).click();
await page.getByRole('button', { name: 'Create as draft' }).click();
// Review that the document was created with the correct values.
await page.waitForURL(/\/documents\/\d+/);
const documentId = Number(page.url().match(/\/documents\/(\d+)/)?.[1]);
await page.waitForURL(/documents/);
const documentId = Number(page.url().split('/').pop());
const document = await prisma.document.findFirstOrThrow({
where: {
@@ -249,8 +250,9 @@ test('[TEMPLATE]: should create a team document from a team template', async ({
await page.getByRole('button', { name: 'Create as draft' }).click();
// Review that the document was created with the correct values.
await page.waitForURL(/\/documents\/\d+/);
const documentId = Number(page.url().match(/\/documents\/(\d+)/)?.[1]);
await page.waitForURL(/documents/);
const documentId = Number(page.url().split('/').pop());
const document = await prisma.document.findFirstOrThrow({
where: {
@@ -351,8 +353,9 @@ test('[TEMPLATE]: should create a document from a template with custom document'
await page.getByRole('button', { name: 'Create as draft' }).click();
// Review that the document was created with the custom document data
await page.waitForURL(/\/documents\/\d+/);
const documentId = Number(page.url().match(/\/documents\/(\d+)/)?.[1]);
await page.waitForURL(/documents/);
const documentId = Number(page.url().split('/').pop());
const document = await prisma.document.findFirstOrThrow({
where: {
@@ -431,8 +434,9 @@ test('[TEMPLATE]: should create a team document from a template with custom docu
await page.getByRole('button', { name: 'Create as draft' }).click();
// Review that the document was created with the custom document data
await page.waitForURL(/\/documents\/\d+/);
const documentId = Number(page.url().match(/\/documents\/(\d+)/)?.[1]);
await page.waitForURL(/documents/);
const documentId = Number(page.url().split('/').pop());
const document = await prisma.document.findFirstOrThrow({
where: {
@@ -496,8 +500,9 @@ test('[TEMPLATE]: should create a document from a template using template docume
await page.getByRole('button', { name: 'Create as draft' }).click();
// Review that the document was created with the template's document data
await page.waitForURL(/\/documents\/\d+/);
const documentId = Number(page.url().match(/\/documents\/(\d+)/)?.[1]);
await page.waitForURL(/documents/);
const documentId = Number(page.url().split('/').pop());
const document = await prisma.document.findFirstOrThrow({
where: {
@@ -586,8 +591,9 @@ test('[TEMPLATE]: should persist document visibility when creating from template
await page.getByRole('button', { name: 'Create as draft' }).click();
// Review that the document was created with the correct visibility
await page.waitForURL(/\/documents\/\d+/);
const documentId = Number(page.url().match(/\/documents\/(\d+)/)?.[1]);
await page.waitForURL(/documents/);
const documentId = Number(page.url().split('/').pop());
const document = await prisma.document.findFirstOrThrow({
where: {
@@ -610,368 +616,3 @@ test('[TEMPLATE]: should persist document visibility when creating from template
// Template should not be visible to regular member
await expect(page.getByRole('button', { name: 'Use Template' })).not.toBeVisible();
});
/**
* This test verifies that we can create a document from a template with duplicate recipients
**/
test('[TEMPLATE]: should create a document from a template with duplicate recipients', async ({
page,
}) => {
const user = await seedUser();
const template = await seedBlankTemplate(user);
const isBillingEnabled =
process.env.NEXT_PUBLIC_FEATURE_BILLING_ENABLED === 'true' && enterprisePriceId;
await seedUserSubscription({
userId: user.id,
priceId: enterprisePriceId,
});
await apiSignin({
page,
email: user.email,
redirectPath: `/templates/${template.id}/edit`,
});
// Set template title.
await page.getByLabel('Title').fill('TEMPLATE_TITLE');
// Set template document access.
await page.getByTestId('documentAccessSelectValue').click();
await page.getByLabel('Require account').getByText('Require account').click();
await expect(page.getByTestId('documentAccessSelectValue')).toContainText('Require account');
// Set EE action auth.
if (isBillingEnabled) {
await page.getByTestId('documentActionSelectValue').click();
await page.getByLabel('Require passkey').getByText('Require passkey').click();
await expect(page.getByTestId('documentActionSelectValue')).toContainText('Require passkey');
}
// Set email options.
await page.getByRole('button', { name: 'Email Options' }).click();
await page.getByLabel('Subject (Optional)').fill('SUBJECT');
await page.getByLabel('Message (Optional)').fill('MESSAGE');
// Set advanced options.
await page.getByRole('button', { name: 'Advanced Options' }).click();
await page.locator('button').filter({ hasText: 'YYYY-MM-DD HH:mm a' }).click();
await page.getByLabel('DD/MM/YYYY').click();
await page.locator('.time-zone-field').click();
await page.getByRole('option', { name: 'Etc/UTC' }).click();
await page.getByLabel('Redirect URL').fill('https://documenso.com');
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Placeholder' })).toBeVisible();
// Add 2 signers.
await page.getByPlaceholder('Email').fill('recipient1@documenso.com');
await page.getByPlaceholder('Name').fill('Recipient 1');
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
await page.getByPlaceholder('Email').nth(1).fill('recipient1@documenso.com');
await page.getByPlaceholder('Name').nth(1).fill('Recipient 1');
// Apply require passkey for Recipient 1.
if (isBillingEnabled) {
await page.getByLabel('Show advanced settings').check();
await page.getByRole('combobox').first().click();
await page.getByLabel('Require passkey').click();
}
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Fields' })).toBeVisible();
// Add signature fields for each recipient
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 100,
y: 100,
},
});
await page.getByRole('combobox').click();
await page.getByRole('option', { name: 'Recipient 1 (recipient1@documenso.com)' }).nth(1).click();
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 200,
y: 100,
},
});
await page.getByRole('button', { name: 'Save template' }).click();
// Use template
await page.waitForURL('**/templates');
await page.getByRole('button', { name: 'Use Template' }).click();
await page.getByRole('button', { name: 'Create as draft' }).click();
// Review that the document was created with the correct values.
await page.waitForURL(/\/documents\/\d+/);
const documentId = Number(page.url().match(/\/documents\/(\d+)/)?.[1]);
const document = await prisma.document.findFirstOrThrow({
where: {
id: documentId,
},
include: {
recipients: true,
documentMeta: true,
},
});
const documentAuth = extractDocumentAuthMethods({
documentAuth: document.authOptions,
});
expect(document.title).toEqual('TEMPLATE_TITLE');
expect(documentAuth.documentAuthOption.globalAccessAuth).toEqual('ACCOUNT');
expect(documentAuth.documentAuthOption.globalActionAuth).toEqual(
isBillingEnabled ? 'PASSKEY' : null,
);
expect(document.documentMeta?.dateFormat).toEqual('dd/MM/yyyy hh:mm a');
expect(document.documentMeta?.message).toEqual('MESSAGE');
expect(document.documentMeta?.redirectUrl).toEqual('https://documenso.com');
expect(document.documentMeta?.subject).toEqual('SUBJECT');
expect(document.documentMeta?.timezone).toEqual('Etc/UTC');
const recipientOne = document.recipients[0];
const recipientTwo = document.recipients[1];
const recipientOneAuth = extractDocumentAuthMethods({
documentAuth: document.authOptions,
recipientAuth: recipientOne.authOptions,
});
const recipientTwoAuth = extractDocumentAuthMethods({
documentAuth: document.authOptions,
recipientAuth: recipientTwo.authOptions,
});
if (isBillingEnabled) {
expect(recipientOneAuth.derivedRecipientActionAuth).toEqual('PASSKEY');
}
expect(recipientOneAuth.derivedRecipientAccessAuth).toEqual('ACCOUNT');
expect(recipientTwoAuth.derivedRecipientAccessAuth).toEqual('ACCOUNT');
await page.getByRole('link', { name: 'Edit' }).click();
await expect(page.getByRole('heading', { name: 'General' })).toBeVisible();
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Signers' })).toBeVisible();
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Fields' })).toBeVisible();
await expect(page.getByText('SignatureRE').first()).toBeVisible();
await page.getByRole('combobox').click();
await page.getByRole('option', { name: 'recipient1@documenso.com' }).nth(1).click();
await expect(page.getByText('SignatureRE').nth(1)).toBeVisible();
});
/**
* This test verifies that we can create a document from a template with a mix of duplicate and unique recipients
**/
test('[TEMPLATE]: should create a document from a template with mixed duplicate and unique recipients', async ({
page,
}) => {
const user = await seedUser();
const template = await seedBlankTemplate(user);
const isBillingEnabled =
process.env.NEXT_PUBLIC_FEATURE_BILLING_ENABLED === 'true' && enterprisePriceId;
await seedUserSubscription({
userId: user.id,
priceId: enterprisePriceId,
});
await apiSignin({
page,
email: user.email,
redirectPath: `/templates/${template.id}/edit`,
});
// Set template title.
await page.getByLabel('Title').fill('TEMPLATE_MIXED_RECIPIENTS');
// Set template document access.
await page.getByTestId('documentAccessSelectValue').click();
await page.getByLabel('Require account').getByText('Require account').click();
await expect(page.getByTestId('documentAccessSelectValue')).toContainText('Require account');
// Set EE action auth.
if (isBillingEnabled) {
await page.getByTestId('documentActionSelectValue').click();
await page.getByLabel('Require passkey').getByText('Require passkey').click();
await expect(page.getByTestId('documentActionSelectValue')).toContainText('Require passkey');
}
// Set email options.
await page.getByRole('button', { name: 'Email Options' }).click();
await page.getByLabel('Subject (Optional)').fill('SUBJECT');
await page.getByLabel('Message (Optional)').fill('MESSAGE');
// Set advanced options.
await page.getByRole('button', { name: 'Advanced Options' }).click();
await page.locator('button').filter({ hasText: 'YYYY-MM-DD HH:mm a' }).click();
await page.getByLabel('DD/MM/YYYY').click();
await page.locator('.time-zone-field').click();
await page.getByRole('option', { name: 'Etc/UTC' }).click();
await page.getByLabel('Redirect URL').fill('https://documenso.com');
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Placeholder' })).toBeVisible();
// Add 4 signers: 2 duplicates of recipient1 and 2 unique recipients
await page.getByPlaceholder('Email').fill('recipient1@documenso.com');
await page.getByPlaceholder('Name').fill('Recipient 1');
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
await page.getByPlaceholder('Email').nth(1).fill('recipient2@documenso.com');
await page.getByPlaceholder('Name').nth(1).fill('Recipient 2');
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
await page.getByPlaceholder('Email').nth(2).fill('recipient1@documenso.com');
await page.getByPlaceholder('Name').nth(2).fill('Recipient 1');
await page.getByRole('button', { name: 'Add Placeholder Recipient' }).click();
await page.getByPlaceholder('Email').nth(3).fill('recipient3@documenso.com');
await page.getByPlaceholder('Name').nth(3).fill('Recipient 3');
// Apply require passkey for first instance of Recipient 1
if (isBillingEnabled) {
await page.getByLabel('Show advanced settings').check();
await page.getByRole('combobox').first().click();
await page.getByLabel('Require passkey').click();
}
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Fields' })).toBeVisible();
// Add signature fields for each recipient
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 100,
y: 100,
},
});
await page.getByRole('combobox').click();
await page.getByRole('option', { name: 'Recipient 2 (recipient2@documenso.com)' }).click();
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 200,
y: 100,
},
});
await page.getByRole('combobox').click();
await page.getByRole('option', { name: 'Recipient 1 (recipient1@documenso.com)' }).nth(1).click();
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 300,
y: 100,
},
});
await page.getByRole('combobox').click();
await page.getByRole('option', { name: 'Recipient 3 (recipient3@documenso.com)' }).click();
await page.getByRole('button', { name: 'Signature' }).click();
await page.locator('canvas').click({
position: {
x: 400,
y: 100,
},
});
await page.getByRole('button', { name: 'Save template' }).click();
// Use template
await page.waitForURL('**/templates');
await page.getByRole('button', { name: 'Use Template' }).click();
await page.getByRole('button', { name: 'Create as draft' }).click();
// Review that the document was created with the correct values.
await page.waitForURL(/\/documents\/\d+/);
const documentId = Number(page.url().match(/\/documents\/(\d+)/)?.[1]);
const document = await prisma.document.findFirstOrThrow({
where: {
id: documentId,
},
include: {
recipients: {
orderBy: {
email: 'asc',
},
},
documentMeta: true,
},
});
const documentAuth = extractDocumentAuthMethods({
documentAuth: document.authOptions,
});
expect(document.title).toEqual('TEMPLATE_MIXED_RECIPIENTS');
expect(documentAuth.documentAuthOption.globalAccessAuth).toEqual('ACCOUNT');
expect(documentAuth.documentAuthOption.globalActionAuth).toEqual(
isBillingEnabled ? 'PASSKEY' : null,
);
expect(document.documentMeta?.dateFormat).toEqual('dd/MM/yyyy hh:mm a');
expect(document.documentMeta?.message).toEqual('MESSAGE');
expect(document.documentMeta?.redirectUrl).toEqual('https://documenso.com');
expect(document.documentMeta?.subject).toEqual('SUBJECT');
expect(document.documentMeta?.timezone).toEqual('Etc/UTC');
// Check auth settings for first instance of recipient1
const firstRecipientOne = document.recipients[0];
const firstRecipientOneAuth = extractDocumentAuthMethods({
documentAuth: document.authOptions,
recipientAuth: firstRecipientOne.authOptions,
});
if (isBillingEnabled) {
expect(firstRecipientOneAuth.derivedRecipientActionAuth).toEqual('PASSKEY');
}
expect(firstRecipientOneAuth.derivedRecipientAccessAuth).toEqual('ACCOUNT');
await page.getByRole('link', { name: 'Edit' }).click();
await expect(page.getByRole('heading', { name: 'General' })).toBeVisible();
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Signers' })).toBeVisible();
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.getByRole('heading', { name: 'Add Fields' })).toBeVisible();
await expect(page.getByText('SignatureRE').first()).toBeVisible();
await page.getByRole('combobox').click();
await page.getByRole('option', { name: 'recipient2@documenso.com' }).click();
await expect(page.getByText('SignatureRE').nth(1)).toBeVisible();
await page.getByRole('combobox').click();
await page.getByRole('option', { name: 'recipient1@documenso.com' }).nth(1).click();
await expect(page.getByText('SignatureRE').nth(2)).toBeVisible();
await page.getByRole('combobox').click();
await page.getByRole('option', { name: 'recipient3@documenso.com' }).click();
await expect(page.getByText('SignatureRE').nth(3)).toBeVisible();
});

View File

@@ -0,0 +1,177 @@
import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-logs';
import type { ApiRequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
import { putPdfFile } from '@documenso/lib/universal/upload/put-file';
import { createDocumentAuditLogData } from '@documenso/lib/utils/document-audit-logs';
import { prisma } from '@documenso/prisma';
import { DocumentStatus, RecipientRole, SendStatus, SigningStatus } from '@documenso/prisma/client';
import { jobs } from '../../jobs/client';
import { getFile } from '../../universal/upload/get-file';
import { insertFormValuesInPdf } from '../pdf/insert-form-values-in-pdf';
export type SelfSignDocumentOptions = {
documentId: number;
userId: number;
teamId?: number;
requestMetadata?: ApiRequestMetadata;
};
export const selfSignDocument = async ({
documentId,
userId,
teamId,
requestMetadata,
}: SelfSignDocumentOptions) => {
const user = await prisma.user.findFirstOrThrow({
where: {
id: userId,
},
select: {
id: true,
name: true,
email: true,
},
});
const document = await prisma.document.findUnique({
where: {
id: documentId,
...(teamId
? {
team: {
id: teamId,
members: {
some: {
userId,
},
},
},
}
: {
userId,
teamId: null,
}),
},
include: {
recipients: {
orderBy: [{ signingOrder: { sort: 'asc', nulls: 'last' } }, { id: 'asc' }],
},
documentMeta: true,
documentData: true,
},
});
if (!document) {
throw new Error('Document not found');
}
if (document.recipients.length === 0) {
throw new Error('Document has no recipients');
}
if (document.recipients.length !== 1 || document.recipients[0].email !== user.email) {
throw new Error('Invalid document for self-signing');
}
if (document.status === DocumentStatus.COMPLETED) {
throw new Error('Can not sign completed document');
}
const { documentData } = document;
if (!documentData || !documentData.data) {
throw new Error('Document data not found');
}
if (document.formValues) {
const file = await getFile(documentData);
const prefilled = await insertFormValuesInPdf({
pdf: Buffer.from(file),
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
formValues: document.formValues as Record<string, string | number | boolean>,
});
const newDocumentData = await putPdfFile({
name: document.title,
type: 'application/pdf',
arrayBuffer: async () => Promise.resolve(prefilled),
});
const result = await prisma.document.update({
where: {
id: document.id,
},
data: {
documentDataId: newDocumentData.id,
},
});
Object.assign(document, result);
}
const recipientHasNoActionToTake =
document.recipients[0].role === RecipientRole.CC ||
document.recipients[0].signingStatus === SigningStatus.SIGNED;
if (recipientHasNoActionToTake) {
await jobs.triggerJob({
name: 'internal.seal-document',
payload: {
documentId,
requestMetadata: requestMetadata?.requestMetadata,
},
});
return await prisma.document.findFirstOrThrow({
where: {
id: documentId,
},
include: {
recipients: true,
},
});
}
const updatedDocument = await prisma.$transaction(async (tx) => {
if (document.status === DocumentStatus.DRAFT) {
await tx.documentAuditLog.create({
data: createDocumentAuditLogData({
type: DOCUMENT_AUDIT_LOG_TYPE.SELF_SIGN,
documentId: document.id,
requestMetadata: requestMetadata?.requestMetadata,
user,
data: {
recipientId: document.recipients[0].id,
recipientEmail: document.recipients[0].email,
recipientName: document.recipients[0].name,
recipientRole: document.recipients[0].role,
},
}),
});
}
await tx.recipient.update({
where: {
id: document.recipients[0].id,
},
data: {
sendStatus: SendStatus.SENT,
},
});
return await tx.document.update({
where: {
id: documentId,
},
data: {
status: DocumentStatus.PENDING,
},
include: {
recipients: true,
},
});
});
return updatedDocument;
};

View File

@@ -94,7 +94,7 @@ export const sendDocument = async ({
const { documentData } = document;
if (!documentData.data) {
if (!documentData || !documentData.data) {
throw new Error('Document data not found');
}

View File

@@ -72,22 +72,6 @@ export const setFieldsForDocument = async ({
});
}
// Check that every signer has a signature field
const signers = document.recipients.filter((recipient) => recipient.role === 'SIGNER');
const hasEverySignerSignature = signers.every((signer) =>
fields.some(
(field) =>
(field.type === FieldType.SIGNATURE || field.type === FieldType.FREE_SIGNATURE) &&
field.recipientId === signer.id,
),
);
if (!hasEverySignerSignature) {
throw new AppError(AppErrorCode.INVALID_REQUEST, {
message: 'Every signer must have at least one signature field',
});
}
if (document.completedAt) {
throw new AppError(AppErrorCode.INVALID_REQUEST, {
message: 'Document already complete',
@@ -110,7 +94,9 @@ export const setFieldsForDocument = async ({
const linkedFields = fields.map((field) => {
const existing = existingFields.find((existingField) => existingField.id === field.id);
const recipient = document.recipients.find((recipient) => recipient.id === field.recipientId);
const recipient = document.recipients.find(
(recipient) => recipient.email.toLowerCase() === field.signerEmail.toLowerCase(),
);
// Each field MUST have a recipient associated with it.
if (!recipient) {
@@ -250,8 +236,10 @@ export const setFieldsForDocument = async ({
},
recipient: {
connect: {
documentId,
id: field.recipientId,
documentId_email: {
documentId,
email: fieldSignerEmail,
},
},
},
},
@@ -352,7 +340,6 @@ type FieldData = {
id?: number | null;
type: FieldType;
signerEmail: string;
recipientId: number;
pageNumber: number;
pageX: number;
pageY: number;

View File

@@ -22,7 +22,6 @@ export type SetFieldsForTemplateOptions = {
fields: {
id?: number | null;
type: FieldType;
signerId: number;
signerEmail: string;
pageNumber: number;
pageX: number;
@@ -58,29 +57,12 @@ export const setFieldsForTemplate = async ({
teamId: null,
}),
},
include: {
recipients: true,
},
});
if (!template) {
throw new Error('Template not found');
}
// Check that every signer has a signature field
const signers = template.recipients.filter((recipient) => recipient.role === 'SIGNER');
const hasEverySignerSignature = signers.every((signer) =>
fields.some(
(field) =>
(field.type === FieldType.SIGNATURE || field.type === FieldType.FREE_SIGNATURE) &&
field.signerId === signer.id,
),
);
if (!hasEverySignerSignature) {
throw new Error('Every signer must have at least one signature field');
}
const existingFields = await prisma.field.findMany({
where: {
templateId,
@@ -198,8 +180,10 @@ export const setFieldsForTemplate = async ({
},
recipient: {
connect: {
templateId,
id: field.signerId,
templateId_email: {
templateId,
email: field.signerEmail.toLowerCase(),
},
},
},
},

View File

@@ -125,12 +125,16 @@ export const setDocumentRecipients = async ({
const removedRecipients = existingRecipients.filter(
(existingRecipient) =>
!normalizedRecipients.find((recipient) => recipient.id === existingRecipient.id),
!normalizedRecipients.find(
(recipient) =>
recipient.id === existingRecipient.id || recipient.email === existingRecipient.email,
),
);
const linkedRecipients = normalizedRecipients.map((recipient) => {
const existing = existingRecipients.find(
(existingRecipient) => existingRecipient.id === recipient.id,
(existingRecipient) =>
existingRecipient.id === recipient.id || existingRecipient.email === recipient.email,
);
if (

View File

@@ -103,7 +103,10 @@ export const setTemplateRecipients = async ({
const removedRecipients = existingRecipients.filter(
(existingRecipient) =>
!normalizedRecipients.find((recipient) => recipient.id === existingRecipient.id),
!normalizedRecipients.find(
(recipient) =>
recipient.id === existingRecipient.id || recipient.email === existingRecipient.email,
),
);
if (template.directLink !== null) {
@@ -130,10 +133,14 @@ export const setTemplateRecipients = async ({
const linkedRecipients = normalizedRecipients.map((recipient) => {
const existing = existingRecipients.find(
(existingRecipient) => existingRecipient.id === recipient.id,
(existingRecipient) =>
existingRecipient.id === recipient.id || existingRecipient.email === recipient.email,
);
return { ...recipient, _persisted: existing };
return {
...recipient,
_persisted: existing,
};
});
const persistedRecipients = await prisma.$transaction(async (tx) => {

View File

@@ -141,8 +141,10 @@ export const createDocumentFromTemplateLegacy = async ({
return await prisma.recipient.upsert({
where: {
documentId: document.id,
id: existingRecipient?.id,
documentId_email: {
documentId: document.id,
email: existingRecipient?.email ?? recipient.email,
},
},
update: {
name: recipient.name,

View File

@@ -256,21 +256,10 @@ export const createDocumentFromTemplate = async ({
},
});
const recipientMapping = new Map<number, number>();
template.recipients.forEach((templateRecipient, index) => {
const documentRecipient = document.recipients[index];
if (documentRecipient) {
recipientMapping.set(templateRecipient.id, documentRecipient.id);
}
});
let fieldsToCreate: Omit<Field, 'id' | 'secondaryId' | 'templateId'>[] = [];
finalRecipients.forEach(({ templateRecipientId, fields }) => {
const documentRecipientId = recipientMapping.get(templateRecipientId);
const recipient = document.recipients.find((r) => r.id === documentRecipientId);
Object.values(finalRecipients).forEach(({ email, fields }) => {
const recipient = document.recipients.find((recipient) => recipient.email === email);
if (!recipient) {
throw new Error('Recipient not found.');

View File

@@ -13,6 +13,7 @@ import { ZRecipientAccessAuthTypesSchema, ZRecipientActionAuthTypesSchema } from
export const ZDocumentAuditLogTypeSchema = z.enum([
// Document actions.
'EMAIL_SENT',
'SELF_SIGN',
// Document modification events.
'FIELD_CREATED',
@@ -181,6 +182,14 @@ export const ZDocumentAuditLogEventEmailSentSchema = z.object({
}),
});
/**
* Event: Self sign
*/
export const ZDocumentAuditLogSelfSignSchema = z.object({
type: z.literal(DOCUMENT_AUDIT_LOG_TYPE.SELF_SIGN),
data: ZBaseRecipientDataSchema,
});
/**
* Event: Document completed.
*/
@@ -566,6 +575,7 @@ export const ZDocumentAuditLogBaseSchema = z.object({
export const ZDocumentAuditLogSchema = ZDocumentAuditLogBaseSchema.and(
z.union([
ZDocumentAuditLogEventEmailSentSchema,
ZDocumentAuditLogSelfSignSchema,
ZDocumentAuditLogEventDocumentCompletedSchema,
ZDocumentAuditLogEventDocumentCreatedSchema,
ZDocumentAuditLogEventDocumentDeletedSchema,

View File

@@ -369,16 +369,6 @@ export const formatDocumentAuditLogAction = (
identified: result,
};
})
.with({ type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_REJECTED }, ({ data }) => {
const userName = prefix || _(msg`Recipient`);
const result = msg`${userName} rejected the document`;
return {
anonymous: result,
identified: result,
};
})
.with({ type: DOCUMENT_AUDIT_LOG_TYPE.EMAIL_SENT }, ({ data }) => ({
anonymous: data.isResending ? msg`Email resent` : msg`Email sent`,
identified: data.isResending
@@ -389,6 +379,14 @@ export const formatDocumentAuditLogAction = (
anonymous: msg`Document completed`,
identified: msg`Document completed`,
}))
.with({ type: DOCUMENT_AUDIT_LOG_TYPE.SELF_SIGN }, () => ({
anonymous: msg`Self-signed document`,
identified: msg`${prefix} self-signed the document`,
}))
.with({ type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_REJECTED }, ({ data }) => ({
anonymous: msg`Document rejected`,
identified: msg`${prefix} rejected the document: ${data.reason}`,
}))
.exhaustive();
return {

View File

@@ -1,2 +0,0 @@
-- DropIndex
DROP INDEX "Recipient_documentId_email_key";

View File

@@ -1,5 +0,0 @@
-- DropIndex
DROP INDEX "Recipient_templateId_email_key";
-- CreateIndex
CREATE INDEX "Recipient_email_idx" ON "Recipient"("email");

View File

@@ -443,10 +443,11 @@ model Recipient {
fields Field[]
signatures Signature[]
@@unique([documentId, email])
@@unique([templateId, email])
@@index([documentId])
@@index([templateId])
@@index([token])
@@index([email])
}
enum FieldType {

View File

@@ -5,18 +5,6 @@ import { hashSync } from '@documenso/lib/server-only/auth/hash';
import { prisma } from '..';
import { DocumentDataType, DocumentSource, Role, TeamMemberRole } from '../client';
import { seedPendingDocument } from './documents';
import { seedDirectTemplate, seedTemplate } from './templates';
const createDocumentData = async ({ documentData }: { documentData: string }) => {
return prisma.documentData.create({
data: {
type: DocumentDataType.BYTES_64,
data: documentData,
initialData: documentData,
},
});
};
export const seedDatabase = async () => {
const examplePdf = fs
@@ -51,80 +39,35 @@ export const seedDatabase = async () => {
update: {},
});
for (let i = 1; i <= 4; i++) {
const documentData = await createDocumentData({ documentData: examplePdf });
await prisma.document.create({
data: {
source: DocumentSource.DOCUMENT,
title: `Example Document ${i}`,
documentDataId: documentData.id,
userId: exampleUser.id,
recipients: {
create: {
name: String(adminUser.name),
email: adminUser.email,
token: Math.random().toString(36).slice(2, 9),
},
},
},
});
}
for (let i = 1; i <= 4; i++) {
const documentData = await createDocumentData({ documentData: examplePdf });
await prisma.document.create({
data: {
source: DocumentSource.DOCUMENT,
title: `Document ${i}`,
documentDataId: documentData.id,
userId: adminUser.id,
recipients: {
create: {
name: String(exampleUser.name),
email: exampleUser.email,
token: Math.random().toString(36).slice(2, 9),
},
},
},
});
}
await seedPendingDocument(exampleUser, [adminUser], {
key: 'example-pending',
createDocumentOptions: {
title: 'Pending Document',
const examplePdfData = await prisma.documentData.upsert({
where: {
id: 'clmn0kv5k0000pe04vcqg5zla',
},
create: {
id: 'clmn0kv5k0000pe04vcqg5zla',
type: DocumentDataType.BYTES_64,
data: examplePdf,
initialData: examplePdf,
},
update: {},
});
await seedPendingDocument(adminUser, [exampleUser], {
key: 'admin-pending',
createDocumentOptions: {
title: 'Pending Document',
await prisma.document.create({
data: {
source: DocumentSource.DOCUMENT,
title: 'Example Document',
documentDataId: examplePdfData.id,
userId: exampleUser.id,
recipients: {
create: {
name: String(adminUser.name),
email: adminUser.email,
token: Math.random().toString(36).slice(2, 9),
},
},
},
});
await Promise.all([
seedTemplate({
title: 'Template 1',
userId: exampleUser.id,
}),
seedDirectTemplate({
title: 'Direct Template 1',
userId: exampleUser.id,
}),
seedTemplate({
title: 'Template 1',
userId: adminUser.id,
}),
seedDirectTemplate({
title: 'Direct Template 1',
userId: adminUser.id,
}),
]);
const testUsers = [
'test@documenso.com',
'test2@documenso.com',

View File

@@ -20,6 +20,7 @@ import { getDocumentWithDetailsById } from '@documenso/lib/server-only/document/
import { moveDocumentToTeam } from '@documenso/lib/server-only/document/move-document-to-team';
import { resendDocument } from '@documenso/lib/server-only/document/resend-document';
import { searchDocumentsWithKeyword } from '@documenso/lib/server-only/document/search-documents-with-keyword';
import { selfSignDocument } from '@documenso/lib/server-only/document/self-sign-document';
import { sendDocument } from '@documenso/lib/server-only/document/send-document';
import { updateDocument } from '@documenso/lib/server-only/document/update-document';
import { symmetricEncrypt } from '@documenso/lib/universal/crypto';
@@ -50,6 +51,7 @@ import {
ZMoveDocumentToTeamSchema,
ZResendDocumentMutationSchema,
ZSearchDocumentsMutationSchema,
ZSelfSignDocumentMutationSchema,
ZSetPasswordForDocumentMutationSchema,
ZSetSigningOrderForDocumentMutationSchema,
ZSuccessResponseSchema,
@@ -467,6 +469,28 @@ export const documentRouter = router({
});
}),
selfSignDocument: authenticatedProcedure
.input(ZSelfSignDocumentMutationSchema)
.mutation(async ({ input, ctx }) => {
try {
const { documentId, teamId } = input;
return await selfSignDocument({
userId: ctx.user.id,
documentId,
teamId,
requestMetadata: ctx.metadata,
});
} catch (err) {
console.error(err);
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to self sign this document. Please try again later.',
});
}
}),
/**
* @public
*

View File

@@ -192,6 +192,14 @@ export const ZCreateDocumentV2RequestSchema = z.object({
.optional(),
}),
)
.refine(
(recipients) => {
const emails = recipients.map((recipient) => recipient.email);
return new Set(emails).size === emails.length;
},
{ message: 'Recipients must have unique emails' },
)
.optional(),
meta: z
.object({
@@ -285,6 +293,11 @@ export const ZDistributeDocumentRequestSchema = z.object({
.optional(),
});
export const ZSelfSignDocumentMutationSchema = z.object({
documentId: z.number(),
teamId: z.number().optional(),
});
export const ZDistributeDocumentResponseSchema = ZDocumentLiteSchema;
export const ZSetPasswordForDocumentMutationSchema = z.object({

View File

@@ -232,9 +232,8 @@ export const fieldRouter = router({
teamId,
fields: fields.map((field) => ({
id: field.nativeId,
recipientId: field.recipientId,
type: field.type,
signerEmail: field.signerEmail,
type: field.type,
pageNumber: field.pageNumber,
pageX: field.pageX,
pageY: field.pageY,
@@ -430,7 +429,6 @@ export const fieldRouter = router({
teamId,
fields: fields.map((field) => ({
id: field.nativeId,
signerId: field.recipientId,
signerEmail: field.signerEmail,
type: field.type,
pageNumber: field.pageNumber,

View File

@@ -112,15 +112,13 @@ export const ZSetDocumentFieldsRequestSchema = z.object({
z.object({
formId: z.string().min(1),
nativeId: z.number().optional(),
id: z.number().optional(),
type: z.nativeEnum(FieldType),
recipientId: z.number(),
signerEmail: z.string().min(1),
pageNumber: ZFieldPageNumberSchema,
pageX: ZFieldPageXSchema,
pageY: ZFieldPageYSchema,
pageWidth: ZFieldWidthSchema,
pageHeight: ZFieldHeightSchema,
pageNumber: z.number().min(1),
pageX: z.number().min(0),
pageY: z.number().min(0),
pageWidth: z.number().min(0),
pageHeight: z.number().min(0),
fieldMeta: ZFieldMetaSchema,
}),
),
@@ -138,8 +136,6 @@ export const ZSetFieldsForTemplateRequestSchema = z.object({
nativeId: z.number().optional(),
type: z.nativeEnum(FieldType),
signerEmail: z.string().min(1),
recipientId: z.number().min(1),
signerId: z.number().min(1),
pageNumber: z.number().min(1),
pageX: z.number().min(0),
pageY: z.number().min(0),

View File

@@ -49,7 +49,16 @@ export const ZCreateDocumentRecipientResponseSchema = ZRecipientLiteSchema;
export const ZCreateDocumentRecipientsRequestSchema = z.object({
documentId: z.number(),
recipients: z.array(ZCreateRecipientSchema),
recipients: z.array(ZCreateRecipientSchema).refine(
(recipients) => {
const emails = recipients.map((recipient) => recipient.email.toLowerCase());
return new Set(emails).size === emails.length;
},
{
message: 'Recipients must have unique emails',
},
),
});
export const ZCreateDocumentRecipientsResponseSchema = z.object({
@@ -65,7 +74,18 @@ export const ZUpdateDocumentRecipientResponseSchema = ZRecipientSchema;
export const ZUpdateDocumentRecipientsRequestSchema = z.object({
documentId: z.number(),
recipients: z.array(ZUpdateRecipientSchema),
recipients: z.array(ZUpdateRecipientSchema).refine(
(recipients) => {
const emails = recipients
.filter((recipient) => recipient.email !== undefined)
.map((recipient) => recipient.email?.toLowerCase());
return new Set(emails).size === emails.length;
},
{
message: 'Recipients must have unique emails',
},
),
});
export const ZUpdateDocumentRecipientsResponseSchema = z.object({
@@ -76,19 +96,29 @@ export const ZDeleteDocumentRecipientRequestSchema = z.object({
recipientId: z.number(),
});
export const ZSetDocumentRecipientsRequestSchema = z.object({
documentId: z.number(),
recipients: z.array(
z.object({
nativeId: z.number().optional(),
email: z.string().toLowerCase().email().min(1),
name: z.string(),
role: z.nativeEnum(RecipientRole),
signingOrder: z.number().optional(),
actionAuth: ZRecipientActionAuthTypesSchema.optional().nullable(),
}),
),
});
export const ZSetDocumentRecipientsRequestSchema = z
.object({
documentId: z.number(),
recipients: z.array(
z.object({
nativeId: z.number().optional(),
email: z.string().toLowerCase().email().min(1),
name: z.string(),
role: z.nativeEnum(RecipientRole),
signingOrder: z.number().optional(),
actionAuth: ZRecipientActionAuthTypesSchema.optional().nullable(),
}),
),
})
.refine(
(schema) => {
const emails = schema.recipients.map((recipient) => recipient.email.toLowerCase());
return new Set(emails).size === emails.length;
},
// Dirty hack to handle errors when .root is populated for an array type
{ message: 'Recipients must have unique emails', path: ['recipients__root'] },
);
export const ZSetDocumentRecipientsResponseSchema = z.object({
recipients: ZRecipientLiteSchema.array(),
@@ -103,7 +133,16 @@ export const ZCreateTemplateRecipientResponseSchema = ZRecipientLiteSchema;
export const ZCreateTemplateRecipientsRequestSchema = z.object({
templateId: z.number(),
recipients: z.array(ZCreateRecipientSchema),
recipients: z.array(ZCreateRecipientSchema).refine(
(recipients) => {
const emails = recipients.map((recipient) => recipient.email);
return new Set(emails).size === emails.length;
},
{
message: 'Recipients must have unique emails',
},
),
});
export const ZCreateTemplateRecipientsResponseSchema = z.object({
@@ -119,7 +158,18 @@ export const ZUpdateTemplateRecipientResponseSchema = ZRecipientSchema;
export const ZUpdateTemplateRecipientsRequestSchema = z.object({
templateId: z.number(),
recipients: z.array(ZUpdateRecipientSchema),
recipients: z.array(ZUpdateRecipientSchema).refine(
(recipients) => {
const emails = recipients
.filter((recipient) => recipient.email !== undefined)
.map((recipient) => recipient.email);
return new Set(emails).size === emails.length;
},
{
message: 'Recipients must have unique emails',
},
),
});
export const ZUpdateTemplateRecipientsResponseSchema = z.object({
@@ -130,19 +180,29 @@ export const ZDeleteTemplateRecipientRequestSchema = z.object({
recipientId: z.number(),
});
export const ZSetTemplateRecipientsRequestSchema = z.object({
templateId: z.number(),
recipients: z.array(
z.object({
nativeId: z.number().optional(),
email: z.string().toLowerCase().email().min(1),
name: z.string(),
role: z.nativeEnum(RecipientRole),
signingOrder: z.number().optional(),
actionAuth: ZRecipientActionAuthTypesSchema.optional().nullable(),
}),
),
});
export const ZSetTemplateRecipientsRequestSchema = z
.object({
templateId: z.number(),
recipients: z.array(
z.object({
nativeId: z.number().optional(),
email: z.string().toLowerCase().email().min(1),
name: z.string(),
role: z.nativeEnum(RecipientRole),
signingOrder: z.number().optional(),
actionAuth: ZRecipientActionAuthTypesSchema.optional().nullable(),
}),
),
})
.refine(
(schema) => {
const emails = schema.recipients.map((recipient) => recipient.email);
return new Set(emails).size === emails.length;
},
// Dirty hack to handle errors when .root is populated for an array type
{ message: 'Recipients must have unique emails', path: ['recipients__root'] },
);
export const ZSetTemplateRecipientsResponseSchema = z.object({
recipients: ZRecipientLiteSchema.array(),

View File

@@ -51,7 +51,12 @@ export const ZCreateDocumentFromTemplateRequestSchema = z.object({
name: z.string().optional(),
}),
)
.describe('The information of the recipients to create the document with.'),
.describe('The information of the recipients to create the document with.')
.refine((recipients) => {
const emails = recipients.map((signer) => signer.email);
return new Set(emails).size === emails.length;
}, 'Recipients must have unique emails'),
distributeDocument: z
.boolean()
.describe('Whether to create the document as pending and distribute it to recipients.')

View File

@@ -21,6 +21,7 @@ import {
Type,
User,
} from 'lucide-react';
import { useSession } from 'next-auth/react';
import { useFieldArray, useForm } from 'react-hook-form';
import { useHotkeys } from 'react-hotkeys-hook';
import { prop, sortBy } from 'remeda';
@@ -92,7 +93,6 @@ export type FieldFormType = {
pageY: number;
pageWidth: number;
pageHeight: number;
recipientId: number;
signerEmail: string;
fieldMeta?: FieldMeta;
};
@@ -121,6 +121,7 @@ export const AddFieldsFormPartial = ({
teamId,
}: AddFieldsFormProps) => {
const { toast } = useToast();
const { data: session } = useSession();
const { _ } = useLingui();
const [isMissingSignatureDialogVisible, setIsMissingSignatureDialogVisible] = useState(false);
@@ -144,7 +145,6 @@ export const AddFieldsFormPartial = ({
pageY: Number(field.positionY),
pageWidth: Number(field.width),
pageHeight: Number(field.height),
recipientId: field.recipientId,
signerEmail:
recipients.find((recipient) => recipient.id === field.recipientId)?.email ?? '',
fieldMeta: field.fieldMeta ? ZFieldMetaSchema.parse(field.fieldMeta) : undefined,
@@ -350,7 +350,6 @@ export const AddFieldsFormPartial = ({
pageY,
pageWidth: fieldPageWidth,
pageHeight: fieldPageHeight,
recipientId: selectedSigner.id,
signerEmail: selectedSigner.email,
fieldMeta: undefined,
};
@@ -444,7 +443,6 @@ export const AddFieldsFormPartial = ({
const newField: TAddFieldsFormSchema['fields'][0] = {
...structuredClone(lastActiveField),
formId: nanoid(12),
recipientId: selectedSigner?.id ?? lastActiveField.recipientId,
signerEmail: selectedSigner?.email ?? lastActiveField.signerEmail,
pageX: lastActiveField.pageX + 3,
pageY: lastActiveField.pageY + 3,
@@ -453,7 +451,7 @@ export const AddFieldsFormPartial = ({
append(newField);
}
},
[append, lastActiveField, selectedSigner?.id, selectedSigner?.email, toast],
[append, lastActiveField, selectedSigner?.email, toast],
);
const onFieldPaste = useCallback(
@@ -466,15 +464,13 @@ export const AddFieldsFormPartial = ({
append({
...copiedField,
formId: nanoid(12),
recipientId: selectedSigner?.id ?? copiedField.recipientId,
signerEmail: selectedSigner?.email ?? copiedField.signerEmail,
pageX: copiedField.pageX + 3,
pageY: copiedField.pageY + 3,
});
}
},
[append, fieldClipboard, selectedSigner?.id, selectedSigner?.email],
[append, fieldClipboard, selectedSigner?.email],
);
useEffect(() => {
@@ -564,6 +560,10 @@ export const AddFieldsFormPartial = ({
);
}, [recipientsByRole]);
const hasSameOwnerAsRecipient =
recipientsByRole.SIGNER.length === 1 &&
recipientsByRole.SIGNER[0].email === session?.user?.email;
const handleAdvancedSettings = () => {
setShowAdvancedSettings((prev) => !prev);
};
@@ -573,7 +573,7 @@ export const AddFieldsFormPartial = ({
localFields.some(
(field) =>
(field.type === FieldType.SIGNATURE || field.type === FieldType.FREE_SIGNATURE) &&
field.recipientId === signer.id,
field.signerEmail === signer.email,
),
);
@@ -643,7 +643,7 @@ export const AddFieldsFormPartial = ({
{isDocumentPdfLoaded &&
localFields.map((field, index) => {
const recipientIndex = recipients.findIndex((r) => r.id === field.recipientId);
const recipientIndex = recipients.findIndex((r) => r.email === field.signerEmail);
const hasFieldError =
emptyCheckboxFields.find((f) => f.formId === field.formId) ||
emptyRadioFields.find((f) => f.formId === field.formId) ||
@@ -655,7 +655,7 @@ export const AddFieldsFormPartial = ({
recipientIndex={recipientIndex === -1 ? 0 : recipientIndex}
field={field}
disabled={
selectedSigner?.id !== field.recipientId ||
selectedSigner?.email !== field.signerEmail ||
!canRecipientBeModified(selectedSigner, fields)
}
minHeight={MIN_HEIGHT_PX}
@@ -1138,6 +1138,7 @@ export const AddFieldsFormPartial = ({
documentFlow.onBackStep?.();
}}
goBackLabel={canRenderBackButtonAsRemove ? msg`Remove` : undefined}
goNextLabel={hasSameOwnerAsRecipient ? msg`Sign` : undefined}
onGoNextClick={handleGoNextClick}
/>
</DocumentFlowFormContainerFooter>

View File

@@ -10,7 +10,6 @@ export const ZAddFieldsFormSchema = z.object({
nativeId: z.number().optional(),
type: z.nativeEnum(FieldType),
signerEmail: z.string().min(1),
recipientId: z.number(),
pageNumber: z.number().min(1),
pageX: z.number().min(0),
pageY: z.number().min(0),

View File

@@ -6,22 +6,34 @@ import { ZRecipientActionAuthTypesSchema } from '@documenso/lib/types/document-a
import { ZMapNegativeOneToUndefinedSchema } from './add-settings.types';
import { DocumentSigningOrder, RecipientRole } from '.prisma/client';
export const ZAddSignersFormSchema = z.object({
signers: z.array(
z.object({
formId: z.string().min(1),
nativeId: z.number().optional(),
email: z
.string()
.email({ message: msg`Invalid email`.id })
.min(1),
name: z.string(),
role: z.nativeEnum(RecipientRole),
signingOrder: z.number().optional(),
actionAuth: ZMapNegativeOneToUndefinedSchema.pipe(ZRecipientActionAuthTypesSchema.optional()),
}),
),
signingOrder: z.nativeEnum(DocumentSigningOrder),
});
export const ZAddSignersFormSchema = z
.object({
signers: z.array(
z.object({
formId: z.string().min(1),
nativeId: z.number().optional(),
email: z
.string()
.email({ message: msg`Invalid email`.id })
.min(1),
name: z.string(),
role: z.nativeEnum(RecipientRole),
signingOrder: z.number().optional(),
actionAuth: ZMapNegativeOneToUndefinedSchema.pipe(
ZRecipientActionAuthTypesSchema.optional(),
),
}),
),
signingOrder: z.nativeEnum(DocumentSigningOrder),
})
.refine(
(schema) => {
const emails = schema.signers.map((signer) => signer.email.toLowerCase());
return new Set(emails).size === emails.length;
},
// Dirty hack to handle errors when .root is populated for an array type
{ message: msg`Signers must have unique emails`.id, path: ['signers__root'] },
);
export type TAddSignersFormSchema = z.infer<typeof ZAddSignersFormSchema>;

View File

@@ -8,14 +8,19 @@ import { FieldType } from '@documenso/prisma/client';
export const ZDocumentFlowFormSchema = z.object({
title: z.string().min(1),
signers: z.array(
z.object({
formId: z.string().min(1),
nativeId: z.number().optional(),
email: z.string().min(1).email(),
name: z.string(),
}),
),
signers: z
.array(
z.object({
formId: z.string().min(1),
nativeId: z.number().optional(),
email: z.string().min(1).email(),
name: z.string(),
}),
)
.refine((signers) => {
const emails = signers.map((signer) => signer.email);
return new Set(emails).size === emails.length;
}, 'Signers must have unique emails'),
fields: z.array(
z.object({

View File

@@ -60,7 +60,6 @@ import { getSignerColorStyles, useSignerColors } from '../../lib/signer-colors';
import { Checkbox } from '../checkbox';
import type { FieldFormType } from '../document-flow/add-fields';
import { FieldAdvancedSettings } from '../document-flow/field-item-advanced-settings';
import { MissingSignatureFieldDialog } from '../document-flow/missing-signature-field-dialog';
import { Form, FormControl, FormField, FormItem, FormLabel } from '../form/form';
import { useStep } from '../stepper';
import type { TAddTemplateFieldsFormSchema } from './add-template-fields.types';
@@ -111,7 +110,6 @@ export const AddTemplateFieldsFormPartial = ({
const [fieldClipboard, setFieldClipboard] = useState<
TAddTemplateFieldsFormSchema['fields'][0] | null
>(null);
const [isMissingSignatureDialogVisible, setIsMissingSignatureDialogVisible] = useState(false);
const form = useForm<TAddTemplateFieldsFormSchema>({
defaultValues: {
@@ -124,7 +122,6 @@ export const AddTemplateFieldsFormPartial = ({
pageY: Number(field.positionY),
pageWidth: Number(field.width),
pageHeight: Number(field.height),
recipientId: field.recipientId ?? -1,
signerId: field.recipientId ?? -1,
signerEmail:
recipients.find((recipient) => recipient.id === field.recipientId)?.email ?? '',
@@ -180,8 +177,6 @@ export const AddTemplateFieldsFormPartial = ({
formId: nanoid(12),
signerEmail: selectedSigner?.email ?? lastActiveField.signerEmail,
signerId: selectedSigner?.id ?? lastActiveField.signerId,
recipientId:
selectedSigner?.id || lastActiveField.recipientId || lastActiveField.signerId || 0,
signerToken: selectedSigner?.token ?? lastActiveField.signerToken,
pageX: lastActiveField.pageX + 3,
pageY: lastActiveField.pageY + 3,
@@ -206,29 +201,19 @@ export const AddTemplateFieldsFormPartial = ({
event.preventDefault();
const copiedField = structuredClone(fieldClipboard);
const signerIndex = recipients.findIndex((r) => r.id === selectedSigner?.id);
append({
...copiedField,
formId: nanoid(12),
signerEmail: selectedSigner?.email ?? copiedField.signerEmail,
signerId: selectedSigner?.id ?? copiedField.signerId,
recipientId: selectedSigner?.id || copiedField.recipientId || copiedField.signerId || 0,
signerToken: selectedSigner?.token ?? copiedField.signerToken,
signerIndex: signerIndex >= 0 ? signerIndex : 0,
pageX: copiedField.pageX + 3,
pageY: copiedField.pageY + 3,
});
}
},
[
append,
fieldClipboard,
selectedSigner?.email,
selectedSigner?.id,
selectedSigner?.token,
recipients,
],
[append, fieldClipboard, selectedSigner?.email, selectedSigner?.id, selectedSigner?.token],
);
useHotkeys(['ctrl+c', 'meta+c'], (evt) => onFieldCopy(evt));
@@ -334,8 +319,6 @@ export const AddTemplateFieldsFormPartial = ({
pageX -= fieldPageWidth / 2;
pageY -= fieldPageHeight / 2;
const signerIndex = recipients.findIndex((r) => r.id === selectedSigner.id);
append({
formId: nanoid(12),
type: selectedField,
@@ -346,17 +329,14 @@ export const AddTemplateFieldsFormPartial = ({
pageHeight: fieldPageHeight,
signerEmail: selectedSigner.email,
signerId: selectedSigner.id,
recipientId:
selectedSigner.id || lastActiveField?.recipientId || lastActiveField?.signerId || 0,
signerToken: selectedSigner.token ?? '',
signerIndex: signerIndex >= 0 ? signerIndex : 0,
fieldMeta: undefined,
});
setIsFieldWithinBounds(false);
setSelectedField(null);
},
[append, isWithinPageBounds, selectedField, selectedSigner, getPage, recipients],
[append, isWithinPageBounds, selectedField, selectedSigner, getPage],
);
const onFieldResize = useCallback(
@@ -519,23 +499,6 @@ export const AddTemplateFieldsFormPartial = ({
form.setValue('typedSignatureEnabled', value, { shouldDirty: true });
};
const handleGoNextClick = () => {
const everySignerHasSignature = recipientsByRole.SIGNER.every((signer) =>
localFields.some(
(field) =>
(field.type === FieldType.SIGNATURE || field.type === FieldType.FREE_SIGNATURE) &&
field.recipientId === signer.id,
),
);
if (!everySignerHasSignature) {
setIsMissingSignatureDialogVisible(true);
return;
}
void onFormSubmit();
};
return (
<>
{showAdvancedSettings && currentField ? (
@@ -583,15 +546,14 @@ export const AddTemplateFieldsFormPartial = ({
)}
{localFields.map((field, index) => {
const recipientIndex =
field.signerIndex ?? recipients.findIndex((r) => r.id === field.signerId);
const recipientIndex = recipients.findIndex((r) => r.email === field.signerEmail);
return (
<FieldItem
key={index}
recipientIndex={recipientIndex >= 0 ? recipientIndex : 0}
recipientIndex={recipientIndex === -1 ? 0 : recipientIndex}
field={field}
disabled={selectedSigner?.id !== field.signerId}
disabled={selectedSigner?.email !== field.signerEmail}
minHeight={MIN_HEIGHT_PX}
minWidth={MIN_WIDTH_PX}
defaultHeight={DEFAULT_HEIGHT_PX}
@@ -1031,14 +993,9 @@ export const AddTemplateFieldsFormPartial = ({
previousStep();
remove();
}}
onGoNextClick={handleGoNextClick}
onGoNextClick={() => void onFormSubmit()}
/>
</DocumentFlowFormContainerFooter>
<MissingSignatureFieldDialog
isOpen={isMissingSignatureDialogVisible}
onOpenChange={(value) => setIsMissingSignatureDialogVisible(value)}
/>
</div>
</DocumentFlowFormContainerContent>
</>

View File

@@ -11,14 +11,12 @@ export const ZAddTemplateFieldsFormSchema = z.object({
type: z.nativeEnum(FieldType),
signerEmail: z.string().min(1),
signerToken: z.string(),
signerId: z.number(),
recipientId: z.number(),
signerId: z.number().optional(),
pageNumber: z.number().min(1),
pageX: z.number().min(0),
pageY: z.number().min(0),
pageWidth: z.number().min(0),
pageHeight: z.number().min(0),
signerIndex: z.number().min(0),
fieldMeta: ZFieldMetaSchema,
}),
),

View File

@@ -92,7 +92,6 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
actionAuth: undefined,
...generateRecipientPlaceholder(1),
signingOrder: 1,
signerIndex: 0,
},
];
}
@@ -105,7 +104,6 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
role: recipient.role,
actionAuth: ZRecipientAuthOptionsSchema.parse(recipient.authOptions)?.actionAuth ?? undefined,
signingOrder: recipient.signingOrder ?? index + 1,
signerIndex: index,
}));
if (signingOrder === DocumentSigningOrder.SEQUENTIAL) {
@@ -176,35 +174,21 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
});
const onAddPlaceholderSelfRecipient = () => {
const currentSigners = form.getValues('signers');
const nextSignerIndex = currentSigners.length;
appendSigner({
formId: nanoid(12),
name: user?.name ?? '',
email: user?.email ?? '',
role: RecipientRole.SIGNER,
signingOrder:
currentSigners.length > 0
? (currentSigners[currentSigners.length - 1]?.signingOrder ?? 0) + 1
: 1,
signerIndex: nextSignerIndex,
signingOrder: signers.length > 0 ? (signers[signers.length - 1]?.signingOrder ?? 0) + 1 : 1,
});
};
const onAddPlaceholderRecipient = () => {
const currentSigners = form.getValues('signers');
const nextSignerIndex = currentSigners.length;
appendSigner({
formId: nanoid(12),
role: RecipientRole.SIGNER,
...generateRecipientPlaceholder(placeholderRecipientCount),
signingOrder:
currentSigners.length > 0
? (currentSigners[currentSigners.length - 1]?.signingOrder ?? 0) + 1
: 1,
signerIndex: nextSignerIndex,
signingOrder: signers.length > 0 ? (signers[signers.length - 1]?.signingOrder ?? 0) + 1 : 1,
});
setPlaceholderRecipientCount((count) => count + 1);

View File

@@ -5,21 +5,32 @@ import { DocumentSigningOrder, RecipientRole } from '@documenso/prisma/client';
import { ZMapNegativeOneToUndefinedSchema } from '../document-flow/add-settings.types';
export const ZAddTemplatePlacholderRecipientsFormSchema = z.object({
signers: z.array(
z.object({
formId: z.string().min(1),
nativeId: z.number().optional(),
email: z.string().min(1).email(),
name: z.string(),
role: z.nativeEnum(RecipientRole),
signingOrder: z.number().optional(),
signerIndex: z.number().min(0),
actionAuth: ZMapNegativeOneToUndefinedSchema.pipe(ZRecipientActionAuthTypesSchema.optional()),
}),
),
signingOrder: z.nativeEnum(DocumentSigningOrder),
});
export const ZAddTemplatePlacholderRecipientsFormSchema = z
.object({
signers: z.array(
z.object({
formId: z.string().min(1),
nativeId: z.number().optional(),
email: z.string().min(1).email(),
name: z.string(),
role: z.nativeEnum(RecipientRole),
signingOrder: z.number().optional(),
actionAuth: ZMapNegativeOneToUndefinedSchema.pipe(
ZRecipientActionAuthTypesSchema.optional(),
),
}),
),
signingOrder: z.nativeEnum(DocumentSigningOrder),
})
.refine(
(schema) => {
const emails = schema.signers.map((signer) => signer.email.toLowerCase());
return new Set(emails).size === emails.length;
},
// Dirty hack to handle errors when .root is populated for an array type
{ message: 'Signers must have unique emails', path: ['signers__root'] },
);
export type TAddTemplatePlacholderRecipientsFormSchema = z.infer<
typeof ZAddTemplatePlacholderRecipientsFormSchema