The Open Source DocuSign Alternative.
TypeScript digital-signaturedocument-signingdocusign-alternativee-signatureesignesignaturenext-authnextjsopen-sourcepades-standardpdfpdf-signpdf-signaturepostgresqlprismaself-hostedsigningtypescript
feat: add option to disable Document created from template (#2609)
Catalin Pit5be71cca21ef
diff --git a/apps/remix/app/components/forms/email-preferences-form.tsx b/apps/remix/app/components/forms/email-preferences-form.tsxindex 2dd992676..649d67f7a 100644--- a/apps/remix/app/components/forms/email-preferences-form.tsx+++ b/apps/remix/app/components/forms/email-preferences-form.tsx@@ -219,7 +219,8 @@ export const EmailPreferencesForm = ({<FormDescription><Trans>- Controls the default email settings when new documents or templates are created+ Controls the default email settings when new documents or templates are created.+ Updating these settings will not affect existing documents or templates.</Trans></FormDescription></FormItem>diff --git a/packages/app-tests/e2e/api/v2/envelopes-api.spec.ts b/packages/app-tests/e2e/api/v2/envelopes-api.spec.tsindex ffabac913..27710c6f4 100644--- a/packages/app-tests/e2e/api/v2/envelopes-api.spec.ts+++ b/packages/app-tests/e2e/api/v2/envelopes-api.spec.ts@@ -209,6 +209,7 @@ test.describe('API V2 Envelopes', () => {documentDeleted: false,ownerRecipientExpired: true,ownerDocumentCompleted: true,+ ownerDocumentCreated: true,},},attachments: [diff --git a/packages/app-tests/e2e/envelope-editor-v2/envelope-settings.spec.ts b/packages/app-tests/e2e/envelope-editor-v2/envelope-settings.spec.tsindex 39009f3a6..a5a6f8aad 100644--- a/packages/app-tests/e2e/envelope-editor-v2/envelope-settings.spec.ts+++ b/packages/app-tests/e2e/envelope-editor-v2/envelope-settings.spec.ts@@ -54,6 +54,7 @@ const DB_EXPECTED_VALUES = {documentDeleted: false,ownerDocumentCompleted: false,ownerRecipientExpired: false,+ ownerDocumentCreated: false,},};@@ -138,6 +139,7 @@ const runSettingsFlow = async (await root.locator('#documentDeleted').click();await root.locator('#ownerDocumentCompleted').click();await root.locator('#ownerRecipientExpired').click();+ await root.locator('#ownerDocumentCreated').click();await root.locator('input[name="meta.emailReplyTo"]').fill(TEST_SETTINGS_VALUES.replyTo);await root.locator('input[name="meta.subject"]').fill(TEST_SETTINGS_VALUES.subject);await root.locator('textarea[name="meta.message"]').fill(TEST_SETTINGS_VALUES.message);@@ -207,6 +209,7 @@ const runSettingsFlow = async (await expect(root.locator('#documentDeleted')).toHaveAttribute('aria-checked', 'false');await expect(root.locator('#ownerDocumentCompleted')).toHaveAttribute('aria-checked', 'false');await expect(root.locator('#ownerRecipientExpired')).toHaveAttribute('aria-checked', 'false');+ await expect(root.locator('#ownerDocumentCreated')).toHaveAttribute('aria-checked', 'false');await expect(root.locator('input[name="meta.emailReplyTo"]')).toHaveValue(TEST_SETTINGS_VALUES.replyTo,);diff --git a/packages/app-tests/e2e/organisations/organisation-team-preferences.spec.ts b/packages/app-tests/e2e/organisations/organisation-team-preferences.spec.tsindex abb2a08d6..c9b7febf9 100644--- a/packages/app-tests/e2e/organisations/organisation-team-preferences.spec.ts+++ b/packages/app-tests/e2e/organisations/organisation-team-preferences.spec.ts@@ -231,6 +231,7 @@ test('[ORGANISATIONS]: manage email preferences', async ({ page }) => {documentDeleted: false, // uncheckedownerRecipientExpired: true,ownerDocumentCompleted: true,+ ownerDocumentCreated: true,});// Edit the team email settings@@ -271,6 +272,7 @@ test('[ORGANISATIONS]: manage email preferences', async ({ page }) => {documentDeleted: true,ownerRecipientExpired: true,ownerDocumentCompleted: false,+ ownerDocumentCreated: true,});// Verify that a document can be created successfully with the team email settings@@ -292,6 +294,7 @@ test('[ORGANISATIONS]: manage email preferences', async ({ page }) => {documentDeleted: true,ownerRecipientExpired: true,ownerDocumentCompleted: false,+ ownerDocumentCreated: true,});// Test inheritance by setting team back to inherit from organisation@@ -318,6 +321,7 @@ test('[ORGANISATIONS]: manage email preferences', async ({ page }) => {documentDeleted: false,ownerRecipientExpired: true,ownerDocumentCompleted: true,+ ownerDocumentCreated: true,});// Verify that a document can be created successfully with the email settings@@ -339,5 +343,6 @@ test('[ORGANISATIONS]: manage email preferences', async ({ page }) => {documentDeleted: false,ownerRecipientExpired: true,ownerDocumentCompleted: true,+ ownerDocumentCreated: true,});});diff --git a/packages/lib/server-only/template/create-document-from-direct-template.ts b/packages/lib/server-only/template/create-document-from-direct-template.tsindex 81a3059b5..59b1ec910 100644--- a/packages/lib/server-only/template/create-document-from-direct-template.ts+++ b/packages/lib/server-only/template/create-document-from-direct-template.ts@@ -24,6 +24,7 @@ import { jobs } from '../../jobs/client';import { DOCUMENT_AUDIT_LOG_TYPE, RECIPIENT_DIFF_TYPE } from '../../types/document-audit-logs';import type { TRecipientActionAuthTypes } from '../../types/document-auth';import { DocumentAccessAuth, ZRecipientAuthOptionsSchema } from '../../types/document-auth';+import { extractDerivedDocumentEmailSettings } from '../../types/document-email';import { ZFieldMetaSchema } from '../../types/field-meta';import {ZWebhookDocumentSchema,@@ -743,14 +744,17 @@ export const createDocumentFromDirectTemplate = async ({};});- // Send email to template owner via background job.- await jobs.triggerJob({- name: 'send.document.created.from.direct.template.email',- payload: {- envelopeId: createdEnvelope.id,- recipientId,- },- });+ const emailSettings = extractDerivedDocumentEmailSettings(documentMeta);++ if (emailSettings.ownerDocumentCreated) {+ await jobs.triggerJob({+ name: 'send.document.created.from.direct.template.email',+ payload: {+ envelopeId: createdEnvelope.id,+ recipientId,+ },+ });+ }try {// This handles sending emails and sealing the document if required.diff --git a/packages/lib/server-only/webhooks/trigger/generate-sample-data.ts b/packages/lib/server-only/webhooks/trigger/generate-sample-data.tsindex ec736d17a..5f25973ef 100644--- a/packages/lib/server-only/webhooks/trigger/generate-sample-data.ts+++ b/packages/lib/server-only/webhooks/trigger/generate-sample-data.ts@@ -440,6 +440,7 @@ export const generateSampleWebhookPayload = (documentCompleted: true,ownerDocumentCompleted: true,ownerRecipientExpired: true,+ ownerDocumentCreated: true,recipientSigningRequest: true,},},diff --git a/packages/lib/types/document-email.ts b/packages/lib/types/document-email.tsindex cc659519b..4ecb8b6a9 100644--- a/packages/lib/types/document-email.ts+++ b/packages/lib/types/document-email.ts@@ -11,6 +11,7 @@ export enum DocumentEmailEvents {DocumentDeleted = 'documentDeleted',OwnerDocumentCompleted = 'ownerDocumentCompleted',OwnerRecipientExpired = 'ownerRecipientExpired',+ OwnerDocumentCreated = 'ownerDocumentCreated',}export const ZDocumentEmailSettingsSchema = z@@ -59,6 +60,12 @@ export const ZDocumentEmailSettingsSchema = z"Whether to send an email to the document owner when a recipient's signing window has expired.",).default(true),+ ownerDocumentCreated: z+ .boolean()+ .describe(+ 'Whether to send an email to the document owner when a document is created from a direct template.',+ )+ .default(true),}).strip().catch(() => ({ ...DEFAULT_DOCUMENT_EMAIL_SETTINGS }));@@ -86,6 +93,7 @@ export const extractDerivedDocumentEmailSettings = (documentDeleted: false,ownerDocumentCompleted: emailSettings.ownerDocumentCompleted,ownerRecipientExpired: emailSettings.ownerRecipientExpired,+ ownerDocumentCreated: emailSettings.ownerDocumentCreated,};};@@ -98,4 +106,5 @@ export const DEFAULT_DOCUMENT_EMAIL_SETTINGS: TDocumentEmailSettings = {documentDeleted: true,ownerDocumentCompleted: true,ownerRecipientExpired: true,+ ownerDocumentCreated: true,};diff --git a/packages/ui/components/document/document-email-checkboxes.tsx b/packages/ui/components/document/document-email-checkboxes.tsxindex dc846abbd..200503709 100644--- a/packages/ui/components/document/document-email-checkboxes.tsx+++ b/packages/ui/components/document/document-email-checkboxes.tsx@@ -291,6 +291,45 @@ export const DocumentEmailCheckboxes = ({</label></div>+ <div className="flex flex-row items-center">+ <Checkbox+ id={DocumentEmailEvents.OwnerDocumentCreated}+ className="h-5 w-5"+ checked={value.ownerDocumentCreated}+ onCheckedChange={(checked) =>+ onChange({ ...value, [DocumentEmailEvents.OwnerDocumentCreated]: Boolean(checked) })+ }+ />++ <label+ className="ml-2 flex flex-row items-center text-sm text-muted-foreground"+ htmlFor={DocumentEmailEvents.OwnerDocumentCreated}+ >+ <Trans>Email the owner when a document is created from a direct template</Trans>++ <Tooltip>+ <TooltipTrigger>+ <InfoIcon className="mx-2 h-4 w-4" />+ </TooltipTrigger>++ <TooltipContent className="max-w-md space-y-2 p-4 text-foreground">+ <h2>+ <strong>+ <Trans>Document created from direct template email</Trans>+ </strong>+ </h2>++ <p>+ <Trans>+ This email is sent to the document owner when a recipient creates a document via a+ direct template link.+ </Trans>+ </p>+ </TooltipContent>+ </Tooltip>+ </label>+ </div>+<div className="flex flex-row items-center"><Checkboxid={DocumentEmailEvents.OwnerRecipientExpired}