mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
feat: migrate templates and documents to envelope model
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import { DocumentStatus } from '@prisma/client';
|
import { DocumentStatus, EnvelopeType } from '@prisma/client';
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
|
|
||||||
import { kyselyPrisma, sql } from '@documenso/prisma';
|
import { kyselyPrisma, sql } from '@documenso/prisma';
|
||||||
@ -7,18 +7,19 @@ import { addZeroMonth } from '../add-zero-month';
|
|||||||
|
|
||||||
export const getCompletedDocumentsMonthly = async (type: 'count' | 'cumulative' = 'count') => {
|
export const getCompletedDocumentsMonthly = async (type: 'count' | 'cumulative' = 'count') => {
|
||||||
const qb = kyselyPrisma.$kysely
|
const qb = kyselyPrisma.$kysely
|
||||||
.selectFrom('Document')
|
.selectFrom('Envelope')
|
||||||
.select(({ fn }) => [
|
.select(({ fn }) => [
|
||||||
fn<Date>('DATE_TRUNC', [sql.lit('MONTH'), 'Document.updatedAt']).as('month'),
|
fn<Date>('DATE_TRUNC', [sql.lit('MONTH'), 'Envelope.updatedAt']).as('month'),
|
||||||
fn.count('id').as('count'),
|
fn.count('id').as('count'),
|
||||||
fn
|
fn
|
||||||
.sum(fn.count('id'))
|
.sum(fn.count('id'))
|
||||||
// Feels like a bug in the Kysely extension but I just can not do this orderBy in a type-safe manner
|
// Feels like a bug in the Kysely extension but I just can not do this orderBy in a type-safe manner
|
||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any
|
||||||
.over((ob) => ob.orderBy(fn('DATE_TRUNC', [sql.lit('MONTH'), 'Document.updatedAt']) as any))
|
.over((ob) => ob.orderBy(fn('DATE_TRUNC', [sql.lit('MONTH'), 'Envelope.updatedAt']) as any))
|
||||||
.as('cume_count'),
|
.as('cume_count'),
|
||||||
])
|
])
|
||||||
.where(() => sql`"Document"."status" = ${DocumentStatus.COMPLETED}::"DocumentStatus"`)
|
.where(() => sql`"Envelope"."status" = ${DocumentStatus.COMPLETED}::"DocumentStatus"`)
|
||||||
|
.where(() => sql`"Envelope"."type" = ${EnvelopeType.DOCUMENT}::"EnvelopeType"`)
|
||||||
.groupBy('month')
|
.groupBy('month')
|
||||||
.orderBy('month', 'desc')
|
.orderBy('month', 'desc')
|
||||||
.limit(12);
|
.limit(12);
|
||||||
|
|||||||
@ -3,7 +3,6 @@ import { useState } from 'react';
|
|||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import type { Document } from '@prisma/client';
|
|
||||||
import { useNavigate } from 'react-router';
|
import { useNavigate } from 'react-router';
|
||||||
|
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
@ -22,10 +21,10 @@ import { Input } from '@documenso/ui/primitives/input';
|
|||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
||||||
|
|
||||||
export type AdminDocumentDeleteDialogProps = {
|
export type AdminDocumentDeleteDialogProps = {
|
||||||
document: Document;
|
envelopeId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const AdminDocumentDeleteDialog = ({ document }: AdminDocumentDeleteDialogProps) => {
|
export const AdminDocumentDeleteDialog = ({ envelopeId }: AdminDocumentDeleteDialogProps) => {
|
||||||
const { _ } = useLingui();
|
const { _ } = useLingui();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
@ -42,7 +41,7 @@ export const AdminDocumentDeleteDialog = ({ document }: AdminDocumentDeleteDialo
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await deleteDocument({ id: document.id, reason });
|
await deleteDocument({ id: envelopeId, reason });
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: _(msg`Document deleted`),
|
title: _(msg`Document deleted`),
|
||||||
|
|||||||
@ -81,7 +81,7 @@ export const DocumentMoveToFolderDialog = ({
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const { mutateAsync: moveDocumentToFolder } = trpc.folder.moveDocumentToFolder.useMutation();
|
const { mutateAsync: updateDocument } = trpc.document.update.useMutation();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!open) {
|
if (!open) {
|
||||||
@ -94,9 +94,11 @@ export const DocumentMoveToFolderDialog = ({
|
|||||||
|
|
||||||
const onSubmit = async (data: TMoveDocumentFormSchema) => {
|
const onSubmit = async (data: TMoveDocumentFormSchema) => {
|
||||||
try {
|
try {
|
||||||
await moveDocumentToFolder({
|
await updateDocument({
|
||||||
documentId,
|
documentId,
|
||||||
folderId: data.folderId ?? null,
|
data: {
|
||||||
|
folderId: data.folderId ?? null,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const documentsPath = formatDocumentsPath(team.url);
|
const documentsPath = formatDocumentsPath(team.url);
|
||||||
|
|||||||
@ -4,15 +4,15 @@ import { zodResolver } from '@hookform/resolvers/zod';
|
|||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import { type Recipient, SigningStatus } from '@prisma/client';
|
import { type Recipient, SigningStatus, type Team, type User } from '@prisma/client';
|
||||||
import { History } from 'lucide-react';
|
import { History } from 'lucide-react';
|
||||||
import { useForm, useWatch } from 'react-hook-form';
|
import { useForm, useWatch } from 'react-hook-form';
|
||||||
import * as z from 'zod';
|
import * as z from 'zod';
|
||||||
|
|
||||||
import { useSession } from '@documenso/lib/client-only/providers/session';
|
import { useSession } from '@documenso/lib/client-only/providers/session';
|
||||||
import { getRecipientType } from '@documenso/lib/client-only/recipient-type';
|
import { getRecipientType } from '@documenso/lib/client-only/recipient-type';
|
||||||
import type { TDocumentMany as TDocumentRow } from '@documenso/lib/types/document';
|
|
||||||
import { recipientAbbreviation } from '@documenso/lib/utils/recipient-formatter';
|
import { recipientAbbreviation } from '@documenso/lib/utils/recipient-formatter';
|
||||||
|
import type { Document } from '@documenso/prisma/types/document-legacy-schema';
|
||||||
import { trpc as trpcReact } from '@documenso/trpc/react';
|
import { trpc as trpcReact } from '@documenso/trpc/react';
|
||||||
import { cn } from '@documenso/ui/lib/utils';
|
import { cn } from '@documenso/ui/lib/utils';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
@ -43,7 +43,11 @@ import { StackAvatar } from '../general/stack-avatar';
|
|||||||
const FORM_ID = 'resend-email';
|
const FORM_ID = 'resend-email';
|
||||||
|
|
||||||
export type DocumentResendDialogProps = {
|
export type DocumentResendDialogProps = {
|
||||||
document: TDocumentRow;
|
document: Pick<Document, 'id' | 'userId' | 'teamId' | 'status'> & {
|
||||||
|
user: Pick<User, 'id' | 'name' | 'email'>;
|
||||||
|
recipients: Recipient[];
|
||||||
|
team: Pick<Team, 'id' | 'url'> | null;
|
||||||
|
};
|
||||||
recipients: Recipient[];
|
recipients: Recipient[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -4,14 +4,14 @@ import { zodResolver } from '@hookform/resolvers/zod';
|
|||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Plural, Trans } from '@lingui/react/macro';
|
import { Plural, Trans } from '@lingui/react/macro';
|
||||||
import type { Template, TemplateDirectLink } from '@prisma/client';
|
import { type TemplateDirectLink, TemplateType } from '@prisma/client';
|
||||||
import { TemplateType } from '@prisma/client';
|
|
||||||
import type * as DialogPrimitive from '@radix-ui/react-dialog';
|
import type * as DialogPrimitive from '@radix-ui/react-dialog';
|
||||||
import { CheckCircle2Icon, CircleIcon } from 'lucide-react';
|
import { CheckCircle2Icon, CircleIcon } from 'lucide-react';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
import { P, match } from 'ts-pattern';
|
import { P, match } from 'ts-pattern';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
import { type Template } from '@documenso/prisma/types/template-legacy-schema';
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
import {
|
import {
|
||||||
MAX_TEMPLATE_PUBLIC_DESCRIPTION_LENGTH,
|
MAX_TEMPLATE_PUBLIC_DESCRIPTION_LENGTH,
|
||||||
|
|||||||
@ -54,7 +54,7 @@ export const TemplateCreateDialog = ({ folderId }: TemplateCreateDialogProps) =>
|
|||||||
try {
|
try {
|
||||||
const response = await putPdfFile(file);
|
const response = await putPdfFile(file);
|
||||||
|
|
||||||
const { id } = await createTemplate({
|
const { legacyTemplateId: id } = await createTemplate({
|
||||||
title: file.name,
|
title: file.name,
|
||||||
templateDocumentDataId: response.id,
|
templateDocumentDataId: response.id,
|
||||||
folderId: folderId,
|
folderId: folderId,
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import type { Recipient, Template, TemplateDirectLink } from '@prisma/client';
|
import type { Recipient, TemplateDirectLink } from '@prisma/client';
|
||||||
import { LinkIcon } from 'lucide-react';
|
import { LinkIcon } from 'lucide-react';
|
||||||
|
|
||||||
|
import type { Template } from '@documenso/prisma/types/template-legacy-schema';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
|
|
||||||
import { TemplateDirectLinkDialog } from '~/components/dialogs/template-direct-link-dialog';
|
import { TemplateDirectLinkDialog } from '~/components/dialogs/template-direct-link-dialog';
|
||||||
|
|||||||
@ -3,12 +3,7 @@ import { useEffect, useMemo, useState } from 'react';
|
|||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import {
|
import { type Recipient, RecipientRole, type TemplateDirectLink } from '@prisma/client';
|
||||||
type Recipient,
|
|
||||||
RecipientRole,
|
|
||||||
type Template,
|
|
||||||
type TemplateDirectLink,
|
|
||||||
} from '@prisma/client';
|
|
||||||
import { CircleDotIcon, CircleIcon, ClipboardCopyIcon, InfoIcon, LoaderIcon } from 'lucide-react';
|
import { CircleDotIcon, CircleIcon, ClipboardCopyIcon, InfoIcon, LoaderIcon } from 'lucide-react';
|
||||||
import { Link, useRevalidator } from 'react-router';
|
import { Link, useRevalidator } from 'react-router';
|
||||||
import { P, match } from 'ts-pattern';
|
import { P, match } from 'ts-pattern';
|
||||||
@ -20,6 +15,7 @@ import { DIRECT_TEMPLATE_RECIPIENT_EMAIL } from '@documenso/lib/constants/direct
|
|||||||
import { RECIPIENT_ROLES_DESCRIPTION } from '@documenso/lib/constants/recipient-roles';
|
import { RECIPIENT_ROLES_DESCRIPTION } from '@documenso/lib/constants/recipient-roles';
|
||||||
import { DIRECT_TEMPLATE_DOCUMENTATION } from '@documenso/lib/constants/template';
|
import { DIRECT_TEMPLATE_DOCUMENTATION } from '@documenso/lib/constants/template';
|
||||||
import { formatDirectTemplatePath } from '@documenso/lib/utils/templates';
|
import { formatDirectTemplatePath } from '@documenso/lib/utils/templates';
|
||||||
|
import type { Template } from '@documenso/prisma/types/template-legacy-schema';
|
||||||
import { trpc as trpcReact } from '@documenso/trpc/react';
|
import { trpc as trpcReact } from '@documenso/trpc/react';
|
||||||
import { AnimateGenericFadeInOut } from '@documenso/ui/components/animate/animate-generic-fade-in-out';
|
import { AnimateGenericFadeInOut } from '@documenso/ui/components/animate/animate-generic-fade-in-out';
|
||||||
import { Alert, AlertDescription, AlertTitle } from '@documenso/ui/primitives/alert';
|
import { Alert, AlertDescription, AlertTitle } from '@documenso/ui/primitives/alert';
|
||||||
|
|||||||
@ -83,7 +83,7 @@ export function TemplateMoveToFolderDialog({
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const { mutateAsync: moveTemplateToFolder } = trpc.folder.moveTemplateToFolder.useMutation();
|
const { mutateAsync: updateTemplate } = trpc.template.updateTemplate.useMutation();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isOpen) {
|
if (!isOpen) {
|
||||||
@ -96,9 +96,11 @@ export function TemplateMoveToFolderDialog({
|
|||||||
|
|
||||||
const onSubmit = async (data: TMoveTemplateFormSchema) => {
|
const onSubmit = async (data: TMoveTemplateFormSchema) => {
|
||||||
try {
|
try {
|
||||||
await moveTemplateToFolder({
|
await updateTemplate({
|
||||||
templateId,
|
templateId,
|
||||||
folderId: data.folderId ?? null,
|
data: {
|
||||||
|
folderId: data.folderId ?? null,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
|
|||||||
@ -118,6 +118,9 @@ export const ConfigureFieldsView = ({
|
|||||||
sendStatus: signer.disabled ? SendStatus.SENT : SendStatus.NOT_SENT,
|
sendStatus: signer.disabled ? SendStatus.SENT : SendStatus.NOT_SENT,
|
||||||
readStatus: signer.disabled ? ReadStatus.OPENED : ReadStatus.NOT_OPENED,
|
readStatus: signer.disabled ? ReadStatus.OPENED : ReadStatus.NOT_OPENED,
|
||||||
signingStatus: signer.disabled ? SigningStatus.SIGNED : SigningStatus.NOT_SIGNED,
|
signingStatus: signer.disabled ? SigningStatus.SIGNED : SigningStatus.NOT_SIGNED,
|
||||||
|
|
||||||
|
// Todo: Envelopes - Dummy data
|
||||||
|
envelopeId: '',
|
||||||
}));
|
}));
|
||||||
}, [configData.signers]);
|
}, [configData.signers]);
|
||||||
|
|
||||||
|
|||||||
@ -15,12 +15,14 @@ import { LucideChevronDown, LucideChevronUp } from 'lucide-react';
|
|||||||
|
|
||||||
import { useThrottleFn } from '@documenso/lib/client-only/hooks/use-throttle-fn';
|
import { useThrottleFn } from '@documenso/lib/client-only/hooks/use-throttle-fn';
|
||||||
import { PDF_VIEWER_PAGE_SELECTOR } from '@documenso/lib/constants/pdf-viewer';
|
import { PDF_VIEWER_PAGE_SELECTOR } from '@documenso/lib/constants/pdf-viewer';
|
||||||
import type { DocumentField } from '@documenso/lib/server-only/field/get-fields-for-document';
|
|
||||||
import { isFieldUnsignedAndRequired } from '@documenso/lib/utils/advanced-fields-helpers';
|
import { isFieldUnsignedAndRequired } from '@documenso/lib/utils/advanced-fields-helpers';
|
||||||
import { validateFieldsInserted } from '@documenso/lib/utils/fields';
|
import { validateFieldsInserted } from '@documenso/lib/utils/fields';
|
||||||
import type { RecipientWithFields } from '@documenso/prisma/types/recipient-with-fields';
|
import type { RecipientWithFields } from '@documenso/prisma/types/recipient-with-fields';
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
import { DocumentReadOnlyFields } from '@documenso/ui/components/document/document-read-only-fields';
|
import {
|
||||||
|
type DocumentField,
|
||||||
|
DocumentReadOnlyFields,
|
||||||
|
} from '@documenso/ui/components/document/document-read-only-fields';
|
||||||
import { FieldToolTip } from '@documenso/ui/components/field/field-tooltip';
|
import { FieldToolTip } from '@documenso/ui/components/field/field-tooltip';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
import { ElementVisible } from '@documenso/ui/primitives/element-visible';
|
import { ElementVisible } from '@documenso/ui/primitives/element-visible';
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { createContext, useContext, useEffect, useMemo, useState } from 'react';
|
import { createContext, useContext, useEffect, useMemo, useState } from 'react';
|
||||||
|
|
||||||
import { type Document, FieldType, type Passkey, type Recipient } from '@prisma/client';
|
import { type Envelope, FieldType, type Passkey, type Recipient } from '@prisma/client';
|
||||||
|
|
||||||
import type { SessionUser } from '@documenso/auth/server/lib/session/session';
|
import type { SessionUser } from '@documenso/auth/server/lib/session/session';
|
||||||
import { MAXIMUM_PASSKEYS } from '@documenso/lib/constants/auth';
|
import { MAXIMUM_PASSKEYS } from '@documenso/lib/constants/auth';
|
||||||
@ -26,9 +26,9 @@ type PasskeyData = {
|
|||||||
|
|
||||||
export type DocumentSigningAuthContextValue = {
|
export type DocumentSigningAuthContextValue = {
|
||||||
executeActionAuthProcedure: (_value: ExecuteActionAuthProcedureOptions) => Promise<void>;
|
executeActionAuthProcedure: (_value: ExecuteActionAuthProcedureOptions) => Promise<void>;
|
||||||
documentAuthOptions: Document['authOptions'];
|
documentAuthOptions: Envelope['authOptions'];
|
||||||
documentAuthOption: TDocumentAuthOptions;
|
documentAuthOption: TDocumentAuthOptions;
|
||||||
setDocumentAuthOptions: (_value: Document['authOptions']) => void;
|
setDocumentAuthOptions: (_value: Envelope['authOptions']) => void;
|
||||||
recipient: Recipient;
|
recipient: Recipient;
|
||||||
recipientAuthOption: TRecipientAuthOptions;
|
recipientAuthOption: TRecipientAuthOptions;
|
||||||
setRecipient: (_value: Recipient) => void;
|
setRecipient: (_value: Recipient) => void;
|
||||||
@ -61,7 +61,7 @@ export const useRequiredDocumentSigningAuthContext = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export interface DocumentSigningAuthProviderProps {
|
export interface DocumentSigningAuthProviderProps {
|
||||||
documentAuthOptions: Document['authOptions'];
|
documentAuthOptions: Envelope['authOptions'];
|
||||||
recipient: Recipient;
|
recipient: Recipient;
|
||||||
user?: SessionUser | null;
|
user?: SessionUser | null;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
|
|||||||
@ -3,12 +3,12 @@ import { useEffect, useState } from 'react';
|
|||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import type { Document } from '@prisma/client';
|
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
import { useNavigate } from 'react-router';
|
import { useNavigate } from 'react-router';
|
||||||
import { useSearchParams } from 'react-router';
|
import { useSearchParams } from 'react-router';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
import type { Document } from '@documenso/prisma/types/document-legacy-schema';
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
import {
|
import {
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import { Trans } from '@lingui/react/macro';
|
|||||||
import type { DocumentData } from '@prisma/client';
|
import type { DocumentData } from '@prisma/client';
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
|
|
||||||
|
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
import {
|
import {
|
||||||
@ -23,6 +24,7 @@ export type DocumentCertificateQRViewProps = {
|
|||||||
title: string;
|
title: string;
|
||||||
documentData: DocumentData;
|
documentData: DocumentData;
|
||||||
password?: string | null;
|
password?: string | null;
|
||||||
|
documentTeamUrl: string;
|
||||||
recipientCount?: number;
|
recipientCount?: number;
|
||||||
completedDate?: Date;
|
completedDate?: Date;
|
||||||
};
|
};
|
||||||
@ -32,29 +34,30 @@ export const DocumentCertificateQRView = ({
|
|||||||
title,
|
title,
|
||||||
documentData,
|
documentData,
|
||||||
password,
|
password,
|
||||||
|
documentTeamUrl,
|
||||||
recipientCount = 0,
|
recipientCount = 0,
|
||||||
completedDate,
|
completedDate,
|
||||||
}: DocumentCertificateQRViewProps) => {
|
}: DocumentCertificateQRViewProps) => {
|
||||||
const { data: documentUrl } = trpc.shareLink.getDocumentInternalUrlForQRCode.useQuery({
|
const { data: documentViaUser } = trpc.document.get.useQuery({
|
||||||
documentId,
|
documentId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const [isDialogOpen, setIsDialogOpen] = useState(() => !!documentUrl);
|
const [isDialogOpen, setIsDialogOpen] = useState(() => !!documentViaUser);
|
||||||
|
|
||||||
const formattedDate = completedDate
|
const formattedDate = completedDate
|
||||||
? DateTime.fromJSDate(completedDate).toLocaleString(DateTime.DATETIME_MED)
|
? DateTime.fromJSDate(completedDate).toLocaleString(DateTime.DATETIME_MED)
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (documentUrl) {
|
if (documentViaUser) {
|
||||||
setIsDialogOpen(true);
|
setIsDialogOpen(true);
|
||||||
}
|
}
|
||||||
}, [documentUrl]);
|
}, [documentViaUser]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto w-full max-w-screen-md">
|
<div className="mx-auto w-full max-w-screen-md">
|
||||||
{/* Dialog for internal document link */}
|
{/* Dialog for internal document link */}
|
||||||
{documentUrl && (
|
{documentViaUser && (
|
||||||
<Dialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
|
<Dialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
@ -72,7 +75,11 @@ export const DocumentCertificateQRView = ({
|
|||||||
|
|
||||||
<DialogFooter className="flex flex-row justify-end gap-2">
|
<DialogFooter className="flex flex-row justify-end gap-2">
|
||||||
<Button asChild>
|
<Button asChild>
|
||||||
<a href={documentUrl} target="_blank" rel="noopener noreferrer">
|
<a
|
||||||
|
href={`${formatDocumentsPath(documentTeamUrl)}/${documentViaUser.id}`}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
<Trans>Go to document</Trans>
|
<Trans>Go to document</Trans>
|
||||||
</a>
|
</a>
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@ -64,7 +64,7 @@ export const DocumentDropZoneWrapper = ({ children, className }: DocumentDropZon
|
|||||||
|
|
||||||
const response = await putPdfFile(file);
|
const response = await putPdfFile(file);
|
||||||
|
|
||||||
const { id } = await createDocument({
|
const { legacyDocumentId: id } = await createDocument({
|
||||||
title: file.name,
|
title: file.name,
|
||||||
documentDataId: response.id,
|
documentDataId: response.id,
|
||||||
timezone: userTimezone, // Note: When migrating to v2 document upload remember to pass this through as a 'userTimezone' field.
|
timezone: userTimezone, // Note: When migrating to v2 document upload remember to pass this through as a 'userTimezone' field.
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import type { Document, Recipient, Team, User } from '@prisma/client';
|
import type { Recipient, Team, User } from '@prisma/client';
|
||||||
import { DocumentStatus, RecipientRole, SigningStatus } from '@prisma/client';
|
import { DocumentStatus, RecipientRole, SigningStatus } from '@prisma/client';
|
||||||
import { CheckCircle, Download, EyeIcon, Pencil } from 'lucide-react';
|
import { CheckCircle, Download, EyeIcon, Pencil } from 'lucide-react';
|
||||||
import { Link } from 'react-router';
|
import { Link } from 'react-router';
|
||||||
@ -11,6 +11,7 @@ import { downloadPDF } from '@documenso/lib/client-only/download-pdf';
|
|||||||
import { useSession } from '@documenso/lib/client-only/providers/session';
|
import { useSession } from '@documenso/lib/client-only/providers/session';
|
||||||
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
||||||
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
||||||
|
import type { Document } from '@documenso/prisma/types/document-legacy-schema';
|
||||||
import { trpc as trpcClient } from '@documenso/trpc/client';
|
import { trpc as trpcClient } from '@documenso/trpc/client';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { useState } from 'react';
|
|||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import type { Document, Recipient, Team, User } from '@prisma/client';
|
import type { Recipient, Team, User } from '@prisma/client';
|
||||||
import { DocumentStatus } from '@prisma/client';
|
import { DocumentStatus } from '@prisma/client';
|
||||||
import {
|
import {
|
||||||
Copy,
|
Copy,
|
||||||
@ -19,6 +19,7 @@ import { Link, useNavigate } from 'react-router';
|
|||||||
|
|
||||||
import { downloadPDF } from '@documenso/lib/client-only/download-pdf';
|
import { downloadPDF } from '@documenso/lib/client-only/download-pdf';
|
||||||
import { useSession } from '@documenso/lib/client-only/providers/session';
|
import { useSession } from '@documenso/lib/client-only/providers/session';
|
||||||
|
import type { TDocument } from '@documenso/lib/types/document';
|
||||||
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
||||||
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
||||||
import { trpc as trpcClient } from '@documenso/trpc/client';
|
import { trpc as trpcClient } from '@documenso/trpc/client';
|
||||||
@ -39,7 +40,7 @@ import { DocumentRecipientLinkCopyDialog } from '~/components/general/document/d
|
|||||||
import { useCurrentTeam } from '~/providers/team';
|
import { useCurrentTeam } from '~/providers/team';
|
||||||
|
|
||||||
export type DocumentPageViewDropdownProps = {
|
export type DocumentPageViewDropdownProps = {
|
||||||
document: Document & {
|
document: TDocument & {
|
||||||
user: Pick<User, 'id' | 'name' | 'email'>;
|
user: Pick<User, 'id' | 'name' | 'email'>;
|
||||||
recipients: Recipient[];
|
recipients: Recipient[];
|
||||||
team: Pick<Team, 'id' | 'url'> | null;
|
team: Pick<Team, 'id' | 'url'> | null;
|
||||||
|
|||||||
@ -3,10 +3,11 @@ import { useMemo } from 'react';
|
|||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import type { Document, Recipient, User } from '@prisma/client';
|
import type { Recipient, User } from '@prisma/client';
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
|
|
||||||
import { useIsMounted } from '@documenso/lib/client-only/hooks/use-is-mounted';
|
import { useIsMounted } from '@documenso/lib/client-only/hooks/use-is-mounted';
|
||||||
|
import type { Document } from '@documenso/prisma/types/document-legacy-schema';
|
||||||
|
|
||||||
export type DocumentPageViewInformationProps = {
|
export type DocumentPageViewInformationProps = {
|
||||||
userId: number;
|
userId: number;
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { msg } from '@lingui/core/macro';
|
|||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import { DocumentStatus, RecipientRole, SigningStatus } from '@prisma/client';
|
import { DocumentStatus, RecipientRole, SigningStatus } from '@prisma/client';
|
||||||
import type { Document, Recipient } from '@prisma/client';
|
import type { Recipient } from '@prisma/client';
|
||||||
import {
|
import {
|
||||||
AlertTriangle,
|
AlertTriangle,
|
||||||
CheckIcon,
|
CheckIcon,
|
||||||
@ -19,6 +19,7 @@ import { match } from 'ts-pattern';
|
|||||||
import { RECIPIENT_ROLES_DESCRIPTION } from '@documenso/lib/constants/recipient-roles';
|
import { RECIPIENT_ROLES_DESCRIPTION } from '@documenso/lib/constants/recipient-roles';
|
||||||
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
||||||
import { formatSigningLink } from '@documenso/lib/utils/recipients';
|
import { formatSigningLink } from '@documenso/lib/utils/recipients';
|
||||||
|
import type { Document } from '@documenso/prisma/types/document-legacy-schema';
|
||||||
import { CopyTextButton } from '@documenso/ui/components/common/copy-text-button';
|
import { CopyTextButton } from '@documenso/ui/components/common/copy-text-button';
|
||||||
import { SignatureIcon } from '@documenso/ui/icons/signature';
|
import { SignatureIcon } from '@documenso/ui/icons/signature';
|
||||||
import { AvatarWithText } from '@documenso/ui/primitives/avatar';
|
import { AvatarWithText } from '@documenso/ui/primitives/avatar';
|
||||||
|
|||||||
@ -75,7 +75,7 @@ export const DocumentUploadDropzone = ({ className }: DocumentUploadDropzoneProp
|
|||||||
|
|
||||||
const response = await putPdfFile(file);
|
const response = await putPdfFile(file);
|
||||||
|
|
||||||
const { id } = await createDocument({
|
const { legacyDocumentId: id } = await createDocument({
|
||||||
title: file.name,
|
title: file.name,
|
||||||
documentDataId: response.id,
|
documentDataId: response.id,
|
||||||
timezone: userTimezone, // Note: When migrating to v2 document upload remember to pass this through as a 'userTimezone' field.
|
timezone: userTimezone, // Note: When migrating to v2 document upload remember to pass this through as a 'userTimezone' field.
|
||||||
|
|||||||
@ -42,7 +42,7 @@ export const TemplateDropZoneWrapper = ({ children, className }: TemplateDropZon
|
|||||||
|
|
||||||
const documentData = await putPdfFile(file);
|
const documentData = await putPdfFile(file);
|
||||||
|
|
||||||
const { id } = await createTemplate({
|
const { legacyTemplateId: id } = await createTemplate({
|
||||||
title: file.name,
|
title: file.name,
|
||||||
templateDocumentDataId: documentData.id,
|
templateDocumentDataId: documentData.id,
|
||||||
folderId: folderId ?? undefined,
|
folderId: folderId ?? undefined,
|
||||||
|
|||||||
@ -3,10 +3,11 @@ import { useMemo } from 'react';
|
|||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import type { Template, User } from '@prisma/client';
|
import type { User } from '@prisma/client';
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
|
|
||||||
import { useIsMounted } from '@documenso/lib/client-only/hooks/use-is-mounted';
|
import { useIsMounted } from '@documenso/lib/client-only/hooks/use-is-mounted';
|
||||||
|
import type { Template } from '@documenso/prisma/types/template-legacy-schema';
|
||||||
|
|
||||||
export type TemplatePageViewInformationProps = {
|
export type TemplatePageViewInformationProps = {
|
||||||
userId: number;
|
userId: number;
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import type { Recipient, Template } from '@prisma/client';
|
import type { Recipient } from '@prisma/client';
|
||||||
import { PenIcon, PlusIcon } from 'lucide-react';
|
import { PenIcon, PlusIcon } from 'lucide-react';
|
||||||
import { Link } from 'react-router';
|
import { Link } from 'react-router';
|
||||||
|
|
||||||
import { RECIPIENT_ROLES_DESCRIPTION } from '@documenso/lib/constants/recipient-roles';
|
import { RECIPIENT_ROLES_DESCRIPTION } from '@documenso/lib/constants/recipient-roles';
|
||||||
import { isTemplateRecipientEmailPlaceholder } from '@documenso/lib/constants/template';
|
import { isTemplateRecipientEmailPlaceholder } from '@documenso/lib/constants/template';
|
||||||
import { extractInitials } from '@documenso/lib/utils/recipient-formatter';
|
import { extractInitials } from '@documenso/lib/utils/recipient-formatter';
|
||||||
|
import type { Template } from '@documenso/prisma/types/template-legacy-schema';
|
||||||
import { AvatarWithText } from '@documenso/ui/primitives/avatar';
|
import { AvatarWithText } from '@documenso/ui/primitives/avatar';
|
||||||
|
|
||||||
export type TemplatePageViewRecipientsProps = {
|
export type TemplatePageViewRecipientsProps = {
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { useEffect, useMemo, useState, useTransition } from 'react';
|
|||||||
|
|
||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import type { Document, Role, Subscription } from '@prisma/client';
|
import type { Role, Subscription } from '@prisma/client';
|
||||||
import { Edit, Loader } from 'lucide-react';
|
import { Edit, Loader } from 'lucide-react';
|
||||||
import { Link } from 'react-router';
|
import { Link } from 'react-router';
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ type UserData = {
|
|||||||
email: string;
|
email: string;
|
||||||
roles: Role[];
|
roles: Role[];
|
||||||
subscriptions?: SubscriptionLite[] | null;
|
subscriptions?: SubscriptionLite[] | null;
|
||||||
documents: DocumentLite[];
|
documentCount: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
type SubscriptionLite = Pick<
|
type SubscriptionLite = Pick<
|
||||||
@ -28,8 +28,6 @@ type SubscriptionLite = Pick<
|
|||||||
'id' | 'status' | 'planId' | 'priceId' | 'createdAt' | 'periodEnd'
|
'id' | 'status' | 'planId' | 'priceId' | 'createdAt' | 'periodEnd'
|
||||||
>;
|
>;
|
||||||
|
|
||||||
type DocumentLite = Pick<Document, 'id'>;
|
|
||||||
|
|
||||||
type AdminDashboardUsersTableProps = {
|
type AdminDashboardUsersTableProps = {
|
||||||
users: UserData[];
|
users: UserData[];
|
||||||
totalPages: number;
|
totalPages: number;
|
||||||
@ -74,10 +72,7 @@ export const AdminDashboardUsersTable = ({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: _(msg`Documents`),
|
header: _(msg`Documents`),
|
||||||
accessorKey: 'documents',
|
accessorKey: 'documentCount',
|
||||||
cell: ({ row }) => {
|
|
||||||
return <div>{row.original.documents?.length}</div>;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: '',
|
header: '',
|
||||||
|
|||||||
@ -3,8 +3,7 @@ import { useMemo, useState } from 'react';
|
|||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import type { TemplateDirectLink } from '@prisma/client';
|
import { type TemplateDirectLink, TemplateType } from '@prisma/client';
|
||||||
import { TemplateType } from '@prisma/client';
|
|
||||||
import { EditIcon, FileIcon, LinkIcon, MoreHorizontalIcon, Trash2Icon } from 'lucide-react';
|
import { EditIcon, FileIcon, LinkIcon, MoreHorizontalIcon, Trash2Icon } from 'lucide-react';
|
||||||
|
|
||||||
import { useCopyToClipboard } from '@documenso/lib/client-only/hooks/use-copy-to-clipboard';
|
import { useCopyToClipboard } from '@documenso/lib/client-only/hooks/use-copy-to-clipboard';
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import type { Recipient, Template, TemplateDirectLink } from '@prisma/client';
|
import type { Recipient, TemplateDirectLink } from '@prisma/client';
|
||||||
import { Copy, Edit, FolderIcon, MoreHorizontal, Share2Icon, Trash2, Upload } from 'lucide-react';
|
import { Copy, Edit, FolderIcon, MoreHorizontal, Share2Icon, Trash2, Upload } from 'lucide-react';
|
||||||
import { Link } from 'react-router';
|
import { Link } from 'react-router';
|
||||||
|
|
||||||
import { useSession } from '@documenso/lib/client-only/providers/session';
|
import { useSession } from '@documenso/lib/client-only/providers/session';
|
||||||
|
import type { Template } from '@documenso/prisma/types/template-legacy-schema';
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import { SigningStatus } from '@prisma/client';
|
import { EnvelopeType, SigningStatus } from '@prisma/client';
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
import { Link, redirect } from 'react-router';
|
import { Link, redirect } from 'react-router';
|
||||||
|
|
||||||
import { getEntireDocument } from '@documenso/lib/server-only/admin/get-entire-document';
|
import { unsafeGetEntireEnvelope } from '@documenso/lib/server-only/admin/get-entire-document';
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
import {
|
import {
|
||||||
Accordion,
|
Accordion,
|
||||||
@ -36,13 +36,19 @@ export async function loader({ params }: Route.LoaderArgs) {
|
|||||||
throw redirect('/admin/documents');
|
throw redirect('/admin/documents');
|
||||||
}
|
}
|
||||||
|
|
||||||
const document = await getEntireDocument({ id });
|
const envelope = await unsafeGetEntireEnvelope({
|
||||||
|
id: {
|
||||||
|
type: 'documentId',
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
|
});
|
||||||
|
|
||||||
return { document };
|
return { envelope };
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function AdminDocumentDetailsPage({ loaderData }: Route.ComponentProps) {
|
export default function AdminDocumentDetailsPage({ loaderData }: Route.ComponentProps) {
|
||||||
const { document } = loaderData;
|
const { envelope } = loaderData;
|
||||||
|
|
||||||
const { _, i18n } = useLingui();
|
const { _, i18n } = useLingui();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
@ -68,11 +74,11 @@ export default function AdminDocumentDetailsPage({ loaderData }: Route.Component
|
|||||||
<div>
|
<div>
|
||||||
<div className="flex items-start justify-between">
|
<div className="flex items-start justify-between">
|
||||||
<div className="flex items-center gap-x-4">
|
<div className="flex items-center gap-x-4">
|
||||||
<h1 className="text-2xl font-semibold">{document.title}</h1>
|
<h1 className="text-2xl font-semibold">{envelope.title}</h1>
|
||||||
<DocumentStatus status={document.status} />
|
<DocumentStatus status={envelope.status} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{document.deletedAt && (
|
{envelope.deletedAt && (
|
||||||
<Badge size="large" variant="destructive">
|
<Badge size="large" variant="destructive">
|
||||||
<Trans>Deleted</Trans>
|
<Trans>Deleted</Trans>
|
||||||
</Badge>
|
</Badge>
|
||||||
@ -81,11 +87,11 @@ export default function AdminDocumentDetailsPage({ loaderData }: Route.Component
|
|||||||
|
|
||||||
<div className="text-muted-foreground mt-4 text-sm">
|
<div className="text-muted-foreground mt-4 text-sm">
|
||||||
<div>
|
<div>
|
||||||
<Trans>Created on</Trans>: {i18n.date(document.createdAt, DateTime.DATETIME_MED)}
|
<Trans>Created on</Trans>: {i18n.date(envelope.createdAt, DateTime.DATETIME_MED)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<Trans>Last updated at</Trans>: {i18n.date(document.updatedAt, DateTime.DATETIME_MED)}
|
<Trans>Last updated at</Trans>: {i18n.date(envelope.updatedAt, DateTime.DATETIME_MED)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -102,12 +108,12 @@ export default function AdminDocumentDetailsPage({ loaderData }: Route.Component
|
|||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
loading={isResealDocumentLoading}
|
loading={isResealDocumentLoading}
|
||||||
disabled={document.recipients.some(
|
disabled={envelope.recipients.some(
|
||||||
(recipient) =>
|
(recipient) =>
|
||||||
recipient.signingStatus !== SigningStatus.SIGNED &&
|
recipient.signingStatus !== SigningStatus.SIGNED &&
|
||||||
recipient.signingStatus !== SigningStatus.REJECTED,
|
recipient.signingStatus !== SigningStatus.REJECTED,
|
||||||
)}
|
)}
|
||||||
onClick={() => resealDocument({ id: document.id })}
|
onClick={() => resealDocument({ id: envelope.id })}
|
||||||
>
|
>
|
||||||
<Trans>Reseal document</Trans>
|
<Trans>Reseal document</Trans>
|
||||||
</Button>
|
</Button>
|
||||||
@ -123,7 +129,7 @@ export default function AdminDocumentDetailsPage({ loaderData }: Route.Component
|
|||||||
</TooltipProvider>
|
</TooltipProvider>
|
||||||
|
|
||||||
<Button variant="outline" asChild>
|
<Button variant="outline" asChild>
|
||||||
<Link to={`/admin/users/${document.userId}`}>
|
<Link to={`/admin/users/${envelope.userId}`}>
|
||||||
<Trans>Go to owner</Trans>
|
<Trans>Go to owner</Trans>
|
||||||
</Link>
|
</Link>
|
||||||
</Button>
|
</Button>
|
||||||
@ -136,7 +142,7 @@ export default function AdminDocumentDetailsPage({ loaderData }: Route.Component
|
|||||||
|
|
||||||
<div className="mt-4">
|
<div className="mt-4">
|
||||||
<Accordion type="multiple" className="space-y-4">
|
<Accordion type="multiple" className="space-y-4">
|
||||||
{document.recipients.map((recipient) => (
|
{envelope.recipients.map((recipient) => (
|
||||||
<AccordionItem
|
<AccordionItem
|
||||||
key={recipient.id}
|
key={recipient.id}
|
||||||
value={recipient.id.toString()}
|
value={recipient.id.toString()}
|
||||||
@ -161,7 +167,7 @@ export default function AdminDocumentDetailsPage({ loaderData }: Route.Component
|
|||||||
|
|
||||||
<hr className="my-4" />
|
<hr className="my-4" />
|
||||||
|
|
||||||
{document && <AdminDocumentDeleteDialog document={document} />}
|
{envelope && <AdminDocumentDeleteDialog envelopeId={envelope.id} />}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,10 @@ import { getTeamByUrl } from '@documenso/lib/server-only/team/get-team';
|
|||||||
import { DocumentVisibility } from '@documenso/lib/types/document-visibility';
|
import { DocumentVisibility } from '@documenso/lib/types/document-visibility';
|
||||||
import { logDocumentAccess } from '@documenso/lib/utils/logger';
|
import { logDocumentAccess } from '@documenso/lib/utils/logger';
|
||||||
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
||||||
import { DocumentReadOnlyFields } from '@documenso/ui/components/document/document-read-only-fields';
|
import {
|
||||||
|
DocumentReadOnlyFields,
|
||||||
|
mapFieldsWithRecipients,
|
||||||
|
} from '@documenso/ui/components/document/document-read-only-fields';
|
||||||
import { Badge } from '@documenso/ui/primitives/badge';
|
import { Badge } from '@documenso/ui/primitives/badge';
|
||||||
import { Card, CardContent } from '@documenso/ui/primitives/card';
|
import { Card, CardContent } from '@documenso/ui/primitives/card';
|
||||||
import { PDFViewer } from '@documenso/ui/primitives/pdf-viewer';
|
import { PDFViewer } from '@documenso/ui/primitives/pdf-viewer';
|
||||||
@ -54,7 +57,10 @@ export async function loader({ params, request }: Route.LoaderArgs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const document = await getDocumentWithDetailsById({
|
const document = await getDocumentWithDetailsById({
|
||||||
documentId,
|
id: {
|
||||||
|
type: 'documentId',
|
||||||
|
id: documentId,
|
||||||
|
},
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
teamId: team.id,
|
teamId: team.id,
|
||||||
}).catch(() => null);
|
}).catch(() => null);
|
||||||
@ -171,7 +177,7 @@ export default function DocumentPage() {
|
|||||||
|
|
||||||
{document.status !== DocumentStatus.COMPLETED && (
|
{document.status !== DocumentStatus.COMPLETED && (
|
||||||
<DocumentReadOnlyFields
|
<DocumentReadOnlyFields
|
||||||
fields={document.fields}
|
fields={mapFieldsWithRecipients(document.fields, recipients)}
|
||||||
documentMeta={documentMeta || undefined}
|
documentMeta={documentMeta || undefined}
|
||||||
showRecipientTooltip={true}
|
showRecipientTooltip={true}
|
||||||
showRecipientColors={true}
|
showRecipientColors={true}
|
||||||
|
|||||||
@ -42,7 +42,10 @@ export async function loader({ params, request }: Route.LoaderArgs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const document = await getDocumentWithDetailsById({
|
const document = await getDocumentWithDetailsById({
|
||||||
documentId,
|
id: {
|
||||||
|
type: 'documentId',
|
||||||
|
id: documentId,
|
||||||
|
},
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
teamId: team.id,
|
teamId: team.id,
|
||||||
}).catch(() => null);
|
}).catch(() => null);
|
||||||
|
|||||||
@ -2,15 +2,16 @@ import type { MessageDescriptor } from '@lingui/core';
|
|||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import type { Recipient } from '@prisma/client';
|
import { EnvelopeType, type Recipient } from '@prisma/client';
|
||||||
import { ChevronLeft } from 'lucide-react';
|
import { ChevronLeft } from 'lucide-react';
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
import { Link, redirect } from 'react-router';
|
import { Link, redirect } from 'react-router';
|
||||||
|
|
||||||
import { getSession } from '@documenso/auth/server/lib/utils/get-session';
|
import { getSession } from '@documenso/auth/server/lib/utils/get-session';
|
||||||
import { getDocumentById } from '@documenso/lib/server-only/document/get-document-by-id';
|
import { getEnvelopeById } from '@documenso/lib/server-only/envelope/get-envelope-by-id';
|
||||||
import { getRecipientsForDocument } from '@documenso/lib/server-only/recipient/get-recipients-for-document';
|
import { getRecipientsForDocument } from '@documenso/lib/server-only/recipient/get-recipients-for-document';
|
||||||
import { getTeamByUrl } from '@documenso/lib/server-only/team/get-team';
|
import { getTeamByUrl } from '@documenso/lib/server-only/team/get-team';
|
||||||
|
import { mapSecondaryIdToDocumentId } from '@documenso/lib/utils/envelope';
|
||||||
import { logDocumentAccess } from '@documenso/lib/utils/logger';
|
import { logDocumentAccess } from '@documenso/lib/utils/logger';
|
||||||
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
||||||
import { Card } from '@documenso/ui/primitives/card';
|
import { Card } from '@documenso/ui/primitives/card';
|
||||||
@ -40,13 +41,17 @@ export async function loader({ params, request }: Route.LoaderArgs) {
|
|||||||
throw redirect(documentRootPath);
|
throw redirect(documentRootPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
const document = await getDocumentById({
|
const envelope = await getEnvelopeById({
|
||||||
documentId,
|
id: {
|
||||||
|
type: 'documentId',
|
||||||
|
id: documentId,
|
||||||
|
},
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
teamId: team?.id,
|
teamId: team.id,
|
||||||
}).catch(() => null);
|
}).catch(() => null);
|
||||||
|
|
||||||
if (!document || !document.documentData) {
|
if (!envelope) {
|
||||||
throw redirect(documentRootPath);
|
throw redirect(documentRootPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +68,19 @@ export async function loader({ params, request }: Route.LoaderArgs) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
document,
|
// Only return necessary data
|
||||||
|
document: {
|
||||||
|
id: mapSecondaryIdToDocumentId(envelope.secondaryId),
|
||||||
|
title: envelope.title,
|
||||||
|
status: envelope.status,
|
||||||
|
user: {
|
||||||
|
name: envelope.user.name,
|
||||||
|
email: envelope.user.email,
|
||||||
|
},
|
||||||
|
createdAt: envelope.createdAt,
|
||||||
|
updatedAt: envelope.updatedAt,
|
||||||
|
documentMeta: envelope.documentMeta,
|
||||||
|
},
|
||||||
recipients,
|
recipients,
|
||||||
documentRootPath,
|
documentRootPath,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -2,8 +2,7 @@ import { useEffect, useMemo, useState } from 'react';
|
|||||||
|
|
||||||
import { useLingui } from '@lingui/react/macro';
|
import { useLingui } from '@lingui/react/macro';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import type { TemplateDirectLink } from '@prisma/client';
|
import { type TemplateDirectLink, TemplateType } from '@prisma/client';
|
||||||
import { TemplateType } from '@prisma/client';
|
|
||||||
|
|
||||||
import { getSession } from '@documenso/auth/server/lib/utils/get-session';
|
import { getSession } from '@documenso/auth/server/lib/utils/get-session';
|
||||||
import { useSession } from '@documenso/lib/client-only/providers/session';
|
import { useSession } from '@documenso/lib/client-only/providers/session';
|
||||||
|
|||||||
@ -1,14 +1,16 @@
|
|||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
|
import { EnvelopeType } from '@prisma/client';
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
import { redirect } from 'react-router';
|
import { redirect } from 'react-router';
|
||||||
|
|
||||||
import { DOCUMENT_STATUS } from '@documenso/lib/constants/document';
|
import { DOCUMENT_STATUS } from '@documenso/lib/constants/document';
|
||||||
import { APP_I18N_OPTIONS, ZSupportedLanguageCodeSchema } from '@documenso/lib/constants/i18n';
|
import { APP_I18N_OPTIONS, ZSupportedLanguageCodeSchema } from '@documenso/lib/constants/i18n';
|
||||||
import { RECIPIENT_ROLES_DESCRIPTION } from '@documenso/lib/constants/recipient-roles';
|
import { RECIPIENT_ROLES_DESCRIPTION } from '@documenso/lib/constants/recipient-roles';
|
||||||
import { getEntireDocument } from '@documenso/lib/server-only/admin/get-entire-document';
|
import { unsafeGetEntireEnvelope } from '@documenso/lib/server-only/admin/get-entire-document';
|
||||||
import { decryptSecondaryData } from '@documenso/lib/server-only/crypto/decrypt';
|
import { decryptSecondaryData } from '@documenso/lib/server-only/crypto/decrypt';
|
||||||
import { findDocumentAuditLogs } from '@documenso/lib/server-only/document/find-document-audit-logs';
|
import { findDocumentAuditLogs } from '@documenso/lib/server-only/document/find-document-audit-logs';
|
||||||
|
import { mapSecondaryIdToDocumentId } from '@documenso/lib/utils/envelope';
|
||||||
import { getTranslations } from '@documenso/lib/utils/i18n';
|
import { getTranslations } from '@documenso/lib/utils/i18n';
|
||||||
import { Card, CardContent } from '@documenso/ui/primitives/card';
|
import { Card, CardContent } from '@documenso/ui/primitives/card';
|
||||||
|
|
||||||
@ -39,20 +41,24 @@ export async function loader({ request }: Route.LoaderArgs) {
|
|||||||
|
|
||||||
const documentId = Number(rawDocumentId);
|
const documentId = Number(rawDocumentId);
|
||||||
|
|
||||||
const document = await getEntireDocument({
|
const envelope = await unsafeGetEntireEnvelope({
|
||||||
id: documentId,
|
id: {
|
||||||
|
type: 'documentId',
|
||||||
|
id: documentId,
|
||||||
|
},
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
}).catch(() => null);
|
}).catch(() => null);
|
||||||
|
|
||||||
if (!document) {
|
if (!envelope) {
|
||||||
throw redirect('/');
|
throw redirect('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
const documentLanguage = ZSupportedLanguageCodeSchema.parse(document.documentMeta?.language);
|
const documentLanguage = ZSupportedLanguageCodeSchema.parse(envelope.documentMeta?.language);
|
||||||
|
|
||||||
const { data: auditLogs } = await findDocumentAuditLogs({
|
const { data: auditLogs } = await findDocumentAuditLogs({
|
||||||
documentId: documentId,
|
documentId: documentId,
|
||||||
userId: document.userId,
|
userId: envelope.userId,
|
||||||
teamId: document.teamId,
|
teamId: envelope.teamId,
|
||||||
perPage: 100_000,
|
perPage: 100_000,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -60,7 +66,20 @@ export async function loader({ request }: Route.LoaderArgs) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
auditLogs,
|
auditLogs,
|
||||||
document,
|
document: {
|
||||||
|
id: mapSecondaryIdToDocumentId(envelope.secondaryId),
|
||||||
|
title: envelope.title,
|
||||||
|
status: envelope.status,
|
||||||
|
user: {
|
||||||
|
name: envelope.user.name,
|
||||||
|
email: envelope.user.email,
|
||||||
|
},
|
||||||
|
recipients: envelope.recipients,
|
||||||
|
createdAt: envelope.createdAt,
|
||||||
|
updatedAt: envelope.updatedAt,
|
||||||
|
deletedAt: envelope.deletedAt,
|
||||||
|
documentMeta: envelope.documentMeta,
|
||||||
|
},
|
||||||
documentLanguage,
|
documentLanguage,
|
||||||
messages,
|
messages,
|
||||||
};
|
};
|
||||||
@ -90,6 +109,7 @@ export default function AuditLog({ loaderData }: Route.ComponentProps) {
|
|||||||
<Card>
|
<Card>
|
||||||
<CardContent className="grid grid-cols-2 gap-4 p-6 text-sm print:text-xs">
|
<CardContent className="grid grid-cols-2 gap-4 p-6 text-sm print:text-xs">
|
||||||
<p>
|
<p>
|
||||||
|
{/* Todo: Envelopes - Should we should envelope ID instead here? */}
|
||||||
<span className="font-medium">{_(msg`Document ID`)}</span>
|
<span className="font-medium">{_(msg`Document ID`)}</span>
|
||||||
|
|
||||||
<span className="mt-1 block break-words">{document.id}</span>
|
<span className="mt-1 block break-words">{document.id}</span>
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { FieldType, SigningStatus } from '@prisma/client';
|
import { EnvelopeType, FieldType, SigningStatus } from '@prisma/client';
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
import { redirect } from 'react-router';
|
import { redirect } from 'react-router';
|
||||||
import { prop, sortBy } from 'remeda';
|
import { prop, sortBy } from 'remeda';
|
||||||
@ -14,12 +14,13 @@ import {
|
|||||||
RECIPIENT_ROLES_DESCRIPTION,
|
RECIPIENT_ROLES_DESCRIPTION,
|
||||||
RECIPIENT_ROLE_SIGNING_REASONS,
|
RECIPIENT_ROLE_SIGNING_REASONS,
|
||||||
} from '@documenso/lib/constants/recipient-roles';
|
} from '@documenso/lib/constants/recipient-roles';
|
||||||
import { getEntireDocument } from '@documenso/lib/server-only/admin/get-entire-document';
|
import { unsafeGetEntireEnvelope } from '@documenso/lib/server-only/admin/get-entire-document';
|
||||||
import { decryptSecondaryData } from '@documenso/lib/server-only/crypto/decrypt';
|
import { decryptSecondaryData } from '@documenso/lib/server-only/crypto/decrypt';
|
||||||
import { getDocumentCertificateAuditLogs } from '@documenso/lib/server-only/document/get-document-certificate-audit-logs';
|
import { getDocumentCertificateAuditLogs } from '@documenso/lib/server-only/document/get-document-certificate-audit-logs';
|
||||||
import { getOrganisationClaimByTeamId } from '@documenso/lib/server-only/organisation/get-organisation-claims';
|
import { getOrganisationClaimByTeamId } from '@documenso/lib/server-only/organisation/get-organisation-claims';
|
||||||
import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-logs';
|
import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-logs';
|
||||||
import { extractDocumentAuthMethods } from '@documenso/lib/utils/document-auth';
|
import { extractDocumentAuthMethods } from '@documenso/lib/utils/document-auth';
|
||||||
|
import { mapSecondaryIdToDocumentId } from '@documenso/lib/utils/envelope';
|
||||||
import { getTranslations } from '@documenso/lib/utils/i18n';
|
import { getTranslations } from '@documenso/lib/utils/i18n';
|
||||||
import { Card, CardContent } from '@documenso/ui/primitives/card';
|
import { Card, CardContent } from '@documenso/ui/primitives/card';
|
||||||
import {
|
import {
|
||||||
@ -55,26 +56,45 @@ export async function loader({ request }: Route.LoaderArgs) {
|
|||||||
|
|
||||||
const documentId = Number(rawDocumentId);
|
const documentId = Number(rawDocumentId);
|
||||||
|
|
||||||
const document = await getEntireDocument({
|
const envelope = await unsafeGetEntireEnvelope({
|
||||||
id: documentId,
|
id: {
|
||||||
|
type: 'documentId',
|
||||||
|
id: documentId,
|
||||||
|
},
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
}).catch(() => null);
|
}).catch(() => null);
|
||||||
|
|
||||||
if (!document) {
|
if (!envelope) {
|
||||||
throw redirect('/');
|
throw redirect('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
const organisationClaim = await getOrganisationClaimByTeamId({ teamId: document.teamId });
|
const organisationClaim = await getOrganisationClaimByTeamId({ teamId: envelope.teamId });
|
||||||
|
|
||||||
const documentLanguage = ZSupportedLanguageCodeSchema.parse(document.documentMeta?.language);
|
const documentLanguage = ZSupportedLanguageCodeSchema.parse(envelope.documentMeta?.language);
|
||||||
|
|
||||||
const auditLogs = await getDocumentCertificateAuditLogs({
|
const auditLogs = await getDocumentCertificateAuditLogs({
|
||||||
id: documentId,
|
envelopeId: envelope.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
const messages = await getTranslations(documentLanguage);
|
const messages = await getTranslations(documentLanguage);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
document,
|
document: {
|
||||||
|
id: mapSecondaryIdToDocumentId(envelope.secondaryId),
|
||||||
|
title: envelope.title,
|
||||||
|
status: envelope.status,
|
||||||
|
user: {
|
||||||
|
name: envelope.user.name,
|
||||||
|
email: envelope.user.email,
|
||||||
|
},
|
||||||
|
qrToken: envelope.qrToken,
|
||||||
|
authOptions: envelope.authOptions,
|
||||||
|
recipients: envelope.recipients,
|
||||||
|
createdAt: envelope.createdAt,
|
||||||
|
updatedAt: envelope.updatedAt,
|
||||||
|
deletedAt: envelope.deletedAt,
|
||||||
|
documentMeta: envelope.documentMeta,
|
||||||
|
},
|
||||||
hidePoweredBy: organisationClaim.flags.hidePoweredBy,
|
hidePoweredBy: organisationClaim.flags.hidePoweredBy,
|
||||||
documentLanguage,
|
documentLanguage,
|
||||||
auditLogs,
|
auditLogs,
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { useEffect } from 'react';
|
|||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import { type Document, DocumentStatus, FieldType, RecipientRole } from '@prisma/client';
|
import { DocumentStatus, FieldType, RecipientRole } from '@prisma/client';
|
||||||
import { CheckCircle2, Clock8, FileSearch } from 'lucide-react';
|
import { CheckCircle2, Clock8, FileSearch } from 'lucide-react';
|
||||||
import { Link, useRevalidator } from 'react-router';
|
import { Link, useRevalidator } from 'react-router';
|
||||||
import { match } from 'ts-pattern';
|
import { match } from 'ts-pattern';
|
||||||
@ -19,6 +19,7 @@ import { getRecipientSignatures } from '@documenso/lib/server-only/recipient/get
|
|||||||
import { getUserByEmail } from '@documenso/lib/server-only/user/get-user-by-email';
|
import { getUserByEmail } from '@documenso/lib/server-only/user/get-user-by-email';
|
||||||
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
||||||
import { env } from '@documenso/lib/utils/env';
|
import { env } from '@documenso/lib/utils/env';
|
||||||
|
import type { Document } from '@documenso/prisma/types/document-legacy-schema';
|
||||||
import DocumentDialog from '@documenso/ui/components/document/document-dialog';
|
import DocumentDialog from '@documenso/ui/components/document/document-dialog';
|
||||||
import { DocumentDownloadButton } from '@documenso/ui/components/document/document-download-button';
|
import { DocumentDownloadButton } from '@documenso/ui/components/document/document-download-button';
|
||||||
import { DocumentShareButton } from '@documenso/ui/components/document/document-share-button';
|
import { DocumentShareButton } from '@documenso/ui/components/document/document-share-button';
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import type { Team } from '@prisma/client';
|
import type { Team } from '@prisma/client';
|
||||||
import { DocumentStatus } from '@prisma/client';
|
import { DocumentStatus, EnvelopeType } from '@prisma/client';
|
||||||
import { Link, redirect } from 'react-router';
|
import { Link, redirect } from 'react-router';
|
||||||
|
|
||||||
import { getOptionalSession } from '@documenso/auth/server/lib/utils/get-session';
|
import { getOptionalSession } from '@documenso/auth/server/lib/utils/get-session';
|
||||||
import { getDocumentById } from '@documenso/lib/server-only/document/get-document-by-id';
|
|
||||||
import { getDocumentAndSenderByToken } from '@documenso/lib/server-only/document/get-document-by-token';
|
import { getDocumentAndSenderByToken } from '@documenso/lib/server-only/document/get-document-by-token';
|
||||||
|
import { getEnvelopeById } from '@documenso/lib/server-only/envelope/get-envelope-by-id';
|
||||||
import { getRecipientByToken } from '@documenso/lib/server-only/recipient/get-recipient-by-token';
|
import { getRecipientByToken } from '@documenso/lib/server-only/recipient/get-recipient-by-token';
|
||||||
import { getTeamById } from '@documenso/lib/server-only/team/get-team';
|
import { getTeamById } from '@documenso/lib/server-only/team/get-team';
|
||||||
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
||||||
@ -40,12 +40,16 @@ export async function loader({ params, request }: Route.LoaderArgs) {
|
|||||||
let team: Team | null = null;
|
let team: Team | null = null;
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
isOwnerOrTeamMember = await getDocumentById({
|
isOwnerOrTeamMember = await getEnvelopeById({
|
||||||
documentId: document.id,
|
id: {
|
||||||
|
type: 'documentId',
|
||||||
|
id: document.id,
|
||||||
|
},
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
teamId: document.teamId ?? undefined,
|
teamId: document.teamId ?? undefined,
|
||||||
})
|
})
|
||||||
.then((document) => !!document)
|
.then((envelope) => !!envelope)
|
||||||
.catch(() => false);
|
.catch(() => false);
|
||||||
|
|
||||||
if (document.teamId) {
|
if (document.teamId) {
|
||||||
|
|||||||
@ -81,9 +81,9 @@ export default function SharePage() {
|
|||||||
<DocumentCertificateQRView
|
<DocumentCertificateQRView
|
||||||
documentId={document.id}
|
documentId={document.id}
|
||||||
title={document.title}
|
title={document.title}
|
||||||
documentData={document.documentData}
|
documentTeamUrl={document.documentTeamUrl}
|
||||||
password={document.documentMeta?.password}
|
documentData={document.documentData} // Todo: Envelopes
|
||||||
recipientCount={document.recipients?.length ?? 0}
|
recipientCount={document.recipientCount}
|
||||||
completedDate={document.completedAt ?? undefined}
|
completedDate={document.completedAt ?? undefined}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -54,7 +54,10 @@ export const loader = async ({ request, params }: Route.LoaderArgs) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const document = await getDocumentWithDetailsById({
|
const document = await getDocumentWithDetailsById({
|
||||||
documentId,
|
id: {
|
||||||
|
type: 'documentId',
|
||||||
|
id: documentId,
|
||||||
|
},
|
||||||
userId: result?.userId,
|
userId: result?.userId,
|
||||||
teamId: result?.teamId ?? undefined,
|
teamId: result?.teamId ?? undefined,
|
||||||
}).catch(() => null);
|
}).catch(() => null);
|
||||||
|
|||||||
@ -1,6 +1,11 @@
|
|||||||
|
import { EnvelopeType } from '@prisma/client';
|
||||||
import type { Context } from 'hono';
|
import type { Context } from 'hono';
|
||||||
|
|
||||||
import { getSession } from '@documenso/auth/server/lib/utils/get-session';
|
import { getSession } from '@documenso/auth/server/lib/utils/get-session';
|
||||||
|
import {
|
||||||
|
mapDocumentIdToSecondaryId,
|
||||||
|
mapTemplateIdToSecondaryId,
|
||||||
|
} from '@documenso/lib/utils/envelope';
|
||||||
import { buildTeamWhereQuery } from '@documenso/lib/utils/teams';
|
import { buildTeamWhereQuery } from '@documenso/lib/utils/teams';
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
@ -104,9 +109,10 @@ async function hasAccessToDocument(c: Context, documentId: number): Promise<stri
|
|||||||
|
|
||||||
const userId = session.user.id;
|
const userId = session.user.id;
|
||||||
|
|
||||||
const document = await prisma.document.findUnique({
|
const envelope = await prisma.envelope.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: documentId,
|
type: EnvelopeType.DOCUMENT,
|
||||||
|
secondaryId: mapDocumentIdToSecondaryId(documentId),
|
||||||
team: buildTeamWhereQuery({
|
team: buildTeamWhereQuery({
|
||||||
userId,
|
userId,
|
||||||
teamId: undefined,
|
teamId: undefined,
|
||||||
@ -121,7 +127,7 @@ async function hasAccessToDocument(c: Context, documentId: number): Promise<stri
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return document ? document.team.url : null;
|
return envelope ? envelope.team.url : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function hasAccessToFolder(c: Context, folderId: string): Promise<string | null> {
|
async function hasAccessToFolder(c: Context, folderId: string): Promise<string | null> {
|
||||||
@ -154,9 +160,10 @@ async function hasAccessToTemplate(c: Context, templateId: number): Promise<stri
|
|||||||
|
|
||||||
const userId = session.user.id;
|
const userId = session.user.id;
|
||||||
|
|
||||||
const template = await prisma.template.findUnique({
|
const envelope = await prisma.envelope.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: templateId,
|
type: EnvelopeType.TEMPLATE,
|
||||||
|
secondaryId: mapTemplateIdToSecondaryId(templateId),
|
||||||
team: buildTeamWhereQuery({
|
team: buildTeamWhereQuery({
|
||||||
userId,
|
userId,
|
||||||
teamId: undefined,
|
teamId: undefined,
|
||||||
@ -171,5 +178,5 @@ async function hasAccessToTemplate(c: Context, templateId: number): Promise<stri
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return template ? template.team.url : null;
|
return envelope ? envelope.team.url : null;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -8,8 +8,8 @@ import {
|
|||||||
RecipientRole,
|
RecipientRole,
|
||||||
SendStatus,
|
SendStatus,
|
||||||
SigningStatus,
|
SigningStatus,
|
||||||
TemplateType,
|
|
||||||
} from '@prisma/client';
|
} from '@prisma/client';
|
||||||
|
import { TemplateType } from '@prisma/client';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { DATE_FORMATS, DEFAULT_DOCUMENT_DATE_FORMAT } from '@documenso/lib/constants/date-formats';
|
import { DATE_FORMATS, DEFAULT_DOCUMENT_DATE_FORMAT } from '@documenso/lib/constants/date-formats';
|
||||||
@ -49,7 +49,6 @@ export const ZSuccessfulDocumentResponseSchema = z.object({
|
|||||||
teamId: z.number().nullish(),
|
teamId: z.number().nullish(),
|
||||||
title: z.string(),
|
title: z.string(),
|
||||||
status: z.string(),
|
status: z.string(),
|
||||||
documentDataId: z.string(),
|
|
||||||
createdAt: z.date(),
|
createdAt: z.date(),
|
||||||
updatedAt: z.date(),
|
updatedAt: z.date(),
|
||||||
completedAt: z.date().nullable(),
|
completedAt: z.date().nullable(),
|
||||||
@ -545,7 +544,6 @@ export const ZTemplateSchema = z.object({
|
|||||||
title: z.string(),
|
title: z.string(),
|
||||||
userId: z.number(),
|
userId: z.number(),
|
||||||
teamId: z.number().nullish(),
|
teamId: z.number().nullish(),
|
||||||
templateDocumentDataId: z.string(),
|
|
||||||
createdAt: z.date(),
|
createdAt: z.date(),
|
||||||
updatedAt: z.date(),
|
updatedAt: z.date(),
|
||||||
});
|
});
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import { expect, test } from '@playwright/test';
|
|||||||
|
|
||||||
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
||||||
import { createApiToken } from '@documenso/lib/server-only/public-api/create-api-token';
|
import { createApiToken } from '@documenso/lib/server-only/public-api/create-api-token';
|
||||||
|
import { mapSecondaryIdToDocumentId } from '@documenso/lib/utils/envelope';
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import { seedPendingDocumentWithFullFields } from '@documenso/prisma/seed/documents';
|
import { seedPendingDocumentWithFullFields } from '@documenso/prisma/seed/documents';
|
||||||
import { seedUser } from '@documenso/prisma/seed/users';
|
import { seedUser } from '@documenso/prisma/seed/users';
|
||||||
@ -25,7 +26,7 @@ test.describe('Document API', () => {
|
|||||||
|
|
||||||
// Test with sendCompletionEmails: false
|
// Test with sendCompletionEmails: false
|
||||||
const response = await request.post(
|
const response = await request.post(
|
||||||
`${NEXT_PUBLIC_WEBAPP_URL()}/api/v1/documents/${document.id}/send`,
|
`${NEXT_PUBLIC_WEBAPP_URL()}/api/v1/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/send`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
@ -41,7 +42,7 @@ test.describe('Document API', () => {
|
|||||||
expect(response.status()).toBe(200);
|
expect(response.status()).toBe(200);
|
||||||
|
|
||||||
// Verify email settings were updated
|
// Verify email settings were updated
|
||||||
const updatedDocument = await prisma.document.findUnique({
|
const updatedDocument = await prisma.envelope.findUnique({
|
||||||
where: { id: document.id },
|
where: { id: document.id },
|
||||||
include: { documentMeta: true },
|
include: { documentMeta: true },
|
||||||
});
|
});
|
||||||
@ -53,7 +54,7 @@ test.describe('Document API', () => {
|
|||||||
|
|
||||||
// Test with sendCompletionEmails: true
|
// Test with sendCompletionEmails: true
|
||||||
const response2 = await request.post(
|
const response2 = await request.post(
|
||||||
`${NEXT_PUBLIC_WEBAPP_URL()}/api/v1/documents/${document.id}/send`,
|
`${NEXT_PUBLIC_WEBAPP_URL()}/api/v1/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/send`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
@ -69,7 +70,7 @@ test.describe('Document API', () => {
|
|||||||
expect(response2.status()).toBe(200);
|
expect(response2.status()).toBe(200);
|
||||||
|
|
||||||
// Verify email settings were updated
|
// Verify email settings were updated
|
||||||
const updatedDocument2 = await prisma.document.findUnique({
|
const updatedDocument2 = await prisma.envelope.findUnique({
|
||||||
where: { id: document.id },
|
where: { id: document.id },
|
||||||
include: { documentMeta: true },
|
include: { documentMeta: true },
|
||||||
});
|
});
|
||||||
@ -93,16 +94,16 @@ test.describe('Document API', () => {
|
|||||||
|
|
||||||
// Set initial email settings
|
// Set initial email settings
|
||||||
await prisma.documentMeta.upsert({
|
await prisma.documentMeta.upsert({
|
||||||
where: { documentId: document.id },
|
where: { id: document.documentMetaId },
|
||||||
create: {
|
create: {
|
||||||
documentId: document.id,
|
id: document.documentMetaId,
|
||||||
emailSettings: {
|
emailSettings: {
|
||||||
documentCompleted: true,
|
documentCompleted: true,
|
||||||
ownerDocumentCompleted: false,
|
ownerDocumentCompleted: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
update: {
|
update: {
|
||||||
documentId: document.id,
|
id: document.documentMetaId,
|
||||||
emailSettings: {
|
emailSettings: {
|
||||||
documentCompleted: true,
|
documentCompleted: true,
|
||||||
ownerDocumentCompleted: false,
|
ownerDocumentCompleted: false,
|
||||||
@ -118,7 +119,7 @@ test.describe('Document API', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const response = await request.post(
|
const response = await request.post(
|
||||||
`${NEXT_PUBLIC_WEBAPP_URL()}/api/v1/documents/${document.id}/send`,
|
`${NEXT_PUBLIC_WEBAPP_URL()}/api/v1/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/send`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
@ -134,7 +135,7 @@ test.describe('Document API', () => {
|
|||||||
expect(response.status()).toBe(200);
|
expect(response.status()).toBe(200);
|
||||||
|
|
||||||
// Verify email settings were not modified
|
// Verify email settings were not modified
|
||||||
const updatedDocument = await prisma.document.findUnique({
|
const updatedDocument = await prisma.envelope.findUnique({
|
||||||
where: { id: document.id },
|
where: { id: document.id },
|
||||||
include: { documentMeta: true },
|
include: { documentMeta: true },
|
||||||
});
|
});
|
||||||
|
|||||||
@ -3,6 +3,11 @@ import { expect, test } from '@playwright/test';
|
|||||||
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
||||||
import { createApiToken } from '@documenso/lib/server-only/public-api/create-api-token';
|
import { createApiToken } from '@documenso/lib/server-only/public-api/create-api-token';
|
||||||
import type { TCheckboxFieldMeta, TRadioFieldMeta } from '@documenso/lib/types/field-meta';
|
import type { TCheckboxFieldMeta, TRadioFieldMeta } from '@documenso/lib/types/field-meta';
|
||||||
|
import {
|
||||||
|
mapDocumentIdToSecondaryId,
|
||||||
|
mapSecondaryIdToDocumentId,
|
||||||
|
mapSecondaryIdToTemplateId,
|
||||||
|
} from '@documenso/lib/utils/envelope';
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import { FieldType, RecipientRole } from '@documenso/prisma/client';
|
import { FieldType, RecipientRole } from '@documenso/prisma/client';
|
||||||
import { seedBlankTemplate } from '@documenso/prisma/seed/templates';
|
import { seedBlankTemplate } from '@documenso/prisma/seed/templates';
|
||||||
@ -35,10 +40,12 @@ test.describe('Template Field Prefill API v1', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const firstEnvelopeItem = template.envelopeItems[0];
|
||||||
|
|
||||||
// 4. Create a recipient for the template
|
// 4. Create a recipient for the template
|
||||||
const recipient = await prisma.recipient.create({
|
const recipient = await prisma.recipient.create({
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
envelopeId: template.id,
|
||||||
email: 'recipient@example.com',
|
email: 'recipient@example.com',
|
||||||
name: 'Test Recipient',
|
name: 'Test Recipient',
|
||||||
role: RecipientRole.SIGNER,
|
role: RecipientRole.SIGNER,
|
||||||
@ -53,7 +60,8 @@ test.describe('Template Field Prefill API v1', () => {
|
|||||||
// Add TEXT field
|
// Add TEXT field
|
||||||
const textField = await prisma.field.create({
|
const textField = await prisma.field.create({
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
envelopeId: template.id,
|
||||||
|
envelopeItemId: firstEnvelopeItem.id,
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
type: FieldType.TEXT,
|
type: FieldType.TEXT,
|
||||||
page: 1,
|
page: 1,
|
||||||
@ -73,7 +81,8 @@ test.describe('Template Field Prefill API v1', () => {
|
|||||||
// Add NUMBER field
|
// Add NUMBER field
|
||||||
const numberField = await prisma.field.create({
|
const numberField = await prisma.field.create({
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
envelopeId: template.id,
|
||||||
|
envelopeItemId: firstEnvelopeItem.id,
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
type: FieldType.NUMBER,
|
type: FieldType.NUMBER,
|
||||||
page: 1,
|
page: 1,
|
||||||
@ -93,7 +102,8 @@ test.describe('Template Field Prefill API v1', () => {
|
|||||||
// Add RADIO field
|
// Add RADIO field
|
||||||
const radioField = await prisma.field.create({
|
const radioField = await prisma.field.create({
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
envelopeId: template.id,
|
||||||
|
envelopeItemId: firstEnvelopeItem.id,
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
type: FieldType.RADIO,
|
type: FieldType.RADIO,
|
||||||
page: 1,
|
page: 1,
|
||||||
@ -117,7 +127,8 @@ test.describe('Template Field Prefill API v1', () => {
|
|||||||
// Add CHECKBOX field
|
// Add CHECKBOX field
|
||||||
const checkboxField = await prisma.field.create({
|
const checkboxField = await prisma.field.create({
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
envelopeId: template.id,
|
||||||
|
envelopeItemId: firstEnvelopeItem.id,
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
type: FieldType.CHECKBOX,
|
type: FieldType.CHECKBOX,
|
||||||
page: 1,
|
page: 1,
|
||||||
@ -141,7 +152,8 @@ test.describe('Template Field Prefill API v1', () => {
|
|||||||
// Add DROPDOWN field
|
// Add DROPDOWN field
|
||||||
const dropdownField = await prisma.field.create({
|
const dropdownField = await prisma.field.create({
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
envelopeId: template.id,
|
||||||
|
envelopeItemId: firstEnvelopeItem.id,
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
type: FieldType.DROPDOWN,
|
type: FieldType.DROPDOWN,
|
||||||
page: 1,
|
page: 1,
|
||||||
@ -166,11 +178,13 @@ test.describe('Template Field Prefill API v1', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 7. Navigate to the template
|
// 7. Navigate to the template
|
||||||
await page.goto(`${WEBAPP_BASE_URL}/templates/${template.id}`);
|
await page.goto(
|
||||||
|
`${WEBAPP_BASE_URL}/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}`,
|
||||||
|
);
|
||||||
|
|
||||||
// 8. Create a document from the template with prefilled fields
|
// 8. Create a document from the template with prefilled fields
|
||||||
const response = await request.post(
|
const response = await request.post(
|
||||||
`${WEBAPP_BASE_URL}/api/v1/templates/${template.id}/generate-document`,
|
`${WEBAPP_BASE_URL}/api/v1/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}/generate-document`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
@ -229,9 +243,9 @@ test.describe('Template Field Prefill API v1', () => {
|
|||||||
expect(responseData.documentId).toBeDefined();
|
expect(responseData.documentId).toBeDefined();
|
||||||
|
|
||||||
// 9. Verify the document was created with prefilled fields
|
// 9. Verify the document was created with prefilled fields
|
||||||
const document = await prisma.document.findUnique({
|
const document = await prisma.envelope.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: responseData.documentId,
|
secondaryId: mapDocumentIdToSecondaryId(responseData.documentId),
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
fields: true,
|
fields: true,
|
||||||
@ -240,6 +254,10 @@ test.describe('Template Field Prefill API v1', () => {
|
|||||||
|
|
||||||
expect(document).not.toBeNull();
|
expect(document).not.toBeNull();
|
||||||
|
|
||||||
|
if (!document) {
|
||||||
|
throw new Error('Document not found');
|
||||||
|
}
|
||||||
|
|
||||||
// 10. Verify each field has the correct prefilled values
|
// 10. Verify each field has the correct prefilled values
|
||||||
const documentTextField = document?.fields.find(
|
const documentTextField = document?.fields.find(
|
||||||
(field) => field.type === FieldType.TEXT && field.fieldMeta?.type === 'text',
|
(field) => field.type === FieldType.TEXT && field.fieldMeta?.type === 'text',
|
||||||
@ -297,14 +315,14 @@ test.describe('Template Field Prefill API v1', () => {
|
|||||||
// 11. Sign in as the recipient and verify the prefilled fields are visible
|
// 11. Sign in as the recipient and verify the prefilled fields are visible
|
||||||
const documentRecipient = await prisma.recipient.findFirst({
|
const documentRecipient = await prisma.recipient.findFirst({
|
||||||
where: {
|
where: {
|
||||||
documentId: document?.id,
|
envelopeId: document?.id,
|
||||||
email: 'recipient@example.com',
|
email: 'recipient@example.com',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Send the document to the recipient
|
// Send the document to the recipient
|
||||||
const sendResponse = await request.post(
|
const sendResponse = await request.post(
|
||||||
`${WEBAPP_BASE_URL}/api/v1/documents/${document?.id}/send`,
|
`${WEBAPP_BASE_URL}/api/v1/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/send`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
@ -367,10 +385,12 @@ test.describe('Template Field Prefill API v1', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const firstEnvelopeItem = template.envelopeItems[0];
|
||||||
|
|
||||||
// 4. Create a recipient for the template
|
// 4. Create a recipient for the template
|
||||||
const recipient = await prisma.recipient.create({
|
const recipient = await prisma.recipient.create({
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
envelopeId: template.id,
|
||||||
email: 'recipient@example.com',
|
email: 'recipient@example.com',
|
||||||
name: 'Test Recipient',
|
name: 'Test Recipient',
|
||||||
role: RecipientRole.SIGNER,
|
role: RecipientRole.SIGNER,
|
||||||
@ -385,7 +405,8 @@ test.describe('Template Field Prefill API v1', () => {
|
|||||||
// Add TEXT field
|
// Add TEXT field
|
||||||
await prisma.field.create({
|
await prisma.field.create({
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
envelopeId: template.id,
|
||||||
|
envelopeItemId: firstEnvelopeItem.id,
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
type: FieldType.TEXT,
|
type: FieldType.TEXT,
|
||||||
page: 1,
|
page: 1,
|
||||||
@ -405,7 +426,8 @@ test.describe('Template Field Prefill API v1', () => {
|
|||||||
// Add NUMBER field
|
// Add NUMBER field
|
||||||
await prisma.field.create({
|
await prisma.field.create({
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
envelopeId: template.id,
|
||||||
|
envelopeItemId: firstEnvelopeItem.id,
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
type: FieldType.NUMBER,
|
type: FieldType.NUMBER,
|
||||||
page: 1,
|
page: 1,
|
||||||
@ -429,11 +451,13 @@ test.describe('Template Field Prefill API v1', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 7. Navigate to the template
|
// 7. Navigate to the template
|
||||||
await page.goto(`${WEBAPP_BASE_URL}/templates/${template.id}`);
|
await page.goto(
|
||||||
|
`${WEBAPP_BASE_URL}/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}`,
|
||||||
|
);
|
||||||
|
|
||||||
// 8. Create a document from the template without prefilled fields
|
// 8. Create a document from the template without prefilled fields
|
||||||
const response = await request.post(
|
const response = await request.post(
|
||||||
`${WEBAPP_BASE_URL}/api/v1/templates/${template.id}/generate-document`,
|
`${WEBAPP_BASE_URL}/api/v1/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}/generate-document`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
@ -461,9 +485,9 @@ test.describe('Template Field Prefill API v1', () => {
|
|||||||
expect(responseData.documentId).toBeDefined();
|
expect(responseData.documentId).toBeDefined();
|
||||||
|
|
||||||
// 9. Verify the document was created with default fields
|
// 9. Verify the document was created with default fields
|
||||||
const document = await prisma.document.findUnique({
|
const document = await prisma.envelope.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: responseData.documentId,
|
secondaryId: mapDocumentIdToSecondaryId(responseData.documentId),
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
fields: true,
|
fields: true,
|
||||||
@ -472,6 +496,10 @@ test.describe('Template Field Prefill API v1', () => {
|
|||||||
|
|
||||||
expect(document).not.toBeNull();
|
expect(document).not.toBeNull();
|
||||||
|
|
||||||
|
if (!document) {
|
||||||
|
throw new Error('Document not found');
|
||||||
|
}
|
||||||
|
|
||||||
// 10. Verify fields have their default values
|
// 10. Verify fields have their default values
|
||||||
const documentTextField = document?.fields.find((field) => field.type === FieldType.TEXT);
|
const documentTextField = document?.fields.find((field) => field.type === FieldType.TEXT);
|
||||||
expect(documentTextField?.fieldMeta).toMatchObject({
|
expect(documentTextField?.fieldMeta).toMatchObject({
|
||||||
@ -488,7 +516,7 @@ test.describe('Template Field Prefill API v1', () => {
|
|||||||
// 11. Sign in as the recipient and verify the default fields are visible
|
// 11. Sign in as the recipient and verify the default fields are visible
|
||||||
const documentRecipient = await prisma.recipient.findFirst({
|
const documentRecipient = await prisma.recipient.findFirst({
|
||||||
where: {
|
where: {
|
||||||
documentId: document?.id,
|
envelopeId: document?.id,
|
||||||
email: 'recipient@example.com',
|
email: 'recipient@example.com',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -496,7 +524,7 @@ test.describe('Template Field Prefill API v1', () => {
|
|||||||
expect(documentRecipient).not.toBeNull();
|
expect(documentRecipient).not.toBeNull();
|
||||||
|
|
||||||
const sendResponse = await request.post(
|
const sendResponse = await request.post(
|
||||||
`${WEBAPP_BASE_URL}/api/v1/documents/${document?.id}/send`,
|
`${WEBAPP_BASE_URL}/api/v1/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/send`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
@ -539,10 +567,12 @@ test.describe('Template Field Prefill API v1', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const firstEnvelopeItem = template.envelopeItems[0];
|
||||||
|
|
||||||
// 4. Create a recipient for the template
|
// 4. Create a recipient for the template
|
||||||
const recipient = await prisma.recipient.create({
|
const recipient = await prisma.recipient.create({
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
envelopeId: template.id,
|
||||||
email: 'recipient@example.com',
|
email: 'recipient@example.com',
|
||||||
name: 'Test Recipient',
|
name: 'Test Recipient',
|
||||||
role: RecipientRole.SIGNER,
|
role: RecipientRole.SIGNER,
|
||||||
@ -556,7 +586,8 @@ test.describe('Template Field Prefill API v1', () => {
|
|||||||
// 5. Add a field to the template
|
// 5. Add a field to the template
|
||||||
const field = await prisma.field.create({
|
const field = await prisma.field.create({
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
envelopeId: template.id,
|
||||||
|
envelopeItemId: firstEnvelopeItem.id,
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
type: FieldType.RADIO,
|
type: FieldType.RADIO,
|
||||||
page: 1,
|
page: 1,
|
||||||
@ -579,7 +610,7 @@ test.describe('Template Field Prefill API v1', () => {
|
|||||||
|
|
||||||
// 6. Try to create a document with invalid prefill value
|
// 6. Try to create a document with invalid prefill value
|
||||||
const response = await request.post(
|
const response = await request.post(
|
||||||
`${WEBAPP_BASE_URL}/api/v1/templates/${template.id}/generate-document`,
|
`${WEBAPP_BASE_URL}/api/v1/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}/generate-document`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,11 @@ import { expect, test } from '@playwright/test';
|
|||||||
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
||||||
import { createApiToken } from '@documenso/lib/server-only/public-api/create-api-token';
|
import { createApiToken } from '@documenso/lib/server-only/public-api/create-api-token';
|
||||||
import type { TCheckboxFieldMeta, TRadioFieldMeta } from '@documenso/lib/types/field-meta';
|
import type { TCheckboxFieldMeta, TRadioFieldMeta } from '@documenso/lib/types/field-meta';
|
||||||
|
import {
|
||||||
|
mapDocumentIdToSecondaryId,
|
||||||
|
mapSecondaryIdToDocumentId,
|
||||||
|
mapSecondaryIdToTemplateId,
|
||||||
|
} from '@documenso/lib/utils/envelope';
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import { FieldType, RecipientRole } from '@documenso/prisma/client';
|
import { FieldType, RecipientRole } from '@documenso/prisma/client';
|
||||||
import { seedBlankTemplate } from '@documenso/prisma/seed/templates';
|
import { seedBlankTemplate } from '@documenso/prisma/seed/templates';
|
||||||
@ -35,10 +40,12 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const firstEnvelopeItem = template.envelopeItems[0];
|
||||||
|
|
||||||
// 4. Create a recipient for the template
|
// 4. Create a recipient for the template
|
||||||
const recipient = await prisma.recipient.create({
|
const recipient = await prisma.recipient.create({
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
envelopeId: template.id,
|
||||||
email: 'recipient@example.com',
|
email: 'recipient@example.com',
|
||||||
name: 'Test Recipient',
|
name: 'Test Recipient',
|
||||||
role: RecipientRole.SIGNER,
|
role: RecipientRole.SIGNER,
|
||||||
@ -53,7 +60,8 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
// Add TEXT field
|
// Add TEXT field
|
||||||
const textField = await prisma.field.create({
|
const textField = await prisma.field.create({
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
envelopeId: template.id,
|
||||||
|
envelopeItemId: firstEnvelopeItem.id,
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
type: FieldType.TEXT,
|
type: FieldType.TEXT,
|
||||||
page: 1,
|
page: 1,
|
||||||
@ -73,7 +81,8 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
// Add NUMBER field
|
// Add NUMBER field
|
||||||
const numberField = await prisma.field.create({
|
const numberField = await prisma.field.create({
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
envelopeId: template.id,
|
||||||
|
envelopeItemId: firstEnvelopeItem.id,
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
type: FieldType.NUMBER,
|
type: FieldType.NUMBER,
|
||||||
page: 1,
|
page: 1,
|
||||||
@ -93,7 +102,8 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
// Add RADIO field
|
// Add RADIO field
|
||||||
const radioField = await prisma.field.create({
|
const radioField = await prisma.field.create({
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
envelopeId: template.id,
|
||||||
|
envelopeItemId: firstEnvelopeItem.id,
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
type: FieldType.RADIO,
|
type: FieldType.RADIO,
|
||||||
page: 1,
|
page: 1,
|
||||||
@ -117,7 +127,8 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
// Add CHECKBOX field
|
// Add CHECKBOX field
|
||||||
const checkboxField = await prisma.field.create({
|
const checkboxField = await prisma.field.create({
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
envelopeId: template.id,
|
||||||
|
envelopeItemId: firstEnvelopeItem.id,
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
type: FieldType.CHECKBOX,
|
type: FieldType.CHECKBOX,
|
||||||
page: 1,
|
page: 1,
|
||||||
@ -141,7 +152,8 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
// Add DROPDOWN field
|
// Add DROPDOWN field
|
||||||
const dropdownField = await prisma.field.create({
|
const dropdownField = await prisma.field.create({
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
envelopeId: template.id,
|
||||||
|
envelopeItemId: firstEnvelopeItem.id,
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
type: FieldType.DROPDOWN,
|
type: FieldType.DROPDOWN,
|
||||||
page: 1,
|
page: 1,
|
||||||
@ -166,7 +178,9 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 7. Navigate to the template
|
// 7. Navigate to the template
|
||||||
await page.goto(`${WEBAPP_BASE_URL}/templates/${template.id}`);
|
await page.goto(
|
||||||
|
`${WEBAPP_BASE_URL}/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}`,
|
||||||
|
);
|
||||||
|
|
||||||
// 8. Create a document from the template with prefilled fields using v2 API
|
// 8. Create a document from the template with prefilled fields using v2 API
|
||||||
const response = await request.post(`${WEBAPP_BASE_URL}/api/v2-beta/template/use`, {
|
const response = await request.post(`${WEBAPP_BASE_URL}/api/v2-beta/template/use`, {
|
||||||
@ -175,7 +189,7 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
templateId: mapSecondaryIdToTemplateId(template.secondaryId),
|
||||||
recipients: [
|
recipients: [
|
||||||
{
|
{
|
||||||
id: recipient.id,
|
id: recipient.id,
|
||||||
@ -226,9 +240,9 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
expect(responseData.id).toBeDefined();
|
expect(responseData.id).toBeDefined();
|
||||||
|
|
||||||
// 9. Verify the document was created with prefilled fields
|
// 9. Verify the document was created with prefilled fields
|
||||||
const document = await prisma.document.findUnique({
|
const document = await prisma.envelope.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: responseData.id,
|
secondaryId: mapDocumentIdToSecondaryId(responseData.id),
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
fields: true,
|
fields: true,
|
||||||
@ -237,6 +251,10 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
|
|
||||||
expect(document).not.toBeNull();
|
expect(document).not.toBeNull();
|
||||||
|
|
||||||
|
if (!document) {
|
||||||
|
throw new Error('Document not found');
|
||||||
|
}
|
||||||
|
|
||||||
// 10. Verify each field has the correct prefilled values
|
// 10. Verify each field has the correct prefilled values
|
||||||
const documentTextField = document?.fields.find(
|
const documentTextField = document?.fields.find(
|
||||||
(field) => field.type === FieldType.TEXT && field.fieldMeta?.type === 'text',
|
(field) => field.type === FieldType.TEXT && field.fieldMeta?.type === 'text',
|
||||||
@ -297,7 +315,7 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
documentId: document?.id,
|
documentId: mapSecondaryIdToDocumentId(document?.secondaryId),
|
||||||
meta: {
|
meta: {
|
||||||
subject: 'Test Subject',
|
subject: 'Test Subject',
|
||||||
message: 'Test Message',
|
message: 'Test Message',
|
||||||
@ -311,7 +329,7 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
// 11. Sign in as the recipient and verify the prefilled fields are visible
|
// 11. Sign in as the recipient and verify the prefilled fields are visible
|
||||||
const documentRecipient = await prisma.recipient.findFirst({
|
const documentRecipient = await prisma.recipient.findFirst({
|
||||||
where: {
|
where: {
|
||||||
documentId: document?.id,
|
envelopeId: document?.id,
|
||||||
email: 'recipient@example.com',
|
email: 'recipient@example.com',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -364,10 +382,12 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const firstEnvelopeItem = template.envelopeItems[0];
|
||||||
|
|
||||||
// 4. Create a recipient for the template
|
// 4. Create a recipient for the template
|
||||||
const recipient = await prisma.recipient.create({
|
const recipient = await prisma.recipient.create({
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
envelopeId: template.id,
|
||||||
email: 'recipient@example.com',
|
email: 'recipient@example.com',
|
||||||
name: 'Test Recipient',
|
name: 'Test Recipient',
|
||||||
role: RecipientRole.SIGNER,
|
role: RecipientRole.SIGNER,
|
||||||
@ -382,7 +402,8 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
// Add TEXT field
|
// Add TEXT field
|
||||||
await prisma.field.create({
|
await prisma.field.create({
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
envelopeId: template.id,
|
||||||
|
envelopeItemId: firstEnvelopeItem.id,
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
type: FieldType.TEXT,
|
type: FieldType.TEXT,
|
||||||
page: 1,
|
page: 1,
|
||||||
@ -402,7 +423,8 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
// Add NUMBER field
|
// Add NUMBER field
|
||||||
await prisma.field.create({
|
await prisma.field.create({
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
envelopeId: template.id,
|
||||||
|
envelopeItemId: firstEnvelopeItem.id,
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
type: FieldType.NUMBER,
|
type: FieldType.NUMBER,
|
||||||
page: 1,
|
page: 1,
|
||||||
@ -426,7 +448,9 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 7. Navigate to the template
|
// 7. Navigate to the template
|
||||||
await page.goto(`${WEBAPP_BASE_URL}/templates/${template.id}`);
|
await page.goto(
|
||||||
|
`${WEBAPP_BASE_URL}/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}`,
|
||||||
|
);
|
||||||
|
|
||||||
// 8. Create a document from the template without prefilled fields using v2 API
|
// 8. Create a document from the template without prefilled fields using v2 API
|
||||||
const response = await request.post(`${WEBAPP_BASE_URL}/api/v2-beta/template/use`, {
|
const response = await request.post(`${WEBAPP_BASE_URL}/api/v2-beta/template/use`, {
|
||||||
@ -435,7 +459,7 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
templateId: mapSecondaryIdToTemplateId(template.secondaryId),
|
||||||
recipients: [
|
recipients: [
|
||||||
{
|
{
|
||||||
id: recipient.id,
|
id: recipient.id,
|
||||||
@ -454,9 +478,9 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
expect(responseData.id).toBeDefined();
|
expect(responseData.id).toBeDefined();
|
||||||
|
|
||||||
// 9. Verify the document was created with default fields
|
// 9. Verify the document was created with default fields
|
||||||
const document = await prisma.document.findUnique({
|
const document = await prisma.envelope.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: responseData.id,
|
secondaryId: mapDocumentIdToSecondaryId(responseData.id),
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
fields: true,
|
fields: true,
|
||||||
@ -465,6 +489,10 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
|
|
||||||
expect(document).not.toBeNull();
|
expect(document).not.toBeNull();
|
||||||
|
|
||||||
|
if (!document) {
|
||||||
|
throw new Error('Document not found');
|
||||||
|
}
|
||||||
|
|
||||||
// 10. Verify fields have their default values
|
// 10. Verify fields have their default values
|
||||||
const documentTextField = document?.fields.find((field) => field.type === FieldType.TEXT);
|
const documentTextField = document?.fields.find((field) => field.type === FieldType.TEXT);
|
||||||
expect(documentTextField?.fieldMeta).toMatchObject({
|
expect(documentTextField?.fieldMeta).toMatchObject({
|
||||||
@ -484,7 +512,7 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
documentId: document?.id,
|
documentId: mapSecondaryIdToDocumentId(document?.secondaryId),
|
||||||
meta: {
|
meta: {
|
||||||
subject: 'Test Subject',
|
subject: 'Test Subject',
|
||||||
message: 'Test Message',
|
message: 'Test Message',
|
||||||
@ -498,7 +526,7 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
// 11. Sign in as the recipient and verify the default fields are visible
|
// 11. Sign in as the recipient and verify the default fields are visible
|
||||||
const documentRecipient = await prisma.recipient.findFirst({
|
const documentRecipient = await prisma.recipient.findFirst({
|
||||||
where: {
|
where: {
|
||||||
documentId: document?.id,
|
envelopeId: document?.id,
|
||||||
email: 'recipient@example.com',
|
email: 'recipient@example.com',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -531,10 +559,12 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const firstEnvelopeItem = template.envelopeItems[0];
|
||||||
|
|
||||||
// 4. Create a recipient for the template
|
// 4. Create a recipient for the template
|
||||||
const recipient = await prisma.recipient.create({
|
const recipient = await prisma.recipient.create({
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
envelopeId: template.id,
|
||||||
email: 'recipient@example.com',
|
email: 'recipient@example.com',
|
||||||
name: 'Test Recipient',
|
name: 'Test Recipient',
|
||||||
role: RecipientRole.SIGNER,
|
role: RecipientRole.SIGNER,
|
||||||
@ -548,7 +578,8 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
// 5. Add a field to the template
|
// 5. Add a field to the template
|
||||||
const field = await prisma.field.create({
|
const field = await prisma.field.create({
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
envelopeId: template.id,
|
||||||
|
envelopeItemId: firstEnvelopeItem.id,
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
type: FieldType.RADIO,
|
type: FieldType.RADIO,
|
||||||
page: 1,
|
page: 1,
|
||||||
@ -576,7 +607,7 @@ test.describe('Template Field Prefill API v2', () => {
|
|||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
templateId: template.id,
|
templateId: mapSecondaryIdToTemplateId(template.secondaryId),
|
||||||
recipients: [
|
recipients: [
|
||||||
{
|
{
|
||||||
id: recipient.id,
|
id: recipient.id,
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -19,7 +19,7 @@ test('[DOCUMENT_AUTH]: should grant access when not required', async ({ page })
|
|||||||
|
|
||||||
const recipients = await prisma.recipient.findMany({
|
const recipients = await prisma.recipient.findMany({
|
||||||
where: {
|
where: {
|
||||||
documentId: document.id,
|
envelopeId: document.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ test('[DOCUMENT_AUTH]: should allow or deny access when required', async ({ page
|
|||||||
|
|
||||||
const recipients = await prisma.recipient.findMany({
|
const recipients = await prisma.recipient.findMany({
|
||||||
where: {
|
where: {
|
||||||
documentId: document.id,
|
envelopeId: document.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -85,7 +85,7 @@ test('[NEXT_RECIPIENT_DICTATION]: should allow updating next recipient when dict
|
|||||||
await page.waitForURL(`${signUrl}/complete`);
|
await page.waitForURL(`${signUrl}/complete`);
|
||||||
|
|
||||||
// Verify document and recipient states
|
// Verify document and recipient states
|
||||||
const updatedDocument = await prisma.document.findUniqueOrThrow({
|
const updatedDocument = await prisma.envelope.findUniqueOrThrow({
|
||||||
where: { id: document.id },
|
where: { id: document.id },
|
||||||
include: {
|
include: {
|
||||||
recipients: {
|
recipients: {
|
||||||
@ -172,7 +172,7 @@ test('[NEXT_RECIPIENT_DICTATION]: should not show dictation UI when disabled', a
|
|||||||
|
|
||||||
// Verify document and recipient states
|
// Verify document and recipient states
|
||||||
|
|
||||||
const updatedDocument = await prisma.document.findUniqueOrThrow({
|
const updatedDocument = await prisma.envelope.findUniqueOrThrow({
|
||||||
where: { id: document.id },
|
where: { id: document.id },
|
||||||
include: {
|
include: {
|
||||||
recipients: {
|
recipients: {
|
||||||
@ -259,7 +259,7 @@ test('[NEXT_RECIPIENT_DICTATION]: should work with parallel signing flow', async
|
|||||||
|
|
||||||
// Verify final document and recipient states
|
// Verify final document and recipient states
|
||||||
await expect(async () => {
|
await expect(async () => {
|
||||||
const updatedDocument = await prisma.document.findUniqueOrThrow({
|
const updatedDocument = await prisma.envelope.findUniqueOrThrow({
|
||||||
where: { id: document.id },
|
where: { id: document.id },
|
||||||
include: {
|
include: {
|
||||||
recipients: {
|
recipients: {
|
||||||
@ -362,7 +362,7 @@ test('[NEXT_RECIPIENT_DICTATION]: should allow assistant to dictate next signer'
|
|||||||
|
|
||||||
// Verify document and recipient states
|
// Verify document and recipient states
|
||||||
await expect(async () => {
|
await expect(async () => {
|
||||||
const updatedDocument = await prisma.document.findUniqueOrThrow({
|
const updatedDocument = await prisma.envelope.findUniqueOrThrow({
|
||||||
where: { id: document.id },
|
where: { id: document.id },
|
||||||
include: {
|
include: {
|
||||||
recipients: {
|
recipients: {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { expect, test } from '@playwright/test';
|
import { expect, test } from '@playwright/test';
|
||||||
|
|
||||||
|
import { mapSecondaryIdToDocumentId } from '@documenso/lib/utils/envelope';
|
||||||
import {
|
import {
|
||||||
seedBlankDocument,
|
seedBlankDocument,
|
||||||
seedDraftDocument,
|
seedDraftDocument,
|
||||||
@ -16,7 +17,7 @@ test('[DOCUMENT_FLOW]: add settings', async ({ page }) => {
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
redirectPath: `/t/${team.url}/documents/${document.id}/edit`,
|
redirectPath: `/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set title.
|
// Set title.
|
||||||
@ -52,13 +53,15 @@ test('[DOCUMENT_FLOW]: title should be disabled depending on document status', a
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
redirectPath: `/t/${team.url}/documents/${pendingDocument.id}/edit`,
|
redirectPath: `/t/${team.url}/documents/${mapSecondaryIdToDocumentId(pendingDocument.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Should be disabled for pending documents.
|
// Should be disabled for pending documents.
|
||||||
await expect(page.getByLabel('Title')).toBeDisabled();
|
await expect(page.getByLabel('Title')).toBeDisabled();
|
||||||
|
|
||||||
// Should be enabled for draft documents.
|
// Should be enabled for draft documents.
|
||||||
await page.goto(`/t/${team.url}/documents/${draftDocument.id}/edit`);
|
await page.goto(
|
||||||
|
`/t/${team.url}/documents/${mapSecondaryIdToDocumentId(draftDocument.secondaryId)}/edit`,
|
||||||
|
);
|
||||||
await expect(page.getByLabel('Title')).toBeEnabled();
|
await expect(page.getByLabel('Title')).toBeEnabled();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { expect, test } from '@playwright/test';
|
import { expect, test } from '@playwright/test';
|
||||||
|
|
||||||
|
import { mapSecondaryIdToDocumentId } from '@documenso/lib/utils/envelope';
|
||||||
import { seedBlankDocument } from '@documenso/prisma/seed/documents';
|
import { seedBlankDocument } from '@documenso/prisma/seed/documents';
|
||||||
import { seedUser } from '@documenso/prisma/seed/users';
|
import { seedUser } from '@documenso/prisma/seed/users';
|
||||||
|
|
||||||
@ -12,7 +13,7 @@ test('[DOCUMENT_FLOW]: add signers', async ({ page }) => {
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
redirectPath: `/t/${team.url}/documents/${document.id}/edit`,
|
redirectPath: `/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Save the settings by going to the next step.
|
// Save the settings by going to the next step.
|
||||||
|
|||||||
@ -9,7 +9,10 @@ import {
|
|||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
|
|
||||||
import { getRecipientByEmail } from '@documenso/lib/server-only/recipient/get-recipient-by-email';
|
import {
|
||||||
|
mapDocumentIdToSecondaryId,
|
||||||
|
mapSecondaryIdToDocumentId,
|
||||||
|
} from '@documenso/lib/utils/envelope';
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import {
|
import {
|
||||||
seedBlankDocument,
|
seedBlankDocument,
|
||||||
@ -23,7 +26,7 @@ import { signSignaturePad } from '../fixtures/signature';
|
|||||||
// Can't use the function in server-only/document due to it indirectly using
|
// Can't use the function in server-only/document due to it indirectly using
|
||||||
// require imports.
|
// require imports.
|
||||||
const getDocumentByToken = async (token: string) => {
|
const getDocumentByToken = async (token: string) => {
|
||||||
return await prisma.document.findFirstOrThrow({
|
return await prisma.envelope.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
recipients: {
|
recipients: {
|
||||||
some: {
|
some: {
|
||||||
@ -69,7 +72,7 @@ test('[DOCUMENT_FLOW]: should be able to create a document', async ({ page }) =>
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
redirectPath: `/t/${team.url}/documents/${document.id}/edit`,
|
redirectPath: `/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
const documentTitle = `example-${Date.now()}.pdf`;
|
const documentTitle = `example-${Date.now()}.pdf`;
|
||||||
@ -130,7 +133,7 @@ test('[DOCUMENT_FLOW]: should be able to create a document with multiple recipie
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
redirectPath: `/t/${team.url}/documents/${document.id}/edit`,
|
redirectPath: `/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
const documentTitle = `example-${Date.now()}.pdf`;
|
const documentTitle = `example-${Date.now()}.pdf`;
|
||||||
@ -215,7 +218,7 @@ test('[DOCUMENT_FLOW]: should be able to create a document with multiple recipie
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
redirectPath: `/t/${team.url}/documents/${document.id}/edit`,
|
redirectPath: `/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set title
|
// Set title
|
||||||
@ -313,7 +316,7 @@ test('[DOCUMENT_FLOW]: should not be able to create a document without signature
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
redirectPath: `/t/${team.url}/documents/${document.id}/edit`,
|
redirectPath: `/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
const documentTitle = `example-${Date.now()}.pdf`;
|
const documentTitle = `example-${Date.now()}.pdf`;
|
||||||
@ -401,7 +404,7 @@ test('[DOCUMENT_FLOW]: should be able to create, send with redirect url, sign a
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
redirectPath: `/t/${team.url}/documents/${document.id}/edit`,
|
redirectPath: `/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
const documentTitle = `example-${Date.now()}.pdf`;
|
const documentTitle = `example-${Date.now()}.pdf`;
|
||||||
@ -442,9 +445,13 @@ test('[DOCUMENT_FLOW]: should be able to create, send with redirect url, sign a
|
|||||||
const url = page.url().split('/');
|
const url = page.url().split('/');
|
||||||
const documentId = url[url.length - 1];
|
const documentId = url[url.length - 1];
|
||||||
|
|
||||||
const { token } = await getRecipientByEmail({
|
const { token } = await prisma.recipient.findFirstOrThrow({
|
||||||
email: 'user1@example.com',
|
where: {
|
||||||
documentId: Number(documentId),
|
envelope: {
|
||||||
|
secondaryId: mapDocumentIdToSecondaryId(Number(documentId)),
|
||||||
|
},
|
||||||
|
email: 'user1@example.com',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await page.goto(`/sign/${token}`);
|
await page.goto(`/sign/${token}`);
|
||||||
@ -500,7 +507,7 @@ test('[DOCUMENT_FLOW]: should be able to sign a document with custom date', asyn
|
|||||||
recipient: {
|
recipient: {
|
||||||
email: 'user1@example.com',
|
email: 'user1@example.com',
|
||||||
},
|
},
|
||||||
documentId: Number(document.id),
|
envelopeId: document.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -525,7 +532,7 @@ test('[DOCUMENT_FLOW]: should be able to create and sign a document with 3 recip
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
redirectPath: `/t/${team.url}/documents/${document.id}/edit`,
|
redirectPath: `/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
const documentTitle = `Sequential-Signing-${Date.now()}.pdf`;
|
const documentTitle = `Sequential-Signing-${Date.now()}.pdf`;
|
||||||
@ -587,7 +594,7 @@ test('[DOCUMENT_FLOW]: should be able to create and sign a document with 3 recip
|
|||||||
|
|
||||||
await expect(page.getByRole('link', { name: documentTitle })).toBeVisible();
|
await expect(page.getByRole('link', { name: documentTitle })).toBeVisible();
|
||||||
|
|
||||||
const createdDocument = await prisma.document.findFirst({
|
const createdDocument = await prisma.envelope.findFirst({
|
||||||
where: { title: documentTitle },
|
where: { title: documentTitle },
|
||||||
include: { recipients: true },
|
include: { recipients: true },
|
||||||
});
|
});
|
||||||
@ -602,13 +609,13 @@ test('[DOCUMENT_FLOW]: should be able to create and sign a document with 3 recip
|
|||||||
expect(recipient).not.toBeNull();
|
expect(recipient).not.toBeNull();
|
||||||
|
|
||||||
const fields = await prisma.field.findMany({
|
const fields = await prisma.field.findMany({
|
||||||
where: { recipientId: recipient?.id, documentId: createdDocument?.id },
|
where: { recipientId: recipient?.id, envelopeId: createdDocument?.id },
|
||||||
});
|
});
|
||||||
const recipientField = fields[0];
|
const recipientField = fields[0];
|
||||||
|
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
const previousRecipient = await prisma.recipient.findFirst({
|
const previousRecipient = await prisma.recipient.findFirst({
|
||||||
where: { email: `user${i}@example.com`, documentId: createdDocument?.id },
|
where: { email: `user${i}@example.com`, envelopeId: createdDocument?.id },
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(previousRecipient?.signingStatus).toBe(SigningStatus.SIGNED);
|
expect(previousRecipient?.signingStatus).toBe(SigningStatus.SIGNED);
|
||||||
@ -636,7 +643,7 @@ test('[DOCUMENT_FLOW]: should be able to create and sign a document with 3 recip
|
|||||||
// Wait for the document to be signed.
|
// Wait for the document to be signed.
|
||||||
await page.waitForTimeout(10000);
|
await page.waitForTimeout(10000);
|
||||||
|
|
||||||
const finalDocument = await prisma.document.findFirst({
|
const finalDocument = await prisma.envelope.findFirst({
|
||||||
where: { id: createdDocument?.id },
|
where: { id: createdDocument?.id },
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -648,18 +655,20 @@ test('[DOCUMENT_FLOW]: should prevent out-of-order signing in sequential mode',
|
|||||||
}) => {
|
}) => {
|
||||||
const { user, team } = await seedUser();
|
const { user, team } = await seedUser();
|
||||||
|
|
||||||
const { recipients } = await seedPendingDocumentWithFullFields({
|
const { document, recipients } = await seedPendingDocumentWithFullFields({
|
||||||
teamId: team.id,
|
teamId: team.id,
|
||||||
owner: user,
|
owner: user,
|
||||||
recipients: ['user1@example.com', 'user2@example.com', 'user3@example.com'],
|
recipients: ['user1@example.com', 'user2@example.com', 'user3@example.com'],
|
||||||
fields: [FieldType.SIGNATURE],
|
fields: [FieldType.SIGNATURE],
|
||||||
recipientsCreateOptions: [{ signingOrder: 1 }, { signingOrder: 2 }, { signingOrder: 3 }],
|
recipientsCreateOptions: [{ signingOrder: 1 }, { signingOrder: 2 }, { signingOrder: 3 }],
|
||||||
updateDocumentOptions: {
|
});
|
||||||
documentMeta: {
|
|
||||||
create: {
|
await prisma.documentMeta.update({
|
||||||
signingOrder: DocumentSigningOrder.SEQUENTIAL,
|
where: {
|
||||||
},
|
id: document.documentMetaId,
|
||||||
},
|
},
|
||||||
|
data: {
|
||||||
|
signingOrder: DocumentSigningOrder.SEQUENTIAL,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { expect, test } from '@playwright/test';
|
import { expect, test } from '@playwright/test';
|
||||||
|
|
||||||
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
||||||
|
import { mapSecondaryIdToDocumentId } from '@documenso/lib/utils/envelope';
|
||||||
import {
|
import {
|
||||||
seedBlankDocument,
|
seedBlankDocument,
|
||||||
seedCompletedDocument,
|
seedCompletedDocument,
|
||||||
@ -27,7 +28,9 @@ test.describe('Unauthorized Access to Documents', () => {
|
|||||||
redirectPath: `/t/${team.url}/documents`,
|
redirectPath: `/t/${team.url}/documents`,
|
||||||
});
|
});
|
||||||
|
|
||||||
await page.goto(`${NEXT_PUBLIC_WEBAPP_URL()}/t/${team.url}/documents/${document.id}`);
|
await page.goto(
|
||||||
|
`${NEXT_PUBLIC_WEBAPP_URL()}/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}`,
|
||||||
|
);
|
||||||
await expect(page.getByRole('heading', { name: 'Oops! Something went wrong.' })).toBeVisible();
|
await expect(page.getByRole('heading', { name: 'Oops! Something went wrong.' })).toBeVisible();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -40,10 +43,12 @@ test.describe('Unauthorized Access to Documents', () => {
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: unauthorizedUser.email,
|
email: unauthorizedUser.email,
|
||||||
redirectPath: `/t/${team.url}/documents/${document.id}/edit`,
|
redirectPath: `/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
await page.goto(`${NEXT_PUBLIC_WEBAPP_URL()}/t/${team.url}/documents/${document.id}/edit`);
|
await page.goto(
|
||||||
|
`${NEXT_PUBLIC_WEBAPP_URL()}/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/edit`,
|
||||||
|
);
|
||||||
await expect(page.getByRole('heading', { name: 'Oops! Something went wrong.' })).toBeVisible();
|
await expect(page.getByRole('heading', { name: 'Oops! Something went wrong.' })).toBeVisible();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -57,10 +62,12 @@ test.describe('Unauthorized Access to Documents', () => {
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: unauthorizedUser.email,
|
email: unauthorizedUser.email,
|
||||||
redirectPath: `/t/${team.url}/documents/${document.id}`,
|
redirectPath: `/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
await page.goto(`${NEXT_PUBLIC_WEBAPP_URL()}/t/${team.url}/documents/${document.id}`);
|
await page.goto(
|
||||||
|
`${NEXT_PUBLIC_WEBAPP_URL()}/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}`,
|
||||||
|
);
|
||||||
await expect(page.getByRole('heading', { name: 'Oops! Something went wrong.' })).toBeVisible();
|
await expect(page.getByRole('heading', { name: 'Oops! Something went wrong.' })).toBeVisible();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -74,10 +81,12 @@ test.describe('Unauthorized Access to Documents', () => {
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: unauthorizedUser.email,
|
email: unauthorizedUser.email,
|
||||||
redirectPath: `/t/${team.url}/documents/${document.id}/edit`,
|
redirectPath: `/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
await page.goto(`${NEXT_PUBLIC_WEBAPP_URL()}/t/${team.url}/documents/${document.id}/edit`);
|
await page.goto(
|
||||||
|
`${NEXT_PUBLIC_WEBAPP_URL()}/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/edit`,
|
||||||
|
);
|
||||||
await expect(page.getByRole('heading', { name: 'Oops! Something went wrong.' })).toBeVisible();
|
await expect(page.getByRole('heading', { name: 'Oops! Something went wrong.' })).toBeVisible();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -91,10 +100,12 @@ test.describe('Unauthorized Access to Documents', () => {
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: unauthorizedUser.email,
|
email: unauthorizedUser.email,
|
||||||
redirectPath: `/t/${team.url}/documents/${document.id}`,
|
redirectPath: `/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
await page.goto(`${NEXT_PUBLIC_WEBAPP_URL()}/t/${team.url}/documents/${document.id}`);
|
await page.goto(
|
||||||
|
`${NEXT_PUBLIC_WEBAPP_URL()}/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}`,
|
||||||
|
);
|
||||||
await expect(page.getByRole('heading', { name: 'Oops! Something went wrong.' })).toBeVisible();
|
await expect(page.getByRole('heading', { name: 'Oops! Something went wrong.' })).toBeVisible();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -28,7 +28,9 @@ test.describe('Signing Certificate Tests', () => {
|
|||||||
const documentData = await prisma.documentData
|
const documentData = await prisma.documentData
|
||||||
.findFirstOrThrow({
|
.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
id: document.documentDataId,
|
envelopeItem: {
|
||||||
|
envelopeId: document.id,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(async (data) => getFile(data));
|
.then(async (data) => getFile(data));
|
||||||
@ -65,12 +67,21 @@ test.describe('Signing Certificate Tests', () => {
|
|||||||
await page.waitForTimeout(2500);
|
await page.waitForTimeout(2500);
|
||||||
|
|
||||||
// Get the completed document
|
// Get the completed document
|
||||||
const completedDocument = await prisma.document.findFirstOrThrow({
|
const completedDocument = await prisma.envelope.findFirstOrThrow({
|
||||||
where: { id: document.id },
|
where: { id: document.id },
|
||||||
include: { documentData: true },
|
include: {
|
||||||
|
envelopeItems: {
|
||||||
|
include: {
|
||||||
|
documentData: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const completedDocumentData = await getFile(completedDocument.documentData);
|
// Todo: Envelopes
|
||||||
|
const firstDocumentData = completedDocument.envelopeItems[0].documentData;
|
||||||
|
|
||||||
|
const completedDocumentData = await getFile(firstDocumentData);
|
||||||
|
|
||||||
// Load the PDF and check number of pages
|
// Load the PDF and check number of pages
|
||||||
const pdfDoc = await PDFDocument.load(completedDocumentData);
|
const pdfDoc = await PDFDocument.load(completedDocumentData);
|
||||||
@ -110,7 +121,9 @@ test.describe('Signing Certificate Tests', () => {
|
|||||||
const documentData = await prisma.documentData
|
const documentData = await prisma.documentData
|
||||||
.findFirstOrThrow({
|
.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
id: document.documentDataId,
|
envelopeItem: {
|
||||||
|
envelopeId: document.id,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(async (data) => getFile(data));
|
.then(async (data) => getFile(data));
|
||||||
@ -145,12 +158,21 @@ test.describe('Signing Certificate Tests', () => {
|
|||||||
await page.waitForTimeout(2500);
|
await page.waitForTimeout(2500);
|
||||||
|
|
||||||
// Get the completed document
|
// Get the completed document
|
||||||
const completedDocument = await prisma.document.findFirstOrThrow({
|
const completedDocument = await prisma.envelope.findFirstOrThrow({
|
||||||
where: { id: document.id },
|
where: { id: document.id },
|
||||||
include: { documentData: true },
|
include: {
|
||||||
|
envelopeItems: {
|
||||||
|
include: {
|
||||||
|
documentData: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const completedDocumentData = await getFile(completedDocument.documentData);
|
// Todo: Envelopes
|
||||||
|
const firstDocumentData = completedDocument.envelopeItems[0].documentData;
|
||||||
|
|
||||||
|
const completedDocumentData = await getFile(firstDocumentData);
|
||||||
|
|
||||||
// Load the PDF and check number of pages
|
// Load the PDF and check number of pages
|
||||||
const completedPdf = await PDFDocument.load(completedDocumentData);
|
const completedPdf = await PDFDocument.load(completedDocumentData);
|
||||||
@ -190,7 +212,9 @@ test.describe('Signing Certificate Tests', () => {
|
|||||||
const documentData = await prisma.documentData
|
const documentData = await prisma.documentData
|
||||||
.findFirstOrThrow({
|
.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
id: document.documentDataId,
|
envelopeItem: {
|
||||||
|
envelopeId: document.id,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(async (data) => getFile(data));
|
.then(async (data) => getFile(data));
|
||||||
@ -225,12 +249,18 @@ test.describe('Signing Certificate Tests', () => {
|
|||||||
await page.waitForTimeout(2500);
|
await page.waitForTimeout(2500);
|
||||||
|
|
||||||
// Get the completed document
|
// Get the completed document
|
||||||
const completedDocument = await prisma.document.findFirstOrThrow({
|
const completedDocument = await prisma.envelope.findFirstOrThrow({
|
||||||
where: { id: document.id },
|
where: { id: document.id },
|
||||||
include: { documentData: true },
|
include: {
|
||||||
|
envelopeItems: {
|
||||||
|
include: {
|
||||||
|
documentData: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const completedDocumentData = await getFile(completedDocument.documentData);
|
const completedDocumentData = await getFile(completedDocument.envelopeItems[0].documentData);
|
||||||
|
|
||||||
// Load the PDF and check number of pages
|
// Load the PDF and check number of pages
|
||||||
const completedPdf = await PDFDocument.load(completedDocumentData);
|
const completedPdf = await PDFDocument.load(completedDocumentData);
|
||||||
|
|||||||
@ -383,12 +383,10 @@ test('[TEAMS]: can create a template inside a template folder', async ({ page })
|
|||||||
|
|
||||||
await page.waitForTimeout(3000);
|
await page.waitForTimeout(3000);
|
||||||
|
|
||||||
await page.getByRole('button', { name: 'Create' }).click();
|
// Expect redirect.
|
||||||
|
|
||||||
await page.waitForTimeout(1000);
|
|
||||||
|
|
||||||
await expect(page.getByText('documenso-supporter-pledge.pdf')).toBeVisible();
|
await expect(page.getByText('documenso-supporter-pledge.pdf')).toBeVisible();
|
||||||
|
|
||||||
|
// Return to folder and verify file is visible.
|
||||||
await page.goto(`/t/${team.url}/templates/f/${folder.id}`);
|
await page.goto(`/t/${team.url}/templates/f/${folder.id}`);
|
||||||
await expect(page.getByText('documenso-supporter-pledge.pdf')).toBeVisible();
|
await expect(page.getByText('documenso-supporter-pledge.pdf')).toBeVisible();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -96,7 +96,7 @@ test('[ORGANISATIONS]: manage document preferences', async ({ page }) => {
|
|||||||
|
|
||||||
const documentMeta = await prisma.documentMeta.findFirstOrThrow({
|
const documentMeta = await prisma.documentMeta.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
documentId: document.id,
|
id: document.documentMetaId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -272,7 +272,7 @@ test('[ORGANISATIONS]: manage email preferences', async ({ page }) => {
|
|||||||
|
|
||||||
const teamOverrideDocumentMeta = await prisma.documentMeta.findFirstOrThrow({
|
const teamOverrideDocumentMeta = await prisma.documentMeta.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
documentId: teamOverrideDocument.id,
|
id: teamOverrideDocument.documentMetaId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -317,7 +317,7 @@ test('[ORGANISATIONS]: manage email preferences', async ({ page }) => {
|
|||||||
|
|
||||||
const documentMeta = await prisma.documentMeta.findFirstOrThrow({
|
const documentMeta = await prisma.documentMeta.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
documentId: document.id,
|
id: document.documentMetaId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { expect, test } from '@playwright/test';
|
import { expect, test } from '@playwright/test';
|
||||||
import { DocumentStatus, DocumentVisibility, TeamMemberRole } from '@prisma/client';
|
import { DocumentStatus, DocumentVisibility, TeamMemberRole } from '@prisma/client';
|
||||||
|
|
||||||
|
import { mapSecondaryIdToDocumentId } from '@documenso/lib/utils/envelope';
|
||||||
import {
|
import {
|
||||||
seedBlankDocument,
|
seedBlankDocument,
|
||||||
seedDocuments,
|
seedDocuments,
|
||||||
@ -750,7 +751,7 @@ test('[TEAMS]: check that ADMIN role can change document visibility', async ({ p
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: adminUser.email,
|
email: adminUser.email,
|
||||||
redirectPath: `/t/${team.url}/documents/${document.id}/edit`,
|
redirectPath: `/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
await page.getByTestId('documentVisibilitySelectValue').click();
|
await page.getByTestId('documentVisibilitySelectValue').click();
|
||||||
@ -784,7 +785,7 @@ test('[TEAMS]: check that MEMBER role cannot change visibility of EVERYONE docum
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: teamMember.email,
|
email: teamMember.email,
|
||||||
redirectPath: `/t/${team.url}/documents/${document.id}/edit`,
|
redirectPath: `/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
await expect(page.getByTestId('documentVisibilitySelectValue')).toHaveText('Everyone');
|
await expect(page.getByTestId('documentVisibilitySelectValue')).toHaveText('Everyone');
|
||||||
@ -810,7 +811,7 @@ test('[TEAMS]: check that MEMBER role cannot change visibility of MANAGER_AND_AB
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: teamMember.email,
|
email: teamMember.email,
|
||||||
redirectPath: `/t/${team.url}/documents/${document.id}/edit`,
|
redirectPath: `/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
await expect(page.getByTestId('documentVisibilitySelectValue')).toHaveText('Managers and above');
|
await expect(page.getByTestId('documentVisibilitySelectValue')).toHaveText('Managers and above');
|
||||||
@ -836,7 +837,7 @@ test('[TEAMS]: check that MEMBER role cannot change visibility of ADMIN document
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: teamMember.email,
|
email: teamMember.email,
|
||||||
redirectPath: `/t/${team.url}/documents/${document.id}/edit`,
|
redirectPath: `/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
await expect(page.getByTestId('documentVisibilitySelectValue')).toHaveText('Admins only');
|
await expect(page.getByTestId('documentVisibilitySelectValue')).toHaveText('Admins only');
|
||||||
@ -862,7 +863,7 @@ test('[TEAMS]: check that MANAGER role cannot change visibility of ADMIN documen
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: teamManager.email,
|
email: teamManager.email,
|
||||||
redirectPath: `/t/${team.url}/documents/${document.id}/edit`,
|
redirectPath: `/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
await expect(page.getByTestId('documentVisibilitySelectValue')).toHaveText('Admins only');
|
await expect(page.getByTestId('documentVisibilitySelectValue')).toHaveText('Admins only');
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
import { expect, test } from '@playwright/test';
|
import { expect, test } from '@playwright/test';
|
||||||
|
|
||||||
|
import {
|
||||||
|
mapSecondaryIdToDocumentId,
|
||||||
|
mapSecondaryIdToTemplateId,
|
||||||
|
} from '@documenso/lib/utils/envelope';
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import {
|
import {
|
||||||
seedTeamDocumentWithMeta,
|
seedTeamDocumentWithMeta,
|
||||||
@ -21,7 +25,9 @@ test('[TEAMS]: check that default team signature settings are all enabled', asyn
|
|||||||
const document = await seedTeamDocumentWithMeta(team);
|
const document = await seedTeamDocumentWithMeta(team);
|
||||||
|
|
||||||
// Create a document and check the settings
|
// Create a document and check the settings
|
||||||
await page.goto(`/t/${team.url}/documents/${document.id}/edit`);
|
await page.goto(
|
||||||
|
`/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/edit`,
|
||||||
|
);
|
||||||
|
|
||||||
// Verify that the settings match
|
// Verify that the settings match
|
||||||
await page.getByRole('button', { name: 'Advanced Options' }).click();
|
await page.getByRole('button', { name: 'Advanced Options' }).click();
|
||||||
@ -154,7 +160,7 @@ test('[TEAMS]: check signature modes work for templates', async ({ page }) => {
|
|||||||
|
|
||||||
const template = await seedTeamTemplateWithMeta(team);
|
const template = await seedTeamTemplateWithMeta(team);
|
||||||
|
|
||||||
await page.goto(`/t/${team.url}/templates/${template.id}`);
|
await page.goto(`/t/${team.url}/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}`);
|
||||||
await page.getByRole('button', { name: 'Use' }).click();
|
await page.getByRole('button', { name: 'Use' }).click();
|
||||||
|
|
||||||
// Check the send document checkbox to true
|
// Check the send document checkbox to true
|
||||||
@ -162,9 +168,10 @@ test('[TEAMS]: check signature modes work for templates', async ({ page }) => {
|
|||||||
await page.getByRole('button', { name: 'Create and send' }).click();
|
await page.getByRole('button', { name: 'Create and send' }).click();
|
||||||
await page.waitForTimeout(1000);
|
await page.waitForTimeout(1000);
|
||||||
|
|
||||||
const document = await prisma.document.findFirst({
|
const document = await prisma.envelope.findFirst({
|
||||||
where: {
|
where: {
|
||||||
templateId: template.id,
|
// Created from template
|
||||||
|
templateId: mapSecondaryIdToTemplateId(template.secondaryId),
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
documentMeta: true,
|
documentMeta: true,
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { expect, test } from '@playwright/test';
|
import { expect, test } from '@playwright/test';
|
||||||
import { TeamMemberRole } from '@prisma/client';
|
import { TeamMemberRole } from '@prisma/client';
|
||||||
|
|
||||||
|
import { mapSecondaryIdToTemplateId } from '@documenso/lib/utils/envelope';
|
||||||
import { seedTeam, seedTeamMember } from '@documenso/prisma/seed/teams';
|
import { seedTeam, seedTeamMember } from '@documenso/prisma/seed/teams';
|
||||||
import { seedBlankTemplate } from '@documenso/prisma/seed/templates';
|
import { seedBlankTemplate } from '@documenso/prisma/seed/templates';
|
||||||
import { seedUser } from '@documenso/prisma/seed/users';
|
import { seedUser } from '@documenso/prisma/seed/users';
|
||||||
@ -14,7 +15,7 @@ test('[TEMPLATE_FLOW]: add settings', async ({ page }) => {
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
redirectPath: `/t/${team.url}/templates/${template.id}/edit`,
|
redirectPath: `/t/${team.url}/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set title.
|
// Set title.
|
||||||
@ -48,7 +49,7 @@ test('[TEMPLATE_FLOW] add document visibility settings', async ({ page }) => {
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
redirectPath: `/t/${team.url}/templates/${template.id}/edit`,
|
redirectPath: `/t/${team.url}/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set document visibility.
|
// Set document visibility.
|
||||||
@ -63,7 +64,9 @@ test('[TEMPLATE_FLOW] add document visibility settings', async ({ page }) => {
|
|||||||
await expect(page.getByRole('heading', { name: 'Add Placeholders' })).toBeVisible();
|
await expect(page.getByRole('heading', { name: 'Add Placeholders' })).toBeVisible();
|
||||||
|
|
||||||
// Navigate back to the edit page to check that the settings are saved correctly.
|
// Navigate back to the edit page to check that the settings are saved correctly.
|
||||||
await page.goto(`/t/${team.url}/templates/${template.id}/edit`);
|
await page.goto(
|
||||||
|
`/t/${team.url}/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}/edit`,
|
||||||
|
);
|
||||||
|
|
||||||
await expect(page.getByRole('heading', { name: 'General' })).toBeVisible();
|
await expect(page.getByRole('heading', { name: 'General' })).toBeVisible();
|
||||||
await expect(page.getByTestId('documentVisibilitySelectValue')).toContainText(
|
await expect(page.getByTestId('documentVisibilitySelectValue')).toContainText(
|
||||||
@ -96,7 +99,7 @@ test('[TEMPLATE_FLOW] team member visibility permissions', async ({ page }) => {
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: managerUser.email,
|
email: managerUser.email,
|
||||||
redirectPath: `/t/${team.url}/templates/${template.id}/edit`,
|
redirectPath: `/t/${team.url}/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Manager should be able to set visibility to managers and above
|
// Manager should be able to set visibility to managers and above
|
||||||
@ -115,11 +118,12 @@ test('[TEMPLATE_FLOW] team member visibility permissions', async ({ page }) => {
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: memberUser.email,
|
email: memberUser.email,
|
||||||
redirectPath: `/t/${team.url}/templates/${template.id}/edit`,
|
redirectPath: `/t/${team.url}/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Regular member should not be able to modify visibility when set to managers and above
|
// A regular member should not be able to see the template.
|
||||||
await expect(page.getByTestId('documentVisibilitySelectValue')).toBeDisabled();
|
// They should be redirected to the templates page.
|
||||||
|
expect(new URL(page.url()).pathname).toBe(`/t/${team.url}/templates`);
|
||||||
|
|
||||||
// Create a new template with 'everyone' visibility
|
// Create a new template with 'everyone' visibility
|
||||||
const everyoneTemplate = await seedBlankTemplate(owner, team.id, {
|
const everyoneTemplate = await seedBlankTemplate(owner, team.id, {
|
||||||
@ -130,7 +134,9 @@ test('[TEMPLATE_FLOW] team member visibility permissions', async ({ page }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Navigate to the new template
|
// Navigate to the new template
|
||||||
await page.goto(`/t/${team.url}/templates/${everyoneTemplate.id}/edit`);
|
await page.goto(
|
||||||
|
`/t/${team.url}/templates/${mapSecondaryIdToTemplateId(everyoneTemplate.secondaryId)}/edit`,
|
||||||
|
);
|
||||||
|
|
||||||
// Regular member should be able to see but not modify visibility
|
// Regular member should be able to see but not modify visibility
|
||||||
await expect(page.getByTestId('documentVisibilitySelectValue')).toBeDisabled();
|
await expect(page.getByTestId('documentVisibilitySelectValue')).toBeDisabled();
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { expect, test } from '@playwright/test';
|
import { expect, test } from '@playwright/test';
|
||||||
|
|
||||||
|
import { mapSecondaryIdToTemplateId } from '@documenso/lib/utils/envelope';
|
||||||
import { seedBlankTemplate } from '@documenso/prisma/seed/templates';
|
import { seedBlankTemplate } from '@documenso/prisma/seed/templates';
|
||||||
import { seedUser } from '@documenso/prisma/seed/users';
|
import { seedUser } from '@documenso/prisma/seed/users';
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ import { apiSignin } from '../fixtures/authentication';
|
|||||||
// await apiSignin({
|
// await apiSignin({
|
||||||
// page,
|
// page,
|
||||||
// email: user.email,
|
// email: user.email,
|
||||||
// redirectPath: `/templates/${template.id}/edit`,
|
// redirectPath: `/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}/edit`,
|
||||||
// });
|
// });
|
||||||
|
|
||||||
// // Save the settings by going to the next step.
|
// // Save the settings by going to the next step.
|
||||||
@ -79,7 +80,7 @@ test('[TEMPLATE_FLOW]: add placeholder', async ({ page }) => {
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
redirectPath: `/t/${team.url}/templates/${template.id}/edit`,
|
redirectPath: `/t/${team.url}/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Save the settings by going to the next step.
|
// Save the settings by going to the next step.
|
||||||
|
|||||||
@ -4,6 +4,10 @@ import fs from 'fs';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
import { extractDocumentAuthMethods } from '@documenso/lib/utils/document-auth';
|
import { extractDocumentAuthMethods } from '@documenso/lib/utils/document-auth';
|
||||||
|
import {
|
||||||
|
mapDocumentIdToSecondaryId,
|
||||||
|
mapSecondaryIdToTemplateId,
|
||||||
|
} from '@documenso/lib/utils/envelope';
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import { seedTeam, seedTeamMember } from '@documenso/prisma/seed/teams';
|
import { seedTeam, seedTeamMember } from '@documenso/prisma/seed/teams';
|
||||||
import { seedBlankTemplate } from '@documenso/prisma/seed/templates';
|
import { seedBlankTemplate } from '@documenso/prisma/seed/templates';
|
||||||
@ -29,7 +33,7 @@ test('[TEMPLATE]: should create a document from a template', async ({ page }) =>
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
redirectPath: `/t/${team.url}/templates/${template.id}/edit`,
|
redirectPath: `/t/${team.url}/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set template title.
|
// Set template title.
|
||||||
@ -79,9 +83,9 @@ test('[TEMPLATE]: should create a document from a template', async ({ page }) =>
|
|||||||
|
|
||||||
const documentId = Number(page.url().split('/').pop());
|
const documentId = Number(page.url().split('/').pop());
|
||||||
|
|
||||||
const document = await prisma.document.findFirstOrThrow({
|
const document = await prisma.envelope.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
id: documentId,
|
secondaryId: mapDocumentIdToSecondaryId(documentId),
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
recipients: true,
|
recipients: true,
|
||||||
@ -132,7 +136,7 @@ test('[TEMPLATE]: should create a team document from a team template', async ({
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: owner.email,
|
email: owner.email,
|
||||||
redirectPath: `/t/${team.url}/templates/${template.id}/edit`,
|
redirectPath: `/t/${team.url}/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set template title.
|
// Set template title.
|
||||||
@ -182,9 +186,9 @@ test('[TEMPLATE]: should create a team document from a team template', async ({
|
|||||||
|
|
||||||
const documentId = Number(page.url().split('/').pop());
|
const documentId = Number(page.url().split('/').pop());
|
||||||
|
|
||||||
const document = await prisma.document.findFirstOrThrow({
|
const document = await prisma.envelope.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
id: documentId,
|
secondaryId: mapDocumentIdToSecondaryId(documentId),
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
recipients: true,
|
recipients: true,
|
||||||
@ -240,7 +244,7 @@ test('[TEMPLATE]: should create a document from a template with custom document'
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
redirectPath: `/t/${team.url}/templates/${template.id}/edit`,
|
redirectPath: `/t/${team.url}/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set template title
|
// Set template title
|
||||||
@ -288,30 +292,36 @@ test('[TEMPLATE]: should create a document from a template with custom document'
|
|||||||
|
|
||||||
const documentId = Number(page.url().split('/').pop());
|
const documentId = Number(page.url().split('/').pop());
|
||||||
|
|
||||||
const document = await prisma.document.findFirstOrThrow({
|
const document = await prisma.envelope.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
id: documentId,
|
secondaryId: mapDocumentIdToSecondaryId(documentId),
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
documentData: true,
|
envelopeItems: {
|
||||||
|
include: {
|
||||||
|
documentData: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const firstDocumentData = document.envelopeItems[0].documentData;
|
||||||
|
|
||||||
const expectedDocumentDataType =
|
const expectedDocumentDataType =
|
||||||
process.env.NEXT_PUBLIC_UPLOAD_TRANSPORT === 's3'
|
process.env.NEXT_PUBLIC_UPLOAD_TRANSPORT === 's3'
|
||||||
? DocumentDataType.S3_PATH
|
? DocumentDataType.S3_PATH
|
||||||
: DocumentDataType.BYTES_64;
|
: DocumentDataType.BYTES_64;
|
||||||
|
|
||||||
expect(document.title).toEqual('TEMPLATE_WITH_CUSTOM_DOC');
|
expect(document.title).toEqual('TEMPLATE_WITH_CUSTOM_DOC');
|
||||||
expect(document.documentData.type).toEqual(expectedDocumentDataType);
|
expect(firstDocumentData.type).toEqual(expectedDocumentDataType);
|
||||||
|
|
||||||
if (expectedDocumentDataType === DocumentDataType.BYTES_64) {
|
if (expectedDocumentDataType === DocumentDataType.BYTES_64) {
|
||||||
expect(document.documentData.data).toEqual(pdfContent);
|
expect(firstDocumentData.data).toEqual(pdfContent);
|
||||||
expect(document.documentData.initialData).toEqual(pdfContent);
|
expect(firstDocumentData.initialData).toEqual(pdfContent);
|
||||||
} else {
|
} else {
|
||||||
// For S3, we expect the data/initialData to be the S3 path (non-empty string)
|
// For S3, we expect the data/initialData to be the S3 path (non-empty string)
|
||||||
expect(document.documentData.data).toBeTruthy();
|
expect(firstDocumentData.data).toBeTruthy();
|
||||||
expect(document.documentData.initialData).toBeTruthy();
|
expect(firstDocumentData.initialData).toBeTruthy();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -333,7 +343,7 @@ test('[TEMPLATE]: should create a team document from a template with custom docu
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: owner.email,
|
email: owner.email,
|
||||||
redirectPath: `/t/${team.url}/templates/${template.id}/edit`,
|
redirectPath: `/t/${team.url}/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set template title
|
// Set template title
|
||||||
@ -381,12 +391,16 @@ test('[TEMPLATE]: should create a team document from a template with custom docu
|
|||||||
|
|
||||||
const documentId = Number(page.url().split('/').pop());
|
const documentId = Number(page.url().split('/').pop());
|
||||||
|
|
||||||
const document = await prisma.document.findFirstOrThrow({
|
const document = await prisma.envelope.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
id: documentId,
|
secondaryId: mapDocumentIdToSecondaryId(documentId),
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
documentData: true,
|
envelopeItems: {
|
||||||
|
include: {
|
||||||
|
documentData: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -395,17 +409,19 @@ test('[TEMPLATE]: should create a team document from a template with custom docu
|
|||||||
? DocumentDataType.S3_PATH
|
? DocumentDataType.S3_PATH
|
||||||
: DocumentDataType.BYTES_64;
|
: DocumentDataType.BYTES_64;
|
||||||
|
|
||||||
|
const firstDocumentData = document.envelopeItems[0].documentData;
|
||||||
|
|
||||||
expect(document.teamId).toEqual(team.id);
|
expect(document.teamId).toEqual(team.id);
|
||||||
expect(document.title).toEqual('TEAM_TEMPLATE_WITH_CUSTOM_DOC');
|
expect(document.title).toEqual('TEAM_TEMPLATE_WITH_CUSTOM_DOC');
|
||||||
expect(document.documentData.type).toEqual(expectedDocumentDataType);
|
expect(firstDocumentData.type).toEqual(expectedDocumentDataType);
|
||||||
|
|
||||||
if (expectedDocumentDataType === DocumentDataType.BYTES_64) {
|
if (expectedDocumentDataType === DocumentDataType.BYTES_64) {
|
||||||
expect(document.documentData.data).toEqual(pdfContent);
|
expect(firstDocumentData.data).toEqual(pdfContent);
|
||||||
expect(document.documentData.initialData).toEqual(pdfContent);
|
expect(firstDocumentData.initialData).toEqual(pdfContent);
|
||||||
} else {
|
} else {
|
||||||
// For S3, we expect the data/initialData to be the S3 path (non-empty string)
|
// For S3, we expect the data/initialData to be the S3 path (non-empty string)
|
||||||
expect(document.documentData.data).toBeTruthy();
|
expect(firstDocumentData.data).toBeTruthy();
|
||||||
expect(document.documentData.initialData).toBeTruthy();
|
expect(firstDocumentData.initialData).toBeTruthy();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -422,7 +438,7 @@ test('[TEMPLATE]: should create a document from a template using template docume
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
redirectPath: `/t/${team.url}/templates/${template.id}/edit`,
|
redirectPath: `/t/${team.url}/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set template title
|
// Set template title
|
||||||
@ -455,30 +471,40 @@ test('[TEMPLATE]: should create a document from a template using template docume
|
|||||||
|
|
||||||
const documentId = Number(page.url().split('/').pop());
|
const documentId = Number(page.url().split('/').pop());
|
||||||
|
|
||||||
const document = await prisma.document.findFirstOrThrow({
|
const document = await prisma.envelope.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
id: documentId,
|
secondaryId: mapDocumentIdToSecondaryId(documentId),
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
documentData: true,
|
envelopeItems: {
|
||||||
|
include: {
|
||||||
|
documentData: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const templateWithData = await prisma.template.findFirstOrThrow({
|
const firstDocumentData = document.envelopeItems[0].documentData;
|
||||||
|
|
||||||
|
const templateWithData = await prisma.envelope.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
id: template.id,
|
id: template.id,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
templateDocumentData: true,
|
envelopeItems: {
|
||||||
|
include: {
|
||||||
|
documentData: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(document.title).toEqual('TEMPLATE_WITH_ORIGINAL_DOC');
|
expect(document.title).toEqual('TEMPLATE_WITH_ORIGINAL_DOC');
|
||||||
expect(document.documentData.data).toEqual(templateWithData.templateDocumentData.data);
|
expect(firstDocumentData.data).toEqual(templateWithData.envelopeItems[0].documentData.data);
|
||||||
expect(document.documentData.initialData).toEqual(
|
expect(firstDocumentData.initialData).toEqual(
|
||||||
templateWithData.templateDocumentData.initialData,
|
templateWithData.envelopeItems[0].documentData.initialData,
|
||||||
);
|
);
|
||||||
expect(document.documentData.type).toEqual(templateWithData.templateDocumentData.type);
|
expect(firstDocumentData.type).toEqual(templateWithData.envelopeItems[0].documentData.type);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('[TEMPLATE]: should persist document visibility when creating from template', async ({
|
test('[TEMPLATE]: should persist document visibility when creating from template', async ({
|
||||||
@ -493,7 +519,7 @@ test('[TEMPLATE]: should persist document visibility when creating from template
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: owner.email,
|
email: owner.email,
|
||||||
redirectPath: `/t/${team.url}/templates/${template.id}/edit`,
|
redirectPath: `/t/${team.url}/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set template title and visibility
|
// Set template title and visibility
|
||||||
@ -536,9 +562,16 @@ test('[TEMPLATE]: should persist document visibility when creating from template
|
|||||||
|
|
||||||
const documentId = Number(page.url().split('/').pop());
|
const documentId = Number(page.url().split('/').pop());
|
||||||
|
|
||||||
const document = await prisma.document.findFirstOrThrow({
|
const document = await prisma.envelope.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
id: documentId,
|
secondaryId: mapDocumentIdToSecondaryId(documentId),
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
envelopeItems: {
|
||||||
|
include: {
|
||||||
|
documentData: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { customAlphabet } from 'nanoid';
|
|||||||
|
|
||||||
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
||||||
import { createDocumentAuthOptions } from '@documenso/lib/utils/document-auth';
|
import { createDocumentAuthOptions } from '@documenso/lib/utils/document-auth';
|
||||||
|
import { mapSecondaryIdToTemplateId } from '@documenso/lib/utils/envelope';
|
||||||
import { formatDirectTemplatePath } from '@documenso/lib/utils/templates';
|
import { formatDirectTemplatePath } from '@documenso/lib/utils/templates';
|
||||||
import { seedTeam } from '@documenso/prisma/seed/teams';
|
import { seedTeam } from '@documenso/prisma/seed/teams';
|
||||||
import { seedDirectTemplate, seedTemplate } from '@documenso/prisma/seed/templates';
|
import { seedDirectTemplate, seedTemplate } from '@documenso/prisma/seed/templates';
|
||||||
@ -34,7 +35,7 @@ test('[DIRECT_TEMPLATES]: create direct link for template', async ({ page }) =>
|
|||||||
redirectPath: `/t/${team.url}/templates`,
|
redirectPath: `/t/${team.url}/templates`,
|
||||||
});
|
});
|
||||||
|
|
||||||
const url = `${NEXT_PUBLIC_WEBAPP_URL()}/t/${team.url}/templates/${teamTemplate.id}`;
|
const url = `${NEXT_PUBLIC_WEBAPP_URL()}/t/${team.url}/templates/${mapSecondaryIdToTemplateId(teamTemplate.secondaryId)}`;
|
||||||
|
|
||||||
// Owner should see list of templates with no direct link badge.
|
// Owner should see list of templates with no direct link badge.
|
||||||
await page.goto(url);
|
await page.goto(url);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { expect, test } from '@playwright/test';
|
import { expect, test } from '@playwright/test';
|
||||||
|
|
||||||
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
||||||
|
import { mapSecondaryIdToTemplateId } from '@documenso/lib/utils/envelope';
|
||||||
import { seedBlankTemplate } from '@documenso/prisma/seed/templates';
|
import { seedBlankTemplate } from '@documenso/prisma/seed/templates';
|
||||||
import { seedUser } from '@documenso/prisma/seed/users';
|
import { seedUser } from '@documenso/prisma/seed/users';
|
||||||
|
|
||||||
@ -20,10 +21,12 @@ test.describe('Unauthorized Access to Templates', () => {
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: unauthorizedUser.email,
|
email: unauthorizedUser.email,
|
||||||
redirectPath: `/t/${team.url}/templates/${template.id}`,
|
redirectPath: `/t/${team.url}/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
await page.goto(`${NEXT_PUBLIC_WEBAPP_URL()}/t/${team.url}/templates/${template.id}`);
|
await page.goto(
|
||||||
|
`${NEXT_PUBLIC_WEBAPP_URL()}/t/${team.url}/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}`,
|
||||||
|
);
|
||||||
await expect(page.getByRole('heading', { name: 'Oops! Something went wrong.' })).toBeVisible();
|
await expect(page.getByRole('heading', { name: 'Oops! Something went wrong.' })).toBeVisible();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -36,10 +39,12 @@ test.describe('Unauthorized Access to Templates', () => {
|
|||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: unauthorizedUser.email,
|
email: unauthorizedUser.email,
|
||||||
redirectPath: `/t/${team.url}/templates/${template.id}/edit`,
|
redirectPath: `/t/${team.url}/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}/edit`,
|
||||||
});
|
});
|
||||||
|
|
||||||
await page.goto(`${NEXT_PUBLIC_WEBAPP_URL()}/t/${team.url}/templates/${template.id}/edit`);
|
await page.goto(
|
||||||
|
`${NEXT_PUBLIC_WEBAPP_URL()}/t/${team.url}/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}/edit`,
|
||||||
|
);
|
||||||
await expect(page.getByRole('heading', { name: 'Oops! Something went wrong.' })).toBeVisible();
|
await expect(page.getByRole('heading', { name: 'Oops! Something went wrong.' })).toBeVisible();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { DocumentSource, SubscriptionStatus } from '@prisma/client';
|
import { DocumentSource, EnvelopeType, SubscriptionStatus } from '@prisma/client';
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
|
|
||||||
import { IS_BILLING_ENABLED } from '@documenso/lib/constants/app';
|
import { IS_BILLING_ENABLED } from '@documenso/lib/constants/app';
|
||||||
@ -84,8 +84,9 @@ export const getServerLimits = async ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const [documents, directTemplates] = await Promise.all([
|
const [documents, directTemplates] = await Promise.all([
|
||||||
prisma.document.count({
|
prisma.envelope.count({
|
||||||
where: {
|
where: {
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
team: {
|
team: {
|
||||||
organisationId: organisation.id,
|
organisationId: organisation.id,
|
||||||
},
|
},
|
||||||
@ -97,8 +98,9 @@ export const getServerLimits = async ({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
prisma.template.count({
|
prisma.envelope.count({
|
||||||
where: {
|
where: {
|
||||||
|
type: EnvelopeType.TEMPLATE,
|
||||||
team: {
|
team: {
|
||||||
organisationId: organisation.id,
|
organisationId: organisation.id,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
import type { TCreateOrGetShareLinkMutationSchema } from '@documenso/trpc/server/share-link-router/schema';
|
import type { TShareDocumentRequest } from '@documenso/trpc/server/document-router/share-document.types';
|
||||||
|
|
||||||
import { useCopyToClipboard } from './use-copy-to-clipboard';
|
import { useCopyToClipboard } from './use-copy-to-clipboard';
|
||||||
|
|
||||||
@ -12,14 +12,14 @@ export function useCopyShareLink({ onSuccess, onError }: UseCopyShareLinkOptions
|
|||||||
const [, copyToClipboard] = useCopyToClipboard();
|
const [, copyToClipboard] = useCopyToClipboard();
|
||||||
|
|
||||||
const { mutateAsync: createOrGetShareLink, isPending: isCreatingShareLink } =
|
const { mutateAsync: createOrGetShareLink, isPending: isCreatingShareLink } =
|
||||||
trpc.shareLink.createOrGetShareLink.useMutation();
|
trpc.document.share.useMutation();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy a newly created, or pre-existing share link to the user's clipboard.
|
* Copy a newly created, or pre-existing share link to the user's clipboard.
|
||||||
*
|
*
|
||||||
* @param payload The payload to create or get a share link.
|
* @param payload The payload to create or get a share link.
|
||||||
*/
|
*/
|
||||||
const createAndCopyShareLink = async (payload: TCreateOrGetShareLinkMutationSchema) => {
|
const createAndCopyShareLink = async (payload: TShareDocumentRequest) => {
|
||||||
const valueToCopy = createOrGetShareLink(payload).then(
|
const valueToCopy = createOrGetShareLink(payload).then(
|
||||||
(result) => `${window.location.origin}/share/${result.slug}`,
|
(result) => `${window.location.origin}/share/${result.slug}`,
|
||||||
);
|
);
|
||||||
|
|||||||
@ -5,7 +5,9 @@ import type { Field } from '@prisma/client';
|
|||||||
import { getBoundingClientRect } from '@documenso/lib/client-only/get-bounding-client-rect';
|
import { getBoundingClientRect } from '@documenso/lib/client-only/get-bounding-client-rect';
|
||||||
import { PDF_VIEWER_PAGE_SELECTOR } from '@documenso/lib/constants/pdf-viewer';
|
import { PDF_VIEWER_PAGE_SELECTOR } from '@documenso/lib/constants/pdf-viewer';
|
||||||
|
|
||||||
export const useFieldPageCoords = (field: Field) => {
|
export const useFieldPageCoords = (
|
||||||
|
field: Pick<Field, 'positionX' | 'positionY' | 'width' | 'height' | 'page'>,
|
||||||
|
) => {
|
||||||
const [coords, setCoords] = useState({
|
const [coords, setCoords] = useState({
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { OrganisationGroupType, TeamMemberRole } from '@prisma/client';
|
import { DocumentVisibility, OrganisationGroupType, TeamMemberRole } from '@prisma/client';
|
||||||
|
|
||||||
export const TEAM_URL_ROOT_REGEX = new RegExp('^/t/[^/]+/?$');
|
export const TEAM_URL_ROOT_REGEX = new RegExp('^/t/[^/]+/?$');
|
||||||
export const TEAM_URL_REGEX = new RegExp('^/t/[^/]+');
|
export const TEAM_URL_REGEX = new RegExp('^/t/[^/]+');
|
||||||
@ -33,6 +33,16 @@ export const TEAM_MEMBER_ROLE_PERMISSIONS_MAP = {
|
|||||||
MANAGE_TEAM: [TeamMemberRole.ADMIN, TeamMemberRole.MANAGER],
|
MANAGE_TEAM: [TeamMemberRole.ADMIN, TeamMemberRole.MANAGER],
|
||||||
} satisfies Record<string, TeamMemberRole[]>;
|
} satisfies Record<string, TeamMemberRole[]>;
|
||||||
|
|
||||||
|
export const TEAM_DOCUMENT_VISIBILITY_MAP = {
|
||||||
|
[TeamMemberRole.ADMIN]: [
|
||||||
|
DocumentVisibility.ADMIN,
|
||||||
|
DocumentVisibility.MANAGER_AND_ABOVE,
|
||||||
|
DocumentVisibility.EVERYONE,
|
||||||
|
],
|
||||||
|
[TeamMemberRole.MANAGER]: [DocumentVisibility.MANAGER_AND_ABOVE, DocumentVisibility.EVERYONE],
|
||||||
|
[TeamMemberRole.MEMBER]: [DocumentVisibility.EVERYONE],
|
||||||
|
} satisfies Record<TeamMemberRole, DocumentVisibility[]>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A hierarchy of team member roles to determine which role has higher permission than another.
|
* A hierarchy of team member roles to determine which role has higher permission than another.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { createElement } from 'react';
|
import { createElement } from 'react';
|
||||||
|
|
||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { ReadStatus, SendStatus, SigningStatus } from '@prisma/client';
|
import { EnvelopeType, ReadStatus, SendStatus, SigningStatus } from '@prisma/client';
|
||||||
|
|
||||||
import { mailer } from '@documenso/email/mailer';
|
import { mailer } from '@documenso/email/mailer';
|
||||||
import DocumentCancelTemplate from '@documenso/email/templates/document-cancel';
|
import DocumentCancelTemplate from '@documenso/email/templates/document-cancel';
|
||||||
@ -11,6 +11,7 @@ import { getI18nInstance } from '../../../client-only/providers/i18n-server';
|
|||||||
import { NEXT_PUBLIC_WEBAPP_URL } from '../../../constants/app';
|
import { NEXT_PUBLIC_WEBAPP_URL } from '../../../constants/app';
|
||||||
import { getEmailContext } from '../../../server-only/email/get-email-context';
|
import { getEmailContext } from '../../../server-only/email/get-email-context';
|
||||||
import { extractDerivedDocumentEmailSettings } from '../../../types/document-email';
|
import { extractDerivedDocumentEmailSettings } from '../../../types/document-email';
|
||||||
|
import { unsafeBuildEnvelopeIdQuery } from '../../../utils/envelope';
|
||||||
import { renderEmailWithI18N } from '../../../utils/render-email-with-i18n';
|
import { renderEmailWithI18N } from '../../../utils/render-email-with-i18n';
|
||||||
import type { JobRunIO } from '../../client/_internal/job';
|
import type { JobRunIO } from '../../client/_internal/job';
|
||||||
import type { TSendDocumentCancelledEmailsJobDefinition } from './send-document-cancelled-emails';
|
import type { TSendDocumentCancelledEmailsJobDefinition } from './send-document-cancelled-emails';
|
||||||
@ -24,10 +25,14 @@ export const run = async ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { documentId, cancellationReason } = payload;
|
const { documentId, cancellationReason } = payload;
|
||||||
|
|
||||||
const document = await prisma.document.findFirstOrThrow({
|
const envelope = await prisma.envelope.findFirstOrThrow({
|
||||||
where: {
|
where: unsafeBuildEnvelopeIdQuery(
|
||||||
id: documentId,
|
{
|
||||||
},
|
type: 'documentId',
|
||||||
|
id: documentId,
|
||||||
|
},
|
||||||
|
EnvelopeType.DOCUMENT,
|
||||||
|
),
|
||||||
include: {
|
include: {
|
||||||
user: {
|
user: {
|
||||||
select: {
|
select: {
|
||||||
@ -52,12 +57,12 @@ export const run = async ({
|
|||||||
emailType: 'RECIPIENT',
|
emailType: 'RECIPIENT',
|
||||||
source: {
|
source: {
|
||||||
type: 'team',
|
type: 'team',
|
||||||
teamId: document.teamId,
|
teamId: envelope.teamId,
|
||||||
},
|
},
|
||||||
meta: document.documentMeta,
|
meta: envelope.documentMeta,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { documentMeta, user: documentOwner } = document;
|
const { documentMeta, user: documentOwner } = envelope;
|
||||||
|
|
||||||
// Check if document cancellation emails are enabled
|
// Check if document cancellation emails are enabled
|
||||||
const isEmailEnabled = extractDerivedDocumentEmailSettings(documentMeta).documentDeleted;
|
const isEmailEnabled = extractDerivedDocumentEmailSettings(documentMeta).documentDeleted;
|
||||||
@ -69,7 +74,7 @@ export const run = async ({
|
|||||||
const i18n = await getI18nInstance(emailLanguage);
|
const i18n = await getI18nInstance(emailLanguage);
|
||||||
|
|
||||||
// Send cancellation emails to all recipients who have been sent the document or viewed it
|
// Send cancellation emails to all recipients who have been sent the document or viewed it
|
||||||
const recipientsToNotify = document.recipients.filter(
|
const recipientsToNotify = envelope.recipients.filter(
|
||||||
(recipient) =>
|
(recipient) =>
|
||||||
(recipient.sendStatus === SendStatus.SENT || recipient.readStatus === ReadStatus.OPENED) &&
|
(recipient.sendStatus === SendStatus.SENT || recipient.readStatus === ReadStatus.OPENED) &&
|
||||||
recipient.signingStatus !== SigningStatus.REJECTED,
|
recipient.signingStatus !== SigningStatus.REJECTED,
|
||||||
@ -79,7 +84,7 @@ export const run = async ({
|
|||||||
await Promise.all(
|
await Promise.all(
|
||||||
recipientsToNotify.map(async (recipient) => {
|
recipientsToNotify.map(async (recipient) => {
|
||||||
const template = createElement(DocumentCancelTemplate, {
|
const template = createElement(DocumentCancelTemplate, {
|
||||||
documentName: document.title,
|
documentName: envelope.title,
|
||||||
inviterName: documentOwner.name || undefined,
|
inviterName: documentOwner.name || undefined,
|
||||||
inviterEmail: documentOwner.email,
|
inviterEmail: documentOwner.email,
|
||||||
assetBaseUrl: NEXT_PUBLIC_WEBAPP_URL(),
|
assetBaseUrl: NEXT_PUBLIC_WEBAPP_URL(),
|
||||||
@ -102,7 +107,7 @@ export const run = async ({
|
|||||||
},
|
},
|
||||||
from: senderEmail,
|
from: senderEmail,
|
||||||
replyTo: replyToEmail,
|
replyTo: replyToEmail,
|
||||||
subject: i18n._(msg`Document "${document.title}" Cancelled`),
|
subject: i18n._(msg`Document "${envelope.title}" Cancelled`),
|
||||||
html,
|
html,
|
||||||
text,
|
text,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { createElement } from 'react';
|
import { createElement } from 'react';
|
||||||
|
|
||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
|
import { EnvelopeType } from '@prisma/client';
|
||||||
|
|
||||||
import { mailer } from '@documenso/email/mailer';
|
import { mailer } from '@documenso/email/mailer';
|
||||||
import { DocumentRecipientSignedEmailTemplate } from '@documenso/email/templates/document-recipient-signed';
|
import { DocumentRecipientSignedEmailTemplate } from '@documenso/email/templates/document-recipient-signed';
|
||||||
@ -10,6 +11,7 @@ import { getI18nInstance } from '../../../client-only/providers/i18n-server';
|
|||||||
import { NEXT_PUBLIC_WEBAPP_URL } from '../../../constants/app';
|
import { NEXT_PUBLIC_WEBAPP_URL } from '../../../constants/app';
|
||||||
import { getEmailContext } from '../../../server-only/email/get-email-context';
|
import { getEmailContext } from '../../../server-only/email/get-email-context';
|
||||||
import { extractDerivedDocumentEmailSettings } from '../../../types/document-email';
|
import { extractDerivedDocumentEmailSettings } from '../../../types/document-email';
|
||||||
|
import { unsafeBuildEnvelopeIdQuery } from '../../../utils/envelope';
|
||||||
import { renderEmailWithI18N } from '../../../utils/render-email-with-i18n';
|
import { renderEmailWithI18N } from '../../../utils/render-email-with-i18n';
|
||||||
import type { JobRunIO } from '../../client/_internal/job';
|
import type { JobRunIO } from '../../client/_internal/job';
|
||||||
import type { TSendRecipientSignedEmailJobDefinition } from './send-recipient-signed-email';
|
import type { TSendRecipientSignedEmailJobDefinition } from './send-recipient-signed-email';
|
||||||
@ -23,9 +25,15 @@ export const run = async ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { documentId, recipientId } = payload;
|
const { documentId, recipientId } = payload;
|
||||||
|
|
||||||
const document = await prisma.document.findFirst({
|
const envelope = await prisma.envelope.findFirst({
|
||||||
where: {
|
where: {
|
||||||
id: documentId,
|
...unsafeBuildEnvelopeIdQuery(
|
||||||
|
{
|
||||||
|
type: 'documentId',
|
||||||
|
id: documentId,
|
||||||
|
},
|
||||||
|
EnvelopeType.DOCUMENT,
|
||||||
|
),
|
||||||
recipients: {
|
recipients: {
|
||||||
some: {
|
some: {
|
||||||
id: recipientId,
|
id: recipientId,
|
||||||
@ -49,25 +57,25 @@ export const run = async ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!document) {
|
if (!envelope) {
|
||||||
throw new Error('Document not found');
|
throw new Error('Document not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document.recipients.length === 0) {
|
if (envelope.recipients.length === 0) {
|
||||||
throw new Error('Document has no recipients');
|
throw new Error('Document has no recipients');
|
||||||
}
|
}
|
||||||
|
|
||||||
const isRecipientSignedEmailEnabled = extractDerivedDocumentEmailSettings(
|
const isRecipientSignedEmailEnabled = extractDerivedDocumentEmailSettings(
|
||||||
document.documentMeta,
|
envelope.documentMeta,
|
||||||
).recipientSigned;
|
).recipientSigned;
|
||||||
|
|
||||||
if (!isRecipientSignedEmailEnabled) {
|
if (!isRecipientSignedEmailEnabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [recipient] = document.recipients;
|
const [recipient] = envelope.recipients;
|
||||||
const { email: recipientEmail, name: recipientName } = recipient;
|
const { email: recipientEmail, name: recipientName } = recipient;
|
||||||
const { user: owner } = document;
|
const { user: owner } = envelope;
|
||||||
|
|
||||||
const recipientReference = recipientName || recipientEmail;
|
const recipientReference = recipientName || recipientEmail;
|
||||||
|
|
||||||
@ -80,9 +88,9 @@ export const run = async ({
|
|||||||
emailType: 'INTERNAL',
|
emailType: 'INTERNAL',
|
||||||
source: {
|
source: {
|
||||||
type: 'team',
|
type: 'team',
|
||||||
teamId: document.teamId,
|
teamId: envelope.teamId,
|
||||||
},
|
},
|
||||||
meta: document.documentMeta,
|
meta: envelope.documentMeta,
|
||||||
});
|
});
|
||||||
|
|
||||||
const assetBaseUrl = NEXT_PUBLIC_WEBAPP_URL() || 'http://localhost:3000';
|
const assetBaseUrl = NEXT_PUBLIC_WEBAPP_URL() || 'http://localhost:3000';
|
||||||
@ -90,7 +98,7 @@ export const run = async ({
|
|||||||
const i18n = await getI18nInstance(emailLanguage);
|
const i18n = await getI18nInstance(emailLanguage);
|
||||||
|
|
||||||
const template = createElement(DocumentRecipientSignedEmailTemplate, {
|
const template = createElement(DocumentRecipientSignedEmailTemplate, {
|
||||||
documentName: document.title,
|
documentName: envelope.title,
|
||||||
recipientName,
|
recipientName,
|
||||||
recipientEmail,
|
recipientEmail,
|
||||||
assetBaseUrl,
|
assetBaseUrl,
|
||||||
@ -112,7 +120,7 @@ export const run = async ({
|
|||||||
address: owner.email,
|
address: owner.email,
|
||||||
},
|
},
|
||||||
from: senderEmail,
|
from: senderEmail,
|
||||||
subject: i18n._(msg`${recipientReference} has signed "${document.title}"`),
|
subject: i18n._(msg`${recipientReference} has signed "${envelope.title}"`),
|
||||||
html,
|
html,
|
||||||
text,
|
text,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { createElement } from 'react';
|
import { createElement } from 'react';
|
||||||
|
|
||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { SendStatus, SigningStatus } from '@prisma/client';
|
import { EnvelopeType, SendStatus, SigningStatus } from '@prisma/client';
|
||||||
|
|
||||||
import { mailer } from '@documenso/email/mailer';
|
import { mailer } from '@documenso/email/mailer';
|
||||||
import DocumentRejectedEmail from '@documenso/email/templates/document-rejected';
|
import DocumentRejectedEmail from '@documenso/email/templates/document-rejected';
|
||||||
@ -13,6 +13,7 @@ import { NEXT_PUBLIC_WEBAPP_URL } from '../../../constants/app';
|
|||||||
import { DOCUMENSO_INTERNAL_EMAIL } from '../../../constants/email';
|
import { DOCUMENSO_INTERNAL_EMAIL } from '../../../constants/email';
|
||||||
import { getEmailContext } from '../../../server-only/email/get-email-context';
|
import { getEmailContext } from '../../../server-only/email/get-email-context';
|
||||||
import { extractDerivedDocumentEmailSettings } from '../../../types/document-email';
|
import { extractDerivedDocumentEmailSettings } from '../../../types/document-email';
|
||||||
|
import { unsafeBuildEnvelopeIdQuery } from '../../../utils/envelope';
|
||||||
import { renderEmailWithI18N } from '../../../utils/render-email-with-i18n';
|
import { renderEmailWithI18N } from '../../../utils/render-email-with-i18n';
|
||||||
import { formatDocumentsPath } from '../../../utils/teams';
|
import { formatDocumentsPath } from '../../../utils/teams';
|
||||||
import type { JobRunIO } from '../../client/_internal/job';
|
import type { JobRunIO } from '../../client/_internal/job';
|
||||||
@ -27,11 +28,15 @@ export const run = async ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { documentId, recipientId } = payload;
|
const { documentId, recipientId } = payload;
|
||||||
|
|
||||||
const [document, recipient] = await Promise.all([
|
const [envelope, recipient] = await Promise.all([
|
||||||
prisma.document.findFirstOrThrow({
|
prisma.envelope.findFirstOrThrow({
|
||||||
where: {
|
where: unsafeBuildEnvelopeIdQuery(
|
||||||
id: documentId,
|
{
|
||||||
},
|
type: 'documentId',
|
||||||
|
id: documentId,
|
||||||
|
},
|
||||||
|
EnvelopeType.DOCUMENT,
|
||||||
|
),
|
||||||
include: {
|
include: {
|
||||||
user: {
|
user: {
|
||||||
select: {
|
select: {
|
||||||
@ -58,10 +63,10 @@ export const run = async ({
|
|||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const { user: documentOwner } = document;
|
const { user: documentOwner } = envelope;
|
||||||
|
|
||||||
const isEmailEnabled = extractDerivedDocumentEmailSettings(
|
const isEmailEnabled = extractDerivedDocumentEmailSettings(
|
||||||
document.documentMeta,
|
envelope.documentMeta,
|
||||||
).recipientSigningRequest;
|
).recipientSigningRequest;
|
||||||
|
|
||||||
if (!isEmailEnabled) {
|
if (!isEmailEnabled) {
|
||||||
@ -72,9 +77,9 @@ export const run = async ({
|
|||||||
emailType: 'RECIPIENT',
|
emailType: 'RECIPIENT',
|
||||||
source: {
|
source: {
|
||||||
type: 'team',
|
type: 'team',
|
||||||
teamId: document.teamId,
|
teamId: envelope.teamId,
|
||||||
},
|
},
|
||||||
meta: document.documentMeta,
|
meta: envelope.documentMeta,
|
||||||
});
|
});
|
||||||
|
|
||||||
const i18n = await getI18nInstance(emailLanguage);
|
const i18n = await getI18nInstance(emailLanguage);
|
||||||
@ -83,8 +88,8 @@ export const run = async ({
|
|||||||
await io.runTask('send-rejection-confirmation-email', async () => {
|
await io.runTask('send-rejection-confirmation-email', async () => {
|
||||||
const recipientTemplate = createElement(DocumentRejectionConfirmedEmail, {
|
const recipientTemplate = createElement(DocumentRejectionConfirmedEmail, {
|
||||||
recipientName: recipient.name,
|
recipientName: recipient.name,
|
||||||
documentName: document.title,
|
documentName: envelope.title,
|
||||||
documentOwnerName: document.user.name || document.user.email,
|
documentOwnerName: envelope.user.name || envelope.user.email,
|
||||||
reason: recipient.rejectionReason || '',
|
reason: recipient.rejectionReason || '',
|
||||||
assetBaseUrl: NEXT_PUBLIC_WEBAPP_URL(),
|
assetBaseUrl: NEXT_PUBLIC_WEBAPP_URL(),
|
||||||
});
|
});
|
||||||
@ -105,7 +110,7 @@ export const run = async ({
|
|||||||
},
|
},
|
||||||
from: senderEmail,
|
from: senderEmail,
|
||||||
replyTo: replyToEmail,
|
replyTo: replyToEmail,
|
||||||
subject: i18n._(msg`Document "${document.title}" - Rejection Confirmed`),
|
subject: i18n._(msg`Document "${envelope.title}" - Rejection Confirmed`),
|
||||||
html,
|
html,
|
||||||
text,
|
text,
|
||||||
});
|
});
|
||||||
@ -115,9 +120,9 @@ export const run = async ({
|
|||||||
await io.runTask('send-owner-notification-email', async () => {
|
await io.runTask('send-owner-notification-email', async () => {
|
||||||
const ownerTemplate = createElement(DocumentRejectedEmail, {
|
const ownerTemplate = createElement(DocumentRejectedEmail, {
|
||||||
recipientName: recipient.name,
|
recipientName: recipient.name,
|
||||||
documentName: document.title,
|
documentName: envelope.title,
|
||||||
documentUrl: `${NEXT_PUBLIC_WEBAPP_URL()}${formatDocumentsPath(document.team?.url)}/${
|
documentUrl: `${NEXT_PUBLIC_WEBAPP_URL()}${formatDocumentsPath(envelope.team?.url)}/${
|
||||||
document.id
|
envelope.id
|
||||||
}`,
|
}`,
|
||||||
rejectionReason: recipient.rejectionReason || '',
|
rejectionReason: recipient.rejectionReason || '',
|
||||||
assetBaseUrl: NEXT_PUBLIC_WEBAPP_URL(),
|
assetBaseUrl: NEXT_PUBLIC_WEBAPP_URL(),
|
||||||
@ -138,7 +143,7 @@ export const run = async ({
|
|||||||
address: documentOwner.email,
|
address: documentOwner.email,
|
||||||
},
|
},
|
||||||
from: DOCUMENSO_INTERNAL_EMAIL, // Purposefully using internal email here.
|
from: DOCUMENSO_INTERNAL_EMAIL, // Purposefully using internal email here.
|
||||||
subject: i18n._(msg`Document "${document.title}" - Rejected by ${recipient.name}`),
|
subject: i18n._(msg`Document "${envelope.title}" - Rejected by ${recipient.name}`),
|
||||||
html,
|
html,
|
||||||
text,
|
text,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import { msg } from '@lingui/core/macro';
|
|||||||
import {
|
import {
|
||||||
DocumentSource,
|
DocumentSource,
|
||||||
DocumentStatus,
|
DocumentStatus,
|
||||||
|
EnvelopeType,
|
||||||
OrganisationType,
|
OrganisationType,
|
||||||
RecipientRole,
|
RecipientRole,
|
||||||
SendStatus,
|
SendStatus,
|
||||||
@ -23,6 +24,7 @@ import { getEmailContext } from '../../../server-only/email/get-email-context';
|
|||||||
import { DOCUMENT_AUDIT_LOG_TYPE } from '../../../types/document-audit-logs';
|
import { DOCUMENT_AUDIT_LOG_TYPE } from '../../../types/document-audit-logs';
|
||||||
import { extractDerivedDocumentEmailSettings } from '../../../types/document-email';
|
import { extractDerivedDocumentEmailSettings } from '../../../types/document-email';
|
||||||
import { createDocumentAuditLogData } from '../../../utils/document-audit-logs';
|
import { createDocumentAuditLogData } from '../../../utils/document-audit-logs';
|
||||||
|
import { unsafeBuildEnvelopeIdQuery } from '../../../utils/envelope';
|
||||||
import { renderCustomEmailTemplate } from '../../../utils/render-custom-email-template';
|
import { renderCustomEmailTemplate } from '../../../utils/render-custom-email-template';
|
||||||
import { renderEmailWithI18N } from '../../../utils/render-email-with-i18n';
|
import { renderEmailWithI18N } from '../../../utils/render-email-with-i18n';
|
||||||
import type { JobRunIO } from '../../client/_internal/job';
|
import type { JobRunIO } from '../../client/_internal/job';
|
||||||
@ -37,7 +39,7 @@ export const run = async ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { userId, documentId, recipientId, requestMetadata } = payload;
|
const { userId, documentId, recipientId, requestMetadata } = payload;
|
||||||
|
|
||||||
const [user, document, recipient] = await Promise.all([
|
const [user, envelope, recipient] = await Promise.all([
|
||||||
prisma.user.findFirstOrThrow({
|
prisma.user.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
id: userId,
|
id: userId,
|
||||||
@ -48,9 +50,15 @@ export const run = async ({
|
|||||||
name: true,
|
name: true,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
prisma.document.findFirstOrThrow({
|
prisma.envelope.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
id: documentId,
|
...unsafeBuildEnvelopeIdQuery(
|
||||||
|
{
|
||||||
|
type: 'documentId',
|
||||||
|
id: documentId,
|
||||||
|
},
|
||||||
|
EnvelopeType.DOCUMENT,
|
||||||
|
),
|
||||||
status: DocumentStatus.PENDING,
|
status: DocumentStatus.PENDING,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
@ -70,14 +78,14 @@ export const run = async ({
|
|||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const { documentMeta, team } = document;
|
const { documentMeta, team } = envelope;
|
||||||
|
|
||||||
if (recipient.role === RecipientRole.CC) {
|
if (recipient.role === RecipientRole.CC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isRecipientSigningRequestEmailEnabled = extractDerivedDocumentEmailSettings(
|
const isRecipientSigningRequestEmailEnabled = extractDerivedDocumentEmailSettings(
|
||||||
document.documentMeta,
|
envelope.documentMeta,
|
||||||
).recipientSigningRequest;
|
).recipientSigningRequest;
|
||||||
|
|
||||||
if (!isRecipientSigningRequestEmailEnabled) {
|
if (!isRecipientSigningRequestEmailEnabled) {
|
||||||
@ -89,13 +97,13 @@ export const run = async ({
|
|||||||
emailType: 'RECIPIENT',
|
emailType: 'RECIPIENT',
|
||||||
source: {
|
source: {
|
||||||
type: 'team',
|
type: 'team',
|
||||||
teamId: document.teamId,
|
teamId: envelope.teamId,
|
||||||
},
|
},
|
||||||
meta: document.documentMeta,
|
meta: envelope.documentMeta,
|
||||||
});
|
});
|
||||||
|
|
||||||
const customEmail = document?.documentMeta;
|
const customEmail = envelope?.documentMeta;
|
||||||
const isDirectTemplate = document.source === DocumentSource.TEMPLATE_DIRECT_LINK;
|
const isDirectTemplate = envelope.source === DocumentSource.TEMPLATE_DIRECT_LINK;
|
||||||
|
|
||||||
const recipientEmailType = RECIPIENT_ROLE_TO_EMAIL_TYPE[recipient.role];
|
const recipientEmailType = RECIPIENT_ROLE_TO_EMAIL_TYPE[recipient.role];
|
||||||
|
|
||||||
@ -113,7 +121,7 @@ export const run = async ({
|
|||||||
|
|
||||||
if (selfSigner) {
|
if (selfSigner) {
|
||||||
emailMessage = i18n._(
|
emailMessage = i18n._(
|
||||||
msg`You have initiated the document ${`"${document.title}"`} that requires you to ${recipientActionVerb} it.`,
|
msg`You have initiated the document ${`"${envelope.title}"`} that requires you to ${recipientActionVerb} it.`,
|
||||||
);
|
);
|
||||||
emailSubject = i18n._(msg`Please ${recipientActionVerb} your document`);
|
emailSubject = i18n._(msg`Please ${recipientActionVerb} your document`);
|
||||||
}
|
}
|
||||||
@ -136,8 +144,8 @@ export const run = async ({
|
|||||||
|
|
||||||
emailMessage = i18n._(
|
emailMessage = i18n._(
|
||||||
settings.includeSenderDetails
|
settings.includeSenderDetails
|
||||||
? msg`${inviterName} on behalf of "${team.name}" has invited you to ${recipientActionVerb} the document "${document.title}".`
|
? msg`${inviterName} on behalf of "${team.name}" has invited you to ${recipientActionVerb} the document "${envelope.title}".`
|
||||||
: msg`${team.name} has invited you to ${recipientActionVerb} the document "${document.title}".`,
|
: msg`${team.name} has invited you to ${recipientActionVerb} the document "${envelope.title}".`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,14 +153,14 @@ export const run = async ({
|
|||||||
const customEmailTemplate = {
|
const customEmailTemplate = {
|
||||||
'signer.name': name,
|
'signer.name': name,
|
||||||
'signer.email': email,
|
'signer.email': email,
|
||||||
'document.name': document.title,
|
'document.name': envelope.title,
|
||||||
};
|
};
|
||||||
|
|
||||||
const assetBaseUrl = NEXT_PUBLIC_WEBAPP_URL() || 'http://localhost:3000';
|
const assetBaseUrl = NEXT_PUBLIC_WEBAPP_URL() || 'http://localhost:3000';
|
||||||
const signDocumentLink = `${NEXT_PUBLIC_WEBAPP_URL()}/sign/${recipient.token}`;
|
const signDocumentLink = `${NEXT_PUBLIC_WEBAPP_URL()}/sign/${recipient.token}`;
|
||||||
|
|
||||||
const template = createElement(DocumentInviteEmailTemplate, {
|
const template = createElement(DocumentInviteEmailTemplate, {
|
||||||
documentName: document.title,
|
documentName: envelope.title,
|
||||||
inviterName: user.name || undefined,
|
inviterName: user.name || undefined,
|
||||||
inviterEmail:
|
inviterEmail:
|
||||||
organisationType === OrganisationType.ORGANISATION
|
organisationType === OrganisationType.ORGANISATION
|
||||||
@ -210,7 +218,7 @@ export const run = async ({
|
|||||||
await prisma.documentAuditLog.create({
|
await prisma.documentAuditLog.create({
|
||||||
data: createDocumentAuditLogData({
|
data: createDocumentAuditLogData({
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.EMAIL_SENT,
|
type: DOCUMENT_AUDIT_LOG_TYPE.EMAIL_SENT,
|
||||||
documentId: document.id,
|
envelopeId: envelope.id,
|
||||||
user,
|
user,
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
@ -99,9 +99,12 @@ export const run = async ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const document = await io.runTask(`create-document-${rowIndex}`, async () => {
|
const envelope = await io.runTask(`create-document-${rowIndex}`, async () => {
|
||||||
return await createDocumentFromTemplate({
|
return await createDocumentFromTemplate({
|
||||||
templateId: template.id,
|
id: {
|
||||||
|
type: 'templateId',
|
||||||
|
id: template.id,
|
||||||
|
},
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
recipients: recipients.map((recipient, index) => {
|
recipients: recipients.map((recipient, index) => {
|
||||||
@ -124,7 +127,10 @@ export const run = async ({
|
|||||||
if (sendImmediately) {
|
if (sendImmediately) {
|
||||||
await io.runTask(`send-document-${rowIndex}`, async () => {
|
await io.runTask(`send-document-${rowIndex}`, async () => {
|
||||||
await sendDocument({
|
await sendDocument({
|
||||||
documentId: document.id,
|
id: {
|
||||||
|
type: 'envelopeId',
|
||||||
|
id: envelope.id,
|
||||||
|
},
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
requestMetadata: {
|
requestMetadata: {
|
||||||
|
|||||||
@ -1,4 +1,10 @@
|
|||||||
import { DocumentStatus, RecipientRole, SigningStatus, WebhookTriggerEvents } from '@prisma/client';
|
import {
|
||||||
|
DocumentStatus,
|
||||||
|
EnvelopeType,
|
||||||
|
RecipientRole,
|
||||||
|
SigningStatus,
|
||||||
|
WebhookTriggerEvents,
|
||||||
|
} from '@prisma/client';
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { PDFDocument } from 'pdf-lib';
|
import { PDFDocument } from 'pdf-lib';
|
||||||
@ -22,7 +28,7 @@ import { triggerWebhook } from '../../../server-only/webhooks/trigger/trigger-we
|
|||||||
import { DOCUMENT_AUDIT_LOG_TYPE } from '../../../types/document-audit-logs';
|
import { DOCUMENT_AUDIT_LOG_TYPE } from '../../../types/document-audit-logs';
|
||||||
import {
|
import {
|
||||||
ZWebhookDocumentSchema,
|
ZWebhookDocumentSchema,
|
||||||
mapDocumentToWebhookDocumentPayload,
|
mapEnvelopeToWebhookDocumentPayload,
|
||||||
} from '../../../types/webhook-payload';
|
} from '../../../types/webhook-payload';
|
||||||
import { prefixedId } from '../../../universal/id';
|
import { prefixedId } from '../../../universal/id';
|
||||||
import { getFileServerSide } from '../../../universal/upload/get-file.server';
|
import { getFileServerSide } from '../../../universal/upload/get-file.server';
|
||||||
@ -30,6 +36,7 @@ import { putPdfFileServerSide } from '../../../universal/upload/put-file.server'
|
|||||||
import { fieldsContainUnsignedRequiredField } from '../../../utils/advanced-fields-helpers';
|
import { fieldsContainUnsignedRequiredField } from '../../../utils/advanced-fields-helpers';
|
||||||
import { isDocumentCompleted } from '../../../utils/document';
|
import { isDocumentCompleted } from '../../../utils/document';
|
||||||
import { createDocumentAuditLogData } from '../../../utils/document-audit-logs';
|
import { createDocumentAuditLogData } from '../../../utils/document-audit-logs';
|
||||||
|
import { mapDocumentIdToSecondaryId } from '../../../utils/envelope';
|
||||||
import type { JobRunIO } from '../../client/_internal/job';
|
import type { JobRunIO } from '../../client/_internal/job';
|
||||||
import type { TSealDocumentJobDefinition } from './seal-document';
|
import type { TSealDocumentJobDefinition } from './seal-document';
|
||||||
|
|
||||||
@ -42,24 +49,35 @@ export const run = async ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { documentId, sendEmail = true, isResealing = false, requestMetadata } = payload;
|
const { documentId, sendEmail = true, isResealing = false, requestMetadata } = payload;
|
||||||
|
|
||||||
const document = await prisma.document.findFirstOrThrow({
|
const envelope = await prisma.envelope.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
id: documentId,
|
type: EnvelopeType.DOCUMENT,
|
||||||
|
secondaryId: mapDocumentIdToSecondaryId(documentId),
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
documentMeta: true,
|
documentMeta: true,
|
||||||
recipients: true,
|
recipients: true,
|
||||||
|
envelopeItems: {
|
||||||
|
select: {
|
||||||
|
documentDataId: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Todo: Envelopes
|
||||||
|
if (envelope.envelopeItems.length !== 1) {
|
||||||
|
throw new Error('1 Envelope item required');
|
||||||
|
}
|
||||||
|
|
||||||
const settings = await getTeamSettings({
|
const settings = await getTeamSettings({
|
||||||
userId: document.userId,
|
userId: envelope.userId,
|
||||||
teamId: document.teamId,
|
teamId: envelope.teamId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const isComplete =
|
const isComplete =
|
||||||
document.recipients.some((recipient) => recipient.signingStatus === SigningStatus.REJECTED) ||
|
envelope.recipients.some((recipient) => recipient.signingStatus === SigningStatus.REJECTED) ||
|
||||||
document.recipients.every((recipient) => recipient.signingStatus === SigningStatus.SIGNED);
|
envelope.recipients.every((recipient) => recipient.signingStatus === SigningStatus.SIGNED);
|
||||||
|
|
||||||
if (!isComplete) {
|
if (!isComplete) {
|
||||||
throw new AppError(AppErrorCode.UNKNOWN_ERROR, {
|
throw new AppError(AppErrorCode.UNKNOWN_ERROR, {
|
||||||
@ -71,13 +89,13 @@ export const run = async ({
|
|||||||
// after it has already run through the update task further below.
|
// after it has already run through the update task further below.
|
||||||
// eslint-disable-next-line @typescript-eslint/require-await
|
// eslint-disable-next-line @typescript-eslint/require-await
|
||||||
const documentStatus = await io.runTask('get-document-status', async () => {
|
const documentStatus = await io.runTask('get-document-status', async () => {
|
||||||
return document.status;
|
return envelope.status;
|
||||||
});
|
});
|
||||||
|
|
||||||
// This is the same case as above.
|
// This is the same case as above.
|
||||||
// eslint-disable-next-line @typescript-eslint/require-await
|
// eslint-disable-next-line @typescript-eslint/require-await
|
||||||
const documentDataId = await io.runTask('get-document-data-id', async () => {
|
const documentDataId = await io.runTask('get-document-data-id', async () => {
|
||||||
return document.documentDataId;
|
return envelope.envelopeItems[0].documentDataId;
|
||||||
});
|
});
|
||||||
|
|
||||||
const documentData = await prisma.documentData.findFirst({
|
const documentData = await prisma.documentData.findFirst({
|
||||||
@ -87,12 +105,12 @@ export const run = async ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!documentData) {
|
if (!documentData) {
|
||||||
throw new Error(`Document ${document.id} has no document data`);
|
throw new Error(`Document ${envelope.id} has no document data`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const recipients = await prisma.recipient.findMany({
|
const recipients = await prisma.recipient.findMany({
|
||||||
where: {
|
where: {
|
||||||
documentId: document.id,
|
envelopeId: envelope.id,
|
||||||
role: {
|
role: {
|
||||||
not: RecipientRole.CC,
|
not: RecipientRole.CC,
|
||||||
},
|
},
|
||||||
@ -111,7 +129,7 @@ export const run = async ({
|
|||||||
|
|
||||||
const fields = await prisma.field.findMany({
|
const fields = await prisma.field.findMany({
|
||||||
where: {
|
where: {
|
||||||
documentId: document.id,
|
envelopeId: envelope.id,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
signature: true,
|
signature: true,
|
||||||
@ -120,7 +138,7 @@ export const run = async ({
|
|||||||
|
|
||||||
// Skip the field check if the document is rejected
|
// Skip the field check if the document is rejected
|
||||||
if (!isRejected && fieldsContainUnsignedRequiredField(fields)) {
|
if (!isRejected && fieldsContainUnsignedRequiredField(fields)) {
|
||||||
throw new Error(`Document ${document.id} has unsigned required fields`);
|
throw new Error(`Document ${envelope.id} has unsigned required fields`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isResealing) {
|
if (isResealing) {
|
||||||
@ -129,10 +147,10 @@ export const run = async ({
|
|||||||
documentData.data = documentData.initialData;
|
documentData.data = documentData.initialData;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!document.qrToken) {
|
if (!envelope.qrToken) {
|
||||||
await prisma.document.update({
|
await prisma.envelope.update({
|
||||||
where: {
|
where: {
|
||||||
id: document.id,
|
id: envelope.id,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
qrToken: prefixedId('qr'),
|
qrToken: prefixedId('qr'),
|
||||||
@ -145,7 +163,7 @@ export const run = async ({
|
|||||||
const certificateData = settings.includeSigningCertificate
|
const certificateData = settings.includeSigningCertificate
|
||||||
? await getCertificatePdf({
|
? await getCertificatePdf({
|
||||||
documentId,
|
documentId,
|
||||||
language: document.documentMeta?.language,
|
language: envelope.documentMeta?.language,
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.log('Failed to get certificate PDF');
|
console.log('Failed to get certificate PDF');
|
||||||
console.error(e);
|
console.error(e);
|
||||||
@ -157,7 +175,7 @@ export const run = async ({
|
|||||||
const auditLogData = settings.includeAuditLog
|
const auditLogData = settings.includeAuditLog
|
||||||
? await getAuditLogsPdf({
|
? await getAuditLogsPdf({
|
||||||
documentId,
|
documentId,
|
||||||
language: document.documentMeta?.language,
|
language: envelope.documentMeta?.language,
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.log('Failed to get audit logs PDF');
|
console.log('Failed to get audit logs PDF');
|
||||||
console.error(e);
|
console.error(e);
|
||||||
@ -204,7 +222,7 @@ export const run = async ({
|
|||||||
|
|
||||||
for (const field of fields) {
|
for (const field of fields) {
|
||||||
if (field.inserted) {
|
if (field.inserted) {
|
||||||
document.useLegacyFieldInsertion
|
envelope.useLegacyFieldInsertion
|
||||||
? await legacy_insertFieldInPDF(pdfDoc, field)
|
? await legacy_insertFieldInPDF(pdfDoc, field)
|
||||||
: await insertFieldInPDF(pdfDoc, field);
|
: await insertFieldInPDF(pdfDoc, field);
|
||||||
}
|
}
|
||||||
@ -217,7 +235,8 @@ export const run = async ({
|
|||||||
const pdfBytes = await pdfDoc.save();
|
const pdfBytes = await pdfDoc.save();
|
||||||
const pdfBuffer = await signPdf({ pdf: Buffer.from(pdfBytes) });
|
const pdfBuffer = await signPdf({ pdf: Buffer.from(pdfBytes) });
|
||||||
|
|
||||||
const { name } = path.parse(document.title);
|
// Todo: Envelopes - Use the envelope item title instead.
|
||||||
|
const { name } = path.parse(envelope.title);
|
||||||
|
|
||||||
// Add suffix based on document status
|
// Add suffix based on document status
|
||||||
const suffix = isRejected ? '_rejected.pdf' : '_signed.pdf';
|
const suffix = isRejected ? '_rejected.pdf' : '_signed.pdf';
|
||||||
@ -238,7 +257,7 @@ export const run = async ({
|
|||||||
distinctId: nanoid(),
|
distinctId: nanoid(),
|
||||||
event: 'App: Document Sealed',
|
event: 'App: Document Sealed',
|
||||||
properties: {
|
properties: {
|
||||||
documentId: document.id,
|
documentId: envelope.id,
|
||||||
isRejected,
|
isRejected,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -252,9 +271,9 @@ export const run = async ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await tx.document.update({
|
await tx.envelope.update({
|
||||||
where: {
|
where: {
|
||||||
id: document.id,
|
id: envelope.id,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
status: isRejected ? DocumentStatus.REJECTED : DocumentStatus.COMPLETED,
|
status: isRejected ? DocumentStatus.REJECTED : DocumentStatus.COMPLETED,
|
||||||
@ -274,7 +293,7 @@ export const run = async ({
|
|||||||
await tx.documentAuditLog.create({
|
await tx.documentAuditLog.create({
|
||||||
data: createDocumentAuditLogData({
|
data: createDocumentAuditLogData({
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_COMPLETED,
|
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_COMPLETED,
|
||||||
documentId: document.id,
|
envelopeId: envelope.id,
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
user: null,
|
user: null,
|
||||||
data: {
|
data: {
|
||||||
@ -289,21 +308,23 @@ export const run = async ({
|
|||||||
await io.runTask('send-completed-email', async () => {
|
await io.runTask('send-completed-email', async () => {
|
||||||
let shouldSendCompletedEmail = sendEmail && !isResealing && !isRejected;
|
let shouldSendCompletedEmail = sendEmail && !isResealing && !isRejected;
|
||||||
|
|
||||||
if (isResealing && !isDocumentCompleted(document.status)) {
|
if (isResealing && !isDocumentCompleted(envelope.status)) {
|
||||||
shouldSendCompletedEmail = sendEmail;
|
shouldSendCompletedEmail = sendEmail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldSendCompletedEmail) {
|
if (shouldSendCompletedEmail) {
|
||||||
await sendCompletedEmail({ documentId, requestMetadata });
|
await sendCompletedEmail({
|
||||||
|
id: { type: 'envelopeId', id: envelope.id },
|
||||||
|
requestMetadata,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const updatedDocument = await prisma.document.findFirstOrThrow({
|
const updatedEnvelope = await prisma.envelope.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
id: document.id,
|
id: envelope.id,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
documentData: true,
|
|
||||||
documentMeta: true,
|
documentMeta: true,
|
||||||
recipients: true,
|
recipients: true,
|
||||||
},
|
},
|
||||||
@ -313,8 +334,8 @@ export const run = async ({
|
|||||||
event: isRejected
|
event: isRejected
|
||||||
? WebhookTriggerEvents.DOCUMENT_REJECTED
|
? WebhookTriggerEvents.DOCUMENT_REJECTED
|
||||||
: WebhookTriggerEvents.DOCUMENT_COMPLETED,
|
: WebhookTriggerEvents.DOCUMENT_COMPLETED,
|
||||||
data: ZWebhookDocumentSchema.parse(mapDocumentToWebhookDocumentPayload(updatedDocument)),
|
data: ZWebhookDocumentSchema.parse(mapEnvelopeToWebhookDocumentPayload(updatedEnvelope)),
|
||||||
userId: updatedDocument.userId,
|
userId: updatedEnvelope.userId,
|
||||||
teamId: updatedDocument.teamId ?? undefined,
|
teamId: updatedEnvelope.teamId ?? undefined,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,17 +1,21 @@
|
|||||||
import type { Prisma } from '@prisma/client';
|
import { EnvelopeType, type Prisma } from '@prisma/client';
|
||||||
|
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
import type { FindResultResponse } from '../../types/search-params';
|
import type { FindResultResponse } from '../../types/search-params';
|
||||||
|
|
||||||
export interface FindDocumentsOptions {
|
export interface AdminFindDocumentsOptions {
|
||||||
query?: string;
|
query?: string;
|
||||||
page?: number;
|
page?: number;
|
||||||
perPage?: number;
|
perPage?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const findDocuments = async ({ query, page = 1, perPage = 10 }: FindDocumentsOptions) => {
|
export const adminFindDocuments = async ({
|
||||||
const termFilters: Prisma.DocumentWhereInput | undefined = !query
|
query,
|
||||||
|
page = 1,
|
||||||
|
perPage = 10,
|
||||||
|
}: AdminFindDocumentsOptions) => {
|
||||||
|
const termFilters: Prisma.EnvelopeWhereInput | undefined = !query
|
||||||
? undefined
|
? undefined
|
||||||
: {
|
: {
|
||||||
title: {
|
title: {
|
||||||
@ -21,8 +25,9 @@ export const findDocuments = async ({ query, page = 1, perPage = 10 }: FindDocum
|
|||||||
};
|
};
|
||||||
|
|
||||||
const [data, count] = await Promise.all([
|
const [data, count] = await Promise.all([
|
||||||
prisma.document.findMany({
|
prisma.envelope.findMany({
|
||||||
where: {
|
where: {
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
...termFilters,
|
...termFilters,
|
||||||
},
|
},
|
||||||
skip: Math.max(page - 1, 0) * perPage,
|
skip: Math.max(page - 1, 0) * perPage,
|
||||||
@ -39,10 +44,17 @@ export const findDocuments = async ({ query, page = 1, perPage = 10 }: FindDocum
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
recipients: true,
|
recipients: true,
|
||||||
|
team: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
url: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
prisma.document.count({
|
prisma.envelope.count({
|
||||||
where: {
|
where: {
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
...termFilters,
|
...termFilters,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@ -17,15 +17,18 @@ import { createDocumentAuditLogData } from '../../utils/document-audit-logs';
|
|||||||
import { renderEmailWithI18N } from '../../utils/render-email-with-i18n';
|
import { renderEmailWithI18N } from '../../utils/render-email-with-i18n';
|
||||||
import { getEmailContext } from '../email/get-email-context';
|
import { getEmailContext } from '../email/get-email-context';
|
||||||
|
|
||||||
export type SuperDeleteDocumentOptions = {
|
export type AdminSuperDeleteDocumentOptions = {
|
||||||
id: number;
|
envelopeId: string;
|
||||||
requestMetadata?: RequestMetadata;
|
requestMetadata?: RequestMetadata;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const superDeleteDocument = async ({ id, requestMetadata }: SuperDeleteDocumentOptions) => {
|
export const adminSuperDeleteDocument = async ({
|
||||||
const document = await prisma.document.findUnique({
|
envelopeId,
|
||||||
|
requestMetadata,
|
||||||
|
}: AdminSuperDeleteDocumentOptions) => {
|
||||||
|
const envelope = await prisma.envelope.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id,
|
id: envelopeId,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
recipients: true,
|
recipients: true,
|
||||||
@ -40,7 +43,7 @@ export const superDeleteDocument = async ({ id, requestMetadata }: SuperDeleteDo
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!document) {
|
if (!envelope) {
|
||||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||||
message: 'Document not found',
|
message: 'Document not found',
|
||||||
});
|
});
|
||||||
@ -50,38 +53,38 @@ export const superDeleteDocument = async ({ id, requestMetadata }: SuperDeleteDo
|
|||||||
emailType: 'RECIPIENT',
|
emailType: 'RECIPIENT',
|
||||||
source: {
|
source: {
|
||||||
type: 'team',
|
type: 'team',
|
||||||
teamId: document.teamId,
|
teamId: envelope.teamId,
|
||||||
},
|
},
|
||||||
meta: document.documentMeta,
|
meta: envelope.documentMeta,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { status, user } = document;
|
const { status, user } = envelope;
|
||||||
|
|
||||||
const isDocumentDeletedEmailEnabled = extractDerivedDocumentEmailSettings(
|
const isDocumentDeletedEmailEnabled = extractDerivedDocumentEmailSettings(
|
||||||
document.documentMeta,
|
envelope.documentMeta,
|
||||||
).documentDeleted;
|
).documentDeleted;
|
||||||
|
|
||||||
// if the document is pending, send cancellation emails to all recipients
|
// if the document is pending, send cancellation emails to all recipients
|
||||||
if (
|
if (
|
||||||
status === DocumentStatus.PENDING &&
|
status === DocumentStatus.PENDING &&
|
||||||
document.recipients.length > 0 &&
|
envelope.recipients.length > 0 &&
|
||||||
isDocumentDeletedEmailEnabled
|
isDocumentDeletedEmailEnabled
|
||||||
) {
|
) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
document.recipients.map(async (recipient) => {
|
envelope.recipients.map(async (recipient) => {
|
||||||
if (recipient.sendStatus !== SendStatus.SENT) {
|
if (recipient.sendStatus !== SendStatus.SENT) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const assetBaseUrl = NEXT_PUBLIC_WEBAPP_URL() || 'http://localhost:3000';
|
const assetBaseUrl = NEXT_PUBLIC_WEBAPP_URL() || 'http://localhost:3000';
|
||||||
const template = createElement(DocumentCancelTemplate, {
|
const template = createElement(DocumentCancelTemplate, {
|
||||||
documentName: document.title,
|
documentName: envelope.title,
|
||||||
inviterName: user.name || undefined,
|
inviterName: user.name || undefined,
|
||||||
inviterEmail: user.email,
|
inviterEmail: user.email,
|
||||||
assetBaseUrl,
|
assetBaseUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
const lang = document.documentMeta?.language ?? settings.documentLanguage;
|
const lang = envelope.documentMeta?.language ?? settings.documentLanguage;
|
||||||
|
|
||||||
const [html, text] = await Promise.all([
|
const [html, text] = await Promise.all([
|
||||||
renderEmailWithI18N(template, { lang, branding }),
|
renderEmailWithI18N(template, { lang, branding }),
|
||||||
@ -113,7 +116,7 @@ export const superDeleteDocument = async ({ id, requestMetadata }: SuperDeleteDo
|
|||||||
return await prisma.$transaction(async (tx) => {
|
return await prisma.$transaction(async (tx) => {
|
||||||
await tx.documentAuditLog.create({
|
await tx.documentAuditLog.create({
|
||||||
data: createDocumentAuditLogData({
|
data: createDocumentAuditLogData({
|
||||||
documentId: id,
|
envelopeId,
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_DELETED,
|
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_DELETED,
|
||||||
user,
|
user,
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
@ -123,6 +126,6 @@ export const superDeleteDocument = async ({ id, requestMetadata }: SuperDeleteDo
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
return await tx.document.delete({ where: { id } });
|
return await tx.envelope.delete({ where: { id: envelopeId } });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -1,8 +1,13 @@
|
|||||||
|
import { EnvelopeType } from '@prisma/client';
|
||||||
|
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import { ExtendedDocumentStatus } from '@documenso/prisma/types/extended-document-status';
|
import { ExtendedDocumentStatus } from '@documenso/prisma/types/extended-document-status';
|
||||||
|
|
||||||
export const getDocumentStats = async () => {
|
export const getDocumentStats = async () => {
|
||||||
const counts = await prisma.document.groupBy({
|
const counts = await prisma.envelope.groupBy({
|
||||||
|
where: {
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
|
},
|
||||||
by: ['status'],
|
by: ['status'],
|
||||||
_count: {
|
_count: {
|
||||||
_all: true,
|
_all: true,
|
||||||
|
|||||||
@ -1,14 +1,22 @@
|
|||||||
|
import type { EnvelopeType } from '@prisma/client';
|
||||||
|
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
export type GetEntireDocumentOptions = {
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||||
id: number;
|
import type { EnvelopeIdOptions } from '../../utils/envelope';
|
||||||
|
import { unsafeBuildEnvelopeIdQuery } from '../../utils/envelope';
|
||||||
|
|
||||||
|
export type unsafeGetEntireEnvelopeOptions = {
|
||||||
|
id: EnvelopeIdOptions;
|
||||||
|
type: EnvelopeType;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getEntireDocument = async ({ id }: GetEntireDocumentOptions) => {
|
/**
|
||||||
const document = await prisma.document.findFirstOrThrow({
|
* An unauthenticated function that returns the whole envelope
|
||||||
where: {
|
*/
|
||||||
id,
|
export const unsafeGetEntireEnvelope = async ({ id, type }: unsafeGetEntireEnvelopeOptions) => {
|
||||||
},
|
const envelope = await prisma.envelope.findFirst({
|
||||||
|
where: unsafeBuildEnvelopeIdQuery(id, type),
|
||||||
include: {
|
include: {
|
||||||
documentMeta: true,
|
documentMeta: true,
|
||||||
user: {
|
user: {
|
||||||
@ -30,5 +38,11 @@ export const getEntireDocument = async ({ id }: GetEntireDocumentOptions) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return document;
|
if (!envelope) {
|
||||||
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||||
|
message: 'Envelope not found',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return envelope;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { DocumentStatus, SubscriptionStatus } from '@prisma/client';
|
import { DocumentStatus, EnvelopeType, SubscriptionStatus } from '@prisma/client';
|
||||||
|
|
||||||
import { kyselyPrisma, sql } from '@documenso/prisma';
|
import { kyselyPrisma, sql } from '@documenso/prisma';
|
||||||
|
|
||||||
@ -31,22 +31,23 @@ export async function getSigningVolume({
|
|||||||
.selectFrom('Subscription as s')
|
.selectFrom('Subscription as s')
|
||||||
.innerJoin('Organisation as o', 's.organisationId', 'o.id')
|
.innerJoin('Organisation as o', 's.organisationId', 'o.id')
|
||||||
.leftJoin('Team as t', 'o.id', 't.organisationId')
|
.leftJoin('Team as t', 'o.id', 't.organisationId')
|
||||||
.leftJoin('Document as d', (join) =>
|
.leftJoin('Envelope as e', (join) =>
|
||||||
join
|
join
|
||||||
.onRef('t.id', '=', 'd.teamId')
|
.onRef('t.id', '=', 'e.teamId')
|
||||||
.on('d.status', '=', sql.lit(DocumentStatus.COMPLETED))
|
.on('e.status', '=', sql.lit(DocumentStatus.COMPLETED))
|
||||||
.on('d.deletedAt', 'is', null),
|
.on('e.deletedAt', 'is', null),
|
||||||
)
|
)
|
||||||
.where(sql`s.status = ${SubscriptionStatus.ACTIVE}::"SubscriptionStatus"`)
|
.where(sql`s.status = ${SubscriptionStatus.ACTIVE}::"SubscriptionStatus"`)
|
||||||
.where((eb) =>
|
.where((eb) =>
|
||||||
eb.or([eb('o.name', 'ilike', `%${search}%`), eb('t.name', 'ilike', `%${search}%`)]),
|
eb.or([eb('o.name', 'ilike', `%${search}%`), eb('t.name', 'ilike', `%${search}%`)]),
|
||||||
)
|
)
|
||||||
|
.where('e.type', '=', EnvelopeType.DOCUMENT)
|
||||||
.select([
|
.select([
|
||||||
's.id as id',
|
's.id as id',
|
||||||
's.createdAt as createdAt',
|
's.createdAt as createdAt',
|
||||||
's.planId as planId',
|
's.planId as planId',
|
||||||
sql<string>`COALESCE(o.name, 'Unknown')`.as('name'),
|
sql<string>`COALESCE(o.name, 'Unknown')`.as('name'),
|
||||||
sql<number>`COUNT(DISTINCT d.id)`.as('signingVolume'),
|
sql<number>`COUNT(DISTINCT e.id)`.as('signingVolume'),
|
||||||
])
|
])
|
||||||
.groupBy(['s.id', 'o.name']);
|
.groupBy(['s.id', 'o.name']);
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,8 @@
|
|||||||
import type { DocumentDistributionMethod, DocumentSigningOrder } from '@prisma/client';
|
import {
|
||||||
|
type DocumentDistributionMethod,
|
||||||
|
type DocumentSigningOrder,
|
||||||
|
EnvelopeType,
|
||||||
|
} from '@prisma/client';
|
||||||
|
|
||||||
import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-logs';
|
import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-logs';
|
||||||
import type { ApiRequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
|
import type { ApiRequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
|
||||||
@ -11,16 +15,16 @@ import { prisma } from '@documenso/prisma';
|
|||||||
import type { SupportedLanguageCodes } from '../../constants/i18n';
|
import type { SupportedLanguageCodes } from '../../constants/i18n';
|
||||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||||
import type { TDocumentEmailSettings } from '../../types/document-email';
|
import type { TDocumentEmailSettings } from '../../types/document-email';
|
||||||
import { getDocumentWhereInput } from '../document/get-document-by-id';
|
import type { EnvelopeIdOptions } from '../../utils/envelope';
|
||||||
|
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||||
|
|
||||||
export type CreateDocumentMetaOptions = {
|
export type CreateDocumentMetaOptions = {
|
||||||
userId: number;
|
userId: number;
|
||||||
teamId: number;
|
teamId: number;
|
||||||
documentId: number;
|
id: EnvelopeIdOptions;
|
||||||
subject?: string;
|
subject?: string;
|
||||||
message?: string;
|
message?: string;
|
||||||
timezone?: string;
|
timezone?: string;
|
||||||
password?: string;
|
|
||||||
dateFormat?: string;
|
dateFormat?: string;
|
||||||
redirectUrl?: string;
|
redirectUrl?: string;
|
||||||
emailId?: string | null;
|
emailId?: string | null;
|
||||||
@ -36,15 +40,14 @@ export type CreateDocumentMetaOptions = {
|
|||||||
requestMetadata: ApiRequestMetadata;
|
requestMetadata: ApiRequestMetadata;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const upsertDocumentMeta = async ({
|
export const updateDocumentMeta = async ({
|
||||||
|
id,
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
subject,
|
subject,
|
||||||
message,
|
message,
|
||||||
timezone,
|
timezone,
|
||||||
dateFormat,
|
dateFormat,
|
||||||
documentId,
|
|
||||||
password,
|
|
||||||
redirectUrl,
|
redirectUrl,
|
||||||
signingOrder,
|
signingOrder,
|
||||||
allowDictateNextSigner,
|
allowDictateNextSigner,
|
||||||
@ -58,26 +61,27 @@ export const upsertDocumentMeta = async ({
|
|||||||
language,
|
language,
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
}: CreateDocumentMetaOptions) => {
|
}: CreateDocumentMetaOptions) => {
|
||||||
const { documentWhereInput, team } = await getDocumentWhereInput({
|
const { envelopeWhereInput, team } = await getEnvelopeWhereInput({
|
||||||
documentId,
|
id,
|
||||||
|
type: null, // Allow updating both documents and templates meta.
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const document = await prisma.document.findFirst({
|
const envelope = await prisma.envelope.findFirst({
|
||||||
where: documentWhereInput,
|
where: envelopeWhereInput,
|
||||||
include: {
|
include: {
|
||||||
documentMeta: true,
|
documentMeta: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!document) {
|
if (!envelope) {
|
||||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||||
message: 'Document not found',
|
message: 'Document not found',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const { documentMeta: originalDocumentMeta } = document;
|
const { documentMeta: originalDocumentMeta } = envelope;
|
||||||
|
|
||||||
// Validate the emailId belongs to the organisation.
|
// Validate the emailId belongs to the organisation.
|
||||||
if (emailId) {
|
if (emailId) {
|
||||||
@ -96,33 +100,13 @@ export const upsertDocumentMeta = async ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return await prisma.$transaction(async (tx) => {
|
return await prisma.$transaction(async (tx) => {
|
||||||
const upsertedDocumentMeta = await tx.documentMeta.upsert({
|
const upsertedDocumentMeta = await tx.documentMeta.update({
|
||||||
where: {
|
where: {
|
||||||
documentId,
|
id: envelope.documentMetaId,
|
||||||
},
|
},
|
||||||
create: {
|
data: {
|
||||||
subject,
|
subject,
|
||||||
message,
|
message,
|
||||||
password,
|
|
||||||
dateFormat,
|
|
||||||
timezone,
|
|
||||||
documentId,
|
|
||||||
redirectUrl,
|
|
||||||
signingOrder,
|
|
||||||
allowDictateNextSigner,
|
|
||||||
emailId,
|
|
||||||
emailReplyTo,
|
|
||||||
emailSettings,
|
|
||||||
distributionMethod,
|
|
||||||
typedSignatureEnabled,
|
|
||||||
uploadSignatureEnabled,
|
|
||||||
drawSignatureEnabled,
|
|
||||||
language,
|
|
||||||
},
|
|
||||||
update: {
|
|
||||||
subject,
|
|
||||||
message,
|
|
||||||
password,
|
|
||||||
dateFormat,
|
dateFormat,
|
||||||
timezone,
|
timezone,
|
||||||
redirectUrl,
|
redirectUrl,
|
||||||
@ -141,11 +125,12 @@ export const upsertDocumentMeta = async ({
|
|||||||
|
|
||||||
const changes = diffDocumentMetaChanges(originalDocumentMeta ?? {}, upsertedDocumentMeta);
|
const changes = diffDocumentMetaChanges(originalDocumentMeta ?? {}, upsertedDocumentMeta);
|
||||||
|
|
||||||
if (changes.length > 0) {
|
// Create audit logs only for document type envelopes.
|
||||||
|
if (changes.length > 0 && envelope.type === EnvelopeType.DOCUMENT) {
|
||||||
await tx.documentAuditLog.create({
|
await tx.documentAuditLog.create({
|
||||||
data: createDocumentAuditLogData({
|
data: createDocumentAuditLogData({
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_META_UPDATED,
|
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_META_UPDATED,
|
||||||
documentId,
|
envelopeId: envelope.id,
|
||||||
metadata: requestMetadata,
|
metadata: requestMetadata,
|
||||||
data: {
|
data: {
|
||||||
changes: diffDocumentMetaChanges(originalDocumentMeta ?? {}, upsertedDocumentMeta),
|
changes: diffDocumentMetaChanges(originalDocumentMeta ?? {}, upsertedDocumentMeta),
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
DocumentSigningOrder,
|
DocumentSigningOrder,
|
||||||
DocumentStatus,
|
DocumentStatus,
|
||||||
|
EnvelopeType,
|
||||||
RecipientRole,
|
RecipientRole,
|
||||||
SendStatus,
|
SendStatus,
|
||||||
SigningStatus,
|
SigningStatus,
|
||||||
@ -22,9 +23,11 @@ import type { TRecipientAccessAuth, TRecipientActionAuth } from '../../types/doc
|
|||||||
import { DocumentAuth } from '../../types/document-auth';
|
import { DocumentAuth } from '../../types/document-auth';
|
||||||
import {
|
import {
|
||||||
ZWebhookDocumentSchema,
|
ZWebhookDocumentSchema,
|
||||||
mapDocumentToWebhookDocumentPayload,
|
mapEnvelopeToWebhookDocumentPayload,
|
||||||
} from '../../types/webhook-payload';
|
} from '../../types/webhook-payload';
|
||||||
import { extractDocumentAuthMethods } from '../../utils/document-auth';
|
import { extractDocumentAuthMethods } from '../../utils/document-auth';
|
||||||
|
import type { EnvelopeIdOptions } from '../../utils/envelope';
|
||||||
|
import { mapSecondaryIdToDocumentId, unsafeBuildEnvelopeIdQuery } from '../../utils/envelope';
|
||||||
import { getIsRecipientsTurnToSign } from '../recipient/get-is-recipient-turn';
|
import { getIsRecipientsTurnToSign } from '../recipient/get-is-recipient-turn';
|
||||||
import { triggerWebhook } from '../webhooks/trigger/trigger-webhook';
|
import { triggerWebhook } from '../webhooks/trigger/trigger-webhook';
|
||||||
import { isRecipientAuthorized } from './is-recipient-authorized';
|
import { isRecipientAuthorized } from './is-recipient-authorized';
|
||||||
@ -32,7 +35,7 @@ import { sendPendingEmail } from './send-pending-email';
|
|||||||
|
|
||||||
export type CompleteDocumentWithTokenOptions = {
|
export type CompleteDocumentWithTokenOptions = {
|
||||||
token: string;
|
token: string;
|
||||||
documentId: number;
|
id: EnvelopeIdOptions;
|
||||||
userId?: number;
|
userId?: number;
|
||||||
authOptions?: TRecipientActionAuth;
|
authOptions?: TRecipientActionAuth;
|
||||||
accessAuthOptions?: TRecipientAccessAuth;
|
accessAuthOptions?: TRecipientAccessAuth;
|
||||||
@ -43,10 +46,17 @@ export type CompleteDocumentWithTokenOptions = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const getDocument = async ({ token, documentId }: CompleteDocumentWithTokenOptions) => {
|
export const completeDocumentWithToken = async ({
|
||||||
return await prisma.document.findFirstOrThrow({
|
token,
|
||||||
|
id,
|
||||||
|
userId,
|
||||||
|
accessAuthOptions,
|
||||||
|
requestMetadata,
|
||||||
|
nextSigner,
|
||||||
|
}: CompleteDocumentWithTokenOptions) => {
|
||||||
|
const envelope = await prisma.envelope.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
id: documentId,
|
...unsafeBuildEnvelopeIdQuery(id, EnvelopeType.DOCUMENT),
|
||||||
recipients: {
|
recipients: {
|
||||||
some: {
|
some: {
|
||||||
token,
|
token,
|
||||||
@ -62,27 +72,18 @@ const getDocument = async ({ token, documentId }: CompleteDocumentWithTokenOptio
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
export const completeDocumentWithToken = async ({
|
const legacyDocumentId = mapSecondaryIdToDocumentId(envelope.secondaryId);
|
||||||
token,
|
|
||||||
documentId,
|
|
||||||
userId,
|
|
||||||
accessAuthOptions,
|
|
||||||
requestMetadata,
|
|
||||||
nextSigner,
|
|
||||||
}: CompleteDocumentWithTokenOptions) => {
|
|
||||||
const document = await getDocument({ token, documentId });
|
|
||||||
|
|
||||||
if (document.status !== DocumentStatus.PENDING) {
|
if (envelope.status !== DocumentStatus.PENDING) {
|
||||||
throw new Error(`Document ${document.id} must be pending`);
|
throw new Error(`Document ${envelope.id} must be pending`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document.recipients.length === 0) {
|
if (envelope.recipients.length === 0) {
|
||||||
throw new Error(`Document ${document.id} has no recipient with token ${token}`);
|
throw new Error(`Document ${envelope.id} has no recipient with token ${token}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const [recipient] = document.recipients;
|
const [recipient] = envelope.recipients;
|
||||||
|
|
||||||
if (recipient.signingStatus === SigningStatus.SIGNED) {
|
if (recipient.signingStatus === SigningStatus.SIGNED) {
|
||||||
throw new Error(`Recipient ${recipient.id} has already signed`);
|
throw new Error(`Recipient ${recipient.id} has already signed`);
|
||||||
@ -95,7 +96,7 @@ export const completeDocumentWithToken = async ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document.documentMeta?.signingOrder === DocumentSigningOrder.SEQUENTIAL) {
|
if (envelope.documentMeta?.signingOrder === DocumentSigningOrder.SEQUENTIAL) {
|
||||||
const isRecipientsTurn = await getIsRecipientsTurnToSign({ token: recipient.token });
|
const isRecipientsTurn = await getIsRecipientsTurnToSign({ token: recipient.token });
|
||||||
|
|
||||||
if (!isRecipientsTurn) {
|
if (!isRecipientsTurn) {
|
||||||
@ -107,7 +108,7 @@ export const completeDocumentWithToken = async ({
|
|||||||
|
|
||||||
const fields = await prisma.field.findMany({
|
const fields = await prisma.field.findMany({
|
||||||
where: {
|
where: {
|
||||||
documentId: document.id,
|
envelopeId: envelope.id, // Todo: Envelopes - Need to support multi docs.
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -118,7 +119,7 @@ export const completeDocumentWithToken = async ({
|
|||||||
|
|
||||||
// Check ACCESS AUTH 2FA validation during document completion
|
// Check ACCESS AUTH 2FA validation during document completion
|
||||||
const { derivedRecipientAccessAuth } = extractDocumentAuthMethods({
|
const { derivedRecipientAccessAuth } = extractDocumentAuthMethods({
|
||||||
documentAuth: document.authOptions,
|
documentAuth: envelope.authOptions,
|
||||||
recipientAuth: recipient.authOptions,
|
recipientAuth: recipient.authOptions,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -131,7 +132,7 @@ export const completeDocumentWithToken = async ({
|
|||||||
|
|
||||||
const isValid = await isRecipientAuthorized({
|
const isValid = await isRecipientAuthorized({
|
||||||
type: 'ACCESS_2FA',
|
type: 'ACCESS_2FA',
|
||||||
documentAuthOptions: document.authOptions,
|
documentAuthOptions: envelope.authOptions,
|
||||||
recipient: recipient,
|
recipient: recipient,
|
||||||
userId, // Can be undefined for non-account recipients
|
userId, // Can be undefined for non-account recipients
|
||||||
authOptions: accessAuthOptions,
|
authOptions: accessAuthOptions,
|
||||||
@ -141,7 +142,7 @@ export const completeDocumentWithToken = async ({
|
|||||||
await prisma.documentAuditLog.create({
|
await prisma.documentAuditLog.create({
|
||||||
data: createDocumentAuditLogData({
|
data: createDocumentAuditLogData({
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_ACCESS_AUTH_2FA_FAILED,
|
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_ACCESS_AUTH_2FA_FAILED,
|
||||||
documentId: document.id,
|
envelopeId: envelope.id,
|
||||||
data: {
|
data: {
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
recipientName: recipient.name,
|
recipientName: recipient.name,
|
||||||
@ -158,7 +159,7 @@ export const completeDocumentWithToken = async ({
|
|||||||
await prisma.documentAuditLog.create({
|
await prisma.documentAuditLog.create({
|
||||||
data: createDocumentAuditLogData({
|
data: createDocumentAuditLogData({
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_ACCESS_AUTH_2FA_VALIDATED,
|
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_ACCESS_AUTH_2FA_VALIDATED,
|
||||||
documentId: document.id,
|
envelopeId: envelope.id,
|
||||||
data: {
|
data: {
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
recipientName: recipient.name,
|
recipientName: recipient.name,
|
||||||
@ -180,14 +181,14 @@ export const completeDocumentWithToken = async ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const authOptions = extractDocumentAuthMethods({
|
const authOptions = extractDocumentAuthMethods({
|
||||||
documentAuth: document.authOptions,
|
documentAuth: envelope.authOptions,
|
||||||
recipientAuth: recipient.authOptions,
|
recipientAuth: recipient.authOptions,
|
||||||
});
|
});
|
||||||
|
|
||||||
await tx.documentAuditLog.create({
|
await tx.documentAuditLog.create({
|
||||||
data: createDocumentAuditLogData({
|
data: createDocumentAuditLogData({
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_COMPLETED,
|
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_COMPLETED,
|
||||||
documentId: document.id,
|
envelopeId: envelope.id,
|
||||||
user: {
|
user: {
|
||||||
name: recipient.name,
|
name: recipient.name,
|
||||||
email: recipient.email,
|
email: recipient.email,
|
||||||
@ -207,7 +208,7 @@ export const completeDocumentWithToken = async ({
|
|||||||
await jobs.triggerJob({
|
await jobs.triggerJob({
|
||||||
name: 'send.recipient.signed.email',
|
name: 'send.recipient.signed.email',
|
||||||
payload: {
|
payload: {
|
||||||
documentId: document.id,
|
documentId: legacyDocumentId,
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -221,7 +222,7 @@ export const completeDocumentWithToken = async ({
|
|||||||
role: true,
|
role: true,
|
||||||
},
|
},
|
||||||
where: {
|
where: {
|
||||||
documentId: document.id,
|
envelopeId: envelope.id,
|
||||||
signingStatus: {
|
signingStatus: {
|
||||||
not: SigningStatus.SIGNED,
|
not: SigningStatus.SIGNED,
|
||||||
},
|
},
|
||||||
@ -235,17 +236,17 @@ export const completeDocumentWithToken = async ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (pendingRecipients.length > 0) {
|
if (pendingRecipients.length > 0) {
|
||||||
await sendPendingEmail({ documentId, recipientId: recipient.id });
|
await sendPendingEmail({ id, recipientId: recipient.id });
|
||||||
|
|
||||||
if (document.documentMeta?.signingOrder === DocumentSigningOrder.SEQUENTIAL) {
|
if (envelope.documentMeta?.signingOrder === DocumentSigningOrder.SEQUENTIAL) {
|
||||||
const [nextRecipient] = pendingRecipients;
|
const [nextRecipient] = pendingRecipients;
|
||||||
|
|
||||||
await prisma.$transaction(async (tx) => {
|
await prisma.$transaction(async (tx) => {
|
||||||
if (nextSigner && document.documentMeta?.allowDictateNextSigner) {
|
if (nextSigner && envelope.documentMeta?.allowDictateNextSigner) {
|
||||||
await tx.documentAuditLog.create({
|
await tx.documentAuditLog.create({
|
||||||
data: createDocumentAuditLogData({
|
data: createDocumentAuditLogData({
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.RECIPIENT_UPDATED,
|
type: DOCUMENT_AUDIT_LOG_TYPE.RECIPIENT_UPDATED,
|
||||||
documentId: document.id,
|
envelopeId: envelope.id,
|
||||||
user: {
|
user: {
|
||||||
name: recipient.name,
|
name: recipient.name,
|
||||||
email: recipient.email,
|
email: recipient.email,
|
||||||
@ -277,7 +278,7 @@ export const completeDocumentWithToken = async ({
|
|||||||
where: { id: nextRecipient.id },
|
where: { id: nextRecipient.id },
|
||||||
data: {
|
data: {
|
||||||
sendStatus: SendStatus.SENT,
|
sendStatus: SendStatus.SENT,
|
||||||
...(nextSigner && document.documentMeta?.allowDictateNextSigner
|
...(nextSigner && envelope.documentMeta?.allowDictateNextSigner
|
||||||
? {
|
? {
|
||||||
name: nextSigner.name,
|
name: nextSigner.name,
|
||||||
email: nextSigner.email,
|
email: nextSigner.email,
|
||||||
@ -289,8 +290,8 @@ export const completeDocumentWithToken = async ({
|
|||||||
await jobs.triggerJob({
|
await jobs.triggerJob({
|
||||||
name: 'send.signing.requested.email',
|
name: 'send.signing.requested.email',
|
||||||
payload: {
|
payload: {
|
||||||
userId: document.userId,
|
userId: envelope.userId,
|
||||||
documentId: document.id,
|
documentId: legacyDocumentId,
|
||||||
recipientId: nextRecipient.id,
|
recipientId: nextRecipient.id,
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
},
|
},
|
||||||
@ -299,9 +300,9 @@ export const completeDocumentWithToken = async ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const haveAllRecipientsSigned = await prisma.document.findFirst({
|
const haveAllRecipientsSigned = await prisma.envelope.findFirst({
|
||||||
where: {
|
where: {
|
||||||
id: document.id,
|
id: envelope.id,
|
||||||
recipients: {
|
recipients: {
|
||||||
every: {
|
every: {
|
||||||
OR: [{ signingStatus: SigningStatus.SIGNED }, { role: RecipientRole.CC }],
|
OR: [{ signingStatus: SigningStatus.SIGNED }, { role: RecipientRole.CC }],
|
||||||
@ -314,15 +315,16 @@ export const completeDocumentWithToken = async ({
|
|||||||
await jobs.triggerJob({
|
await jobs.triggerJob({
|
||||||
name: 'internal.seal-document',
|
name: 'internal.seal-document',
|
||||||
payload: {
|
payload: {
|
||||||
documentId: document.id,
|
documentId: legacyDocumentId,
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedDocument = await prisma.document.findFirstOrThrow({
|
const updatedDocument = await prisma.envelope.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
id: document.id,
|
id: envelope.id,
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
documentMeta: true,
|
documentMeta: true,
|
||||||
@ -332,7 +334,7 @@ export const completeDocumentWithToken = async ({
|
|||||||
|
|
||||||
await triggerWebhook({
|
await triggerWebhook({
|
||||||
event: WebhookTriggerEvents.DOCUMENT_SIGNED,
|
event: WebhookTriggerEvents.DOCUMENT_SIGNED,
|
||||||
data: ZWebhookDocumentSchema.parse(mapDocumentToWebhookDocumentPayload(updatedDocument)),
|
data: ZWebhookDocumentSchema.parse(mapEnvelopeToWebhookDocumentPayload(updatedDocument)),
|
||||||
userId: updatedDocument.userId,
|
userId: updatedDocument.userId,
|
||||||
teamId: updatedDocument.teamId ?? undefined,
|
teamId: updatedDocument.teamId ?? undefined,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,171 +0,0 @@
|
|||||||
import { DocumentSource, WebhookTriggerEvents } from '@prisma/client';
|
|
||||||
import type { DocumentVisibility } from '@prisma/client';
|
|
||||||
|
|
||||||
import { normalizePdf as makeNormalizedPdf } from '@documenso/lib/server-only/pdf/normalize-pdf';
|
|
||||||
import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-logs';
|
|
||||||
import type { ApiRequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
|
|
||||||
import { createDocumentAuditLogData } from '@documenso/lib/utils/document-audit-logs';
|
|
||||||
import { prisma } from '@documenso/prisma';
|
|
||||||
|
|
||||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
|
||||||
import {
|
|
||||||
ZWebhookDocumentSchema,
|
|
||||||
mapDocumentToWebhookDocumentPayload,
|
|
||||||
} from '../../types/webhook-payload';
|
|
||||||
import { prefixedId } from '../../universal/id';
|
|
||||||
import { getFileServerSide } from '../../universal/upload/get-file.server';
|
|
||||||
import { putPdfFileServerSide } from '../../universal/upload/put-file.server';
|
|
||||||
import { extractDerivedDocumentMeta } from '../../utils/document';
|
|
||||||
import { determineDocumentVisibility } from '../../utils/document-visibility';
|
|
||||||
import { buildTeamWhereQuery } from '../../utils/teams';
|
|
||||||
import { getTeamById } from '../team/get-team';
|
|
||||||
import { getTeamSettings } from '../team/get-team-settings';
|
|
||||||
import { triggerWebhook } from '../webhooks/trigger/trigger-webhook';
|
|
||||||
|
|
||||||
export type CreateDocumentOptions = {
|
|
||||||
title: string;
|
|
||||||
externalId?: string | null;
|
|
||||||
userId: number;
|
|
||||||
teamId: number;
|
|
||||||
documentDataId: string;
|
|
||||||
formValues?: Record<string, string | number | boolean>;
|
|
||||||
normalizePdf?: boolean;
|
|
||||||
timezone?: string;
|
|
||||||
userTimezone?: string;
|
|
||||||
requestMetadata: ApiRequestMetadata;
|
|
||||||
folderId?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const createDocument = async ({
|
|
||||||
userId,
|
|
||||||
title,
|
|
||||||
externalId,
|
|
||||||
documentDataId,
|
|
||||||
teamId,
|
|
||||||
normalizePdf,
|
|
||||||
formValues,
|
|
||||||
requestMetadata,
|
|
||||||
timezone,
|
|
||||||
userTimezone,
|
|
||||||
folderId,
|
|
||||||
}: CreateDocumentOptions) => {
|
|
||||||
const team = await getTeamById({ userId, teamId });
|
|
||||||
|
|
||||||
const settings = await getTeamSettings({
|
|
||||||
userId,
|
|
||||||
teamId,
|
|
||||||
});
|
|
||||||
|
|
||||||
let folderVisibility: DocumentVisibility | undefined;
|
|
||||||
|
|
||||||
if (folderId) {
|
|
||||||
const folder = await prisma.folder.findFirst({
|
|
||||||
where: {
|
|
||||||
id: folderId,
|
|
||||||
team: buildTeamWhereQuery({
|
|
||||||
teamId,
|
|
||||||
userId,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
visibility: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!folder) {
|
|
||||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
|
||||||
message: 'Folder not found',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
folderVisibility = folder.visibility;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (normalizePdf) {
|
|
||||||
const documentData = await prisma.documentData.findFirst({
|
|
||||||
where: {
|
|
||||||
id: documentDataId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (documentData) {
|
|
||||||
const buffer = await getFileServerSide(documentData);
|
|
||||||
|
|
||||||
const normalizedPdf = await makeNormalizedPdf(Buffer.from(buffer));
|
|
||||||
|
|
||||||
const newDocumentData = await putPdfFileServerSide({
|
|
||||||
name: title.endsWith('.pdf') ? title : `${title}.pdf`,
|
|
||||||
type: 'application/pdf',
|
|
||||||
arrayBuffer: async () => Promise.resolve(normalizedPdf),
|
|
||||||
});
|
|
||||||
|
|
||||||
// eslint-disable-next-line require-atomic-updates
|
|
||||||
documentDataId = newDocumentData.id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// userTimezone is last because it's always passed in regardless of the organisation/team settings
|
|
||||||
// for uploads from the frontend
|
|
||||||
const timezoneToUse = timezone || settings.documentTimezone || userTimezone;
|
|
||||||
|
|
||||||
return await prisma.$transaction(async (tx) => {
|
|
||||||
const document = await tx.document.create({
|
|
||||||
data: {
|
|
||||||
title,
|
|
||||||
qrToken: prefixedId('qr'),
|
|
||||||
externalId,
|
|
||||||
documentDataId,
|
|
||||||
userId,
|
|
||||||
teamId,
|
|
||||||
folderId,
|
|
||||||
visibility:
|
|
||||||
folderVisibility ??
|
|
||||||
determineDocumentVisibility(settings.documentVisibility, team.currentTeamRole),
|
|
||||||
formValues,
|
|
||||||
source: DocumentSource.DOCUMENT,
|
|
||||||
documentMeta: {
|
|
||||||
create: extractDerivedDocumentMeta(settings, {
|
|
||||||
timezone: timezoneToUse,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await tx.documentAuditLog.create({
|
|
||||||
data: createDocumentAuditLogData({
|
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_CREATED,
|
|
||||||
documentId: document.id,
|
|
||||||
metadata: requestMetadata,
|
|
||||||
data: {
|
|
||||||
title,
|
|
||||||
source: {
|
|
||||||
type: DocumentSource.DOCUMENT,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const createdDocument = await tx.document.findFirst({
|
|
||||||
where: {
|
|
||||||
id: document.id,
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
documentMeta: true,
|
|
||||||
recipients: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!createdDocument) {
|
|
||||||
throw new Error('Document not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
await triggerWebhook({
|
|
||||||
event: WebhookTriggerEvents.DOCUMENT_CREATED,
|
|
||||||
data: ZWebhookDocumentSchema.parse(mapDocumentToWebhookDocumentPayload(createdDocument)),
|
|
||||||
userId,
|
|
||||||
teamId,
|
|
||||||
});
|
|
||||||
|
|
||||||
return createdDocument;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
@ -1,8 +1,8 @@
|
|||||||
import { createElement } from 'react';
|
import { createElement } from 'react';
|
||||||
|
|
||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import type { Document, DocumentMeta, Recipient, User } from '@prisma/client';
|
import type { DocumentMeta, Envelope, Recipient, User } from '@prisma/client';
|
||||||
import { DocumentStatus, SendStatus, WebhookTriggerEvents } from '@prisma/client';
|
import { DocumentStatus, EnvelopeType, SendStatus, WebhookTriggerEvents } from '@prisma/client';
|
||||||
|
|
||||||
import { mailer } from '@documenso/email/mailer';
|
import { mailer } from '@documenso/email/mailer';
|
||||||
import DocumentCancelTemplate from '@documenso/email/templates/document-cancel';
|
import DocumentCancelTemplate from '@documenso/email/templates/document-cancel';
|
||||||
@ -15,11 +15,12 @@ import { DOCUMENT_AUDIT_LOG_TYPE } from '../../types/document-audit-logs';
|
|||||||
import { extractDerivedDocumentEmailSettings } from '../../types/document-email';
|
import { extractDerivedDocumentEmailSettings } from '../../types/document-email';
|
||||||
import {
|
import {
|
||||||
ZWebhookDocumentSchema,
|
ZWebhookDocumentSchema,
|
||||||
mapDocumentToWebhookDocumentPayload,
|
mapEnvelopeToWebhookDocumentPayload,
|
||||||
} from '../../types/webhook-payload';
|
} from '../../types/webhook-payload';
|
||||||
import type { ApiRequestMetadata } from '../../universal/extract-request-metadata';
|
import type { ApiRequestMetadata } from '../../universal/extract-request-metadata';
|
||||||
import { isDocumentCompleted } from '../../utils/document';
|
import { isDocumentCompleted } from '../../utils/document';
|
||||||
import { createDocumentAuditLogData } from '../../utils/document-audit-logs';
|
import { createDocumentAuditLogData } from '../../utils/document-audit-logs';
|
||||||
|
import { unsafeBuildEnvelopeIdQuery } from '../../utils/envelope';
|
||||||
import { renderEmailWithI18N } from '../../utils/render-email-with-i18n';
|
import { renderEmailWithI18N } from '../../utils/render-email-with-i18n';
|
||||||
import { getEmailContext } from '../email/get-email-context';
|
import { getEmailContext } from '../email/get-email-context';
|
||||||
import { getMemberRoles } from '../team/get-member-roles';
|
import { getMemberRoles } from '../team/get-member-roles';
|
||||||
@ -50,24 +51,23 @@ export const deleteDocument = async ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const document = await prisma.document.findUnique({
|
// Note: This is an unsafe request, we validate the ownership later in the function.
|
||||||
where: {
|
const envelope = await prisma.envelope.findUnique({
|
||||||
id,
|
where: unsafeBuildEnvelopeIdQuery({ type: 'documentId', id }, EnvelopeType.DOCUMENT),
|
||||||
},
|
|
||||||
include: {
|
include: {
|
||||||
recipients: true,
|
recipients: true,
|
||||||
documentMeta: true,
|
documentMeta: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!document) {
|
if (!envelope) {
|
||||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||||
message: 'Document not found',
|
message: 'Document not found',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const isUserTeamMember = await getMemberRoles({
|
const isUserTeamMember = await getMemberRoles({
|
||||||
teamId: document.teamId,
|
teamId: envelope.teamId,
|
||||||
reference: {
|
reference: {
|
||||||
type: 'User',
|
type: 'User',
|
||||||
id: userId,
|
id: userId,
|
||||||
@ -76,8 +76,8 @@ export const deleteDocument = async ({
|
|||||||
.then(() => true)
|
.then(() => true)
|
||||||
.catch(() => false);
|
.catch(() => false);
|
||||||
|
|
||||||
const isUserOwner = document.userId === userId;
|
const isUserOwner = envelope.userId === userId;
|
||||||
const userRecipient = document.recipients.find((recipient) => recipient.email === user.email);
|
const userRecipient = envelope.recipients.find((recipient) => recipient.email === user.email);
|
||||||
|
|
||||||
if (!isUserOwner && !isUserTeamMember && !userRecipient) {
|
if (!isUserOwner && !isUserTeamMember && !userRecipient) {
|
||||||
throw new AppError(AppErrorCode.UNAUTHORIZED, {
|
throw new AppError(AppErrorCode.UNAUTHORIZED, {
|
||||||
@ -88,7 +88,7 @@ export const deleteDocument = async ({
|
|||||||
// Handle hard or soft deleting the actual document if user has permission.
|
// Handle hard or soft deleting the actual document if user has permission.
|
||||||
if (isUserOwner || isUserTeamMember) {
|
if (isUserOwner || isUserTeamMember) {
|
||||||
await handleDocumentOwnerDelete({
|
await handleDocumentOwnerDelete({
|
||||||
document,
|
envelope,
|
||||||
user,
|
user,
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
});
|
});
|
||||||
@ -113,27 +113,16 @@ export const deleteDocument = async ({
|
|||||||
|
|
||||||
await triggerWebhook({
|
await triggerWebhook({
|
||||||
event: WebhookTriggerEvents.DOCUMENT_CANCELLED,
|
event: WebhookTriggerEvents.DOCUMENT_CANCELLED,
|
||||||
data: ZWebhookDocumentSchema.parse(mapDocumentToWebhookDocumentPayload(document)),
|
data: ZWebhookDocumentSchema.parse(mapEnvelopeToWebhookDocumentPayload(envelope)),
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Return partial document for API v1 response.
|
return envelope;
|
||||||
return {
|
|
||||||
id: document.id,
|
|
||||||
userId: document.userId,
|
|
||||||
teamId: document.teamId,
|
|
||||||
title: document.title,
|
|
||||||
status: document.status,
|
|
||||||
documentDataId: document.documentDataId,
|
|
||||||
createdAt: document.createdAt,
|
|
||||||
updatedAt: document.updatedAt,
|
|
||||||
completedAt: document.completedAt,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type HandleDocumentOwnerDeleteOptions = {
|
type HandleDocumentOwnerDeleteOptions = {
|
||||||
document: Document & {
|
envelope: Envelope & {
|
||||||
recipients: Recipient[];
|
recipients: Recipient[];
|
||||||
documentMeta: DocumentMeta | null;
|
documentMeta: DocumentMeta | null;
|
||||||
};
|
};
|
||||||
@ -142,11 +131,11 @@ type HandleDocumentOwnerDeleteOptions = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleDocumentOwnerDelete = async ({
|
const handleDocumentOwnerDelete = async ({
|
||||||
document,
|
envelope,
|
||||||
user,
|
user,
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
}: HandleDocumentOwnerDeleteOptions) => {
|
}: HandleDocumentOwnerDeleteOptions) => {
|
||||||
if (document.deletedAt) {
|
if (envelope.deletedAt) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,17 +143,17 @@ const handleDocumentOwnerDelete = async ({
|
|||||||
emailType: 'RECIPIENT',
|
emailType: 'RECIPIENT',
|
||||||
source: {
|
source: {
|
||||||
type: 'team',
|
type: 'team',
|
||||||
teamId: document.teamId,
|
teamId: envelope.teamId,
|
||||||
},
|
},
|
||||||
meta: document.documentMeta,
|
meta: envelope.documentMeta,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Soft delete completed documents.
|
// Soft delete completed documents.
|
||||||
if (isDocumentCompleted(document.status)) {
|
if (isDocumentCompleted(envelope.status)) {
|
||||||
return await prisma.$transaction(async (tx) => {
|
return await prisma.$transaction(async (tx) => {
|
||||||
await tx.documentAuditLog.create({
|
await tx.documentAuditLog.create({
|
||||||
data: createDocumentAuditLogData({
|
data: createDocumentAuditLogData({
|
||||||
documentId: document.id,
|
envelopeId: envelope.id,
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_DELETED,
|
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_DELETED,
|
||||||
metadata: requestMetadata,
|
metadata: requestMetadata,
|
||||||
data: {
|
data: {
|
||||||
@ -173,9 +162,9 @@ const handleDocumentOwnerDelete = async ({
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
return await tx.document.update({
|
return await tx.envelope.update({
|
||||||
where: {
|
where: {
|
||||||
id: document.id,
|
id: envelope.id,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
deletedAt: new Date().toISOString(),
|
deletedAt: new Date().toISOString(),
|
||||||
@ -185,12 +174,12 @@ const handleDocumentOwnerDelete = async ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Hard delete draft and pending documents.
|
// Hard delete draft and pending documents.
|
||||||
const deletedDocument = await prisma.$transaction(async (tx) => {
|
const deletedEnvelope = await prisma.$transaction(async (tx) => {
|
||||||
// Currently redundant since deleting a document will delete the audit logs.
|
// Currently redundant since deleting a document will delete the audit logs.
|
||||||
// However may be useful if we disassociate audit logs and documents if required.
|
// However may be useful if we disassociate audit logs and documents if required.
|
||||||
await tx.documentAuditLog.create({
|
await tx.documentAuditLog.create({
|
||||||
data: createDocumentAuditLogData({
|
data: createDocumentAuditLogData({
|
||||||
documentId: document.id,
|
envelopeId: envelope.id,
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_DELETED,
|
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_DELETED,
|
||||||
metadata: requestMetadata,
|
metadata: requestMetadata,
|
||||||
data: {
|
data: {
|
||||||
@ -199,9 +188,9 @@ const handleDocumentOwnerDelete = async ({
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
return await tx.document.delete({
|
return await tx.envelope.delete({
|
||||||
where: {
|
where: {
|
||||||
id: document.id,
|
id: envelope.id,
|
||||||
status: {
|
status: {
|
||||||
not: DocumentStatus.COMPLETED,
|
not: DocumentStatus.COMPLETED,
|
||||||
},
|
},
|
||||||
@ -209,17 +198,17 @@ const handleDocumentOwnerDelete = async ({
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const isDocumentDeleteEmailEnabled = extractDerivedDocumentEmailSettings(
|
const isEnvelopeDeleteEmailEnabled = extractDerivedDocumentEmailSettings(
|
||||||
document.documentMeta,
|
envelope.documentMeta,
|
||||||
).documentDeleted;
|
).documentDeleted;
|
||||||
|
|
||||||
if (!isDocumentDeleteEmailEnabled) {
|
if (!isEnvelopeDeleteEmailEnabled) {
|
||||||
return deletedDocument;
|
return deletedEnvelope;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send cancellation emails to recipients.
|
// Send cancellation emails to recipients.
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
document.recipients.map(async (recipient) => {
|
envelope.recipients.map(async (recipient) => {
|
||||||
if (recipient.sendStatus !== SendStatus.SENT) {
|
if (recipient.sendStatus !== SendStatus.SENT) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -227,7 +216,7 @@ const handleDocumentOwnerDelete = async ({
|
|||||||
const assetBaseUrl = NEXT_PUBLIC_WEBAPP_URL() || 'http://localhost:3000';
|
const assetBaseUrl = NEXT_PUBLIC_WEBAPP_URL() || 'http://localhost:3000';
|
||||||
|
|
||||||
const template = createElement(DocumentCancelTemplate, {
|
const template = createElement(DocumentCancelTemplate, {
|
||||||
documentName: document.title,
|
documentName: envelope.title,
|
||||||
inviterName: user.name || undefined,
|
inviterName: user.name || undefined,
|
||||||
inviterEmail: user.email,
|
inviterEmail: user.email,
|
||||||
assetBaseUrl,
|
assetBaseUrl,
|
||||||
@ -258,5 +247,5 @@ const handleDocumentOwnerDelete = async ({
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
return deletedDocument;
|
return deletedEnvelope;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import type { Prisma, Recipient } from '@prisma/client';
|
import type { Recipient } from '@prisma/client';
|
||||||
import { DocumentSource, WebhookTriggerEvents } from '@prisma/client';
|
import { DocumentSource, EnvelopeType, WebhookTriggerEvents } from '@prisma/client';
|
||||||
import { omit } from 'remeda';
|
import { omit } from 'remeda';
|
||||||
|
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
@ -7,39 +7,42 @@ import { prisma } from '@documenso/prisma';
|
|||||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||||
import {
|
import {
|
||||||
ZWebhookDocumentSchema,
|
ZWebhookDocumentSchema,
|
||||||
mapDocumentToWebhookDocumentPayload,
|
mapEnvelopeToWebhookDocumentPayload,
|
||||||
} from '../../types/webhook-payload';
|
} from '../../types/webhook-payload';
|
||||||
import { nanoid, prefixedId } from '../../universal/id';
|
import { nanoid, prefixedId } from '../../universal/id';
|
||||||
|
import type { EnvelopeIdOptions } from '../../utils/envelope';
|
||||||
|
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||||
|
import { incrementDocumentId } from '../envelope/increment-id';
|
||||||
import { triggerWebhook } from '../webhooks/trigger/trigger-webhook';
|
import { triggerWebhook } from '../webhooks/trigger/trigger-webhook';
|
||||||
import { getDocumentWhereInput } from './get-document-by-id';
|
|
||||||
|
|
||||||
export interface DuplicateDocumentOptions {
|
export interface DuplicateDocumentOptions {
|
||||||
documentId: number;
|
id: EnvelopeIdOptions;
|
||||||
userId: number;
|
userId: number;
|
||||||
teamId: number;
|
teamId: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const duplicateDocument = async ({
|
export const duplicateDocument = async ({ id, userId, teamId }: DuplicateDocumentOptions) => {
|
||||||
documentId,
|
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
||||||
userId,
|
id,
|
||||||
teamId,
|
type: EnvelopeType.DOCUMENT,
|
||||||
}: DuplicateDocumentOptions) => {
|
|
||||||
const { documentWhereInput } = await getDocumentWhereInput({
|
|
||||||
documentId,
|
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const document = await prisma.document.findFirst({
|
const envelope = await prisma.envelope.findFirst({
|
||||||
where: documentWhereInput,
|
where: envelopeWhereInput,
|
||||||
select: {
|
select: {
|
||||||
title: true,
|
title: true,
|
||||||
userId: true,
|
userId: true,
|
||||||
documentData: {
|
envelopeItems: {
|
||||||
select: {
|
include: {
|
||||||
data: true,
|
documentData: {
|
||||||
initialData: true,
|
select: {
|
||||||
type: true,
|
data: true,
|
||||||
|
initialData: true,
|
||||||
|
type: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
authOptions: true,
|
authOptions: true,
|
||||||
@ -54,44 +57,36 @@ export const duplicateDocument = async ({
|
|||||||
fields: true,
|
fields: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
teamId: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!document) {
|
if (!envelope) {
|
||||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||||
message: 'Document not found',
|
message: 'Document not found',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const documentData = await prisma.documentData.create({
|
const { documentId, formattedDocumentId } = await incrementDocumentId();
|
||||||
|
|
||||||
|
const createdDocumentMeta = await prisma.documentMeta.create({
|
||||||
data: {
|
data: {
|
||||||
type: document.documentData.type,
|
...omit(envelope.documentMeta, ['id']),
|
||||||
data: document.documentData.initialData,
|
emailSettings: envelope.documentMeta.emailSettings || undefined,
|
||||||
initialData: document.documentData.initialData,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let documentMeta: Prisma.DocumentCreateArgs['data']['documentMeta'] | undefined = undefined;
|
const duplicatedEnvelope = await prisma.envelope.create({
|
||||||
|
|
||||||
if (document.documentMeta) {
|
|
||||||
documentMeta = {
|
|
||||||
create: {
|
|
||||||
...omit(document.documentMeta, ['id', 'documentId']),
|
|
||||||
emailSettings: document.documentMeta.emailSettings || undefined,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const createdDocument = await prisma.document.create({
|
|
||||||
data: {
|
data: {
|
||||||
userId: document.userId,
|
id: prefixedId('envelope'),
|
||||||
teamId: teamId,
|
secondaryId: formattedDocumentId,
|
||||||
title: document.title,
|
type: EnvelopeType.DOCUMENT,
|
||||||
documentDataId: documentData.id,
|
userId,
|
||||||
authOptions: document.authOptions || undefined,
|
teamId,
|
||||||
visibility: document.visibility,
|
title: envelope.title,
|
||||||
qrToken: prefixedId('qr'),
|
documentMetaId: createdDocumentMeta.id,
|
||||||
documentMeta,
|
authOptions: envelope.authOptions || undefined,
|
||||||
|
visibility: envelope.visibility,
|
||||||
source: DocumentSource.DOCUMENT,
|
source: DocumentSource.DOCUMENT,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
@ -100,53 +95,86 @@ export const duplicateDocument = async ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const recipientsToCreate = document.recipients.map((recipient) => ({
|
// Key = original envelope item ID
|
||||||
documentId: createdDocument.id,
|
// Value = duplicated envelope item ID.
|
||||||
email: recipient.email,
|
const oldEnvelopeItemToNewEnvelopeItemIdMap: Record<string, string> = {};
|
||||||
name: recipient.name,
|
|
||||||
role: recipient.role,
|
// Duplicate the envelope items.
|
||||||
signingOrder: recipient.signingOrder,
|
await Promise.all(
|
||||||
token: nanoid(),
|
envelope.envelopeItems.map(async (envelopeItem) => {
|
||||||
fields: {
|
const duplicatedDocumentData = await prisma.documentData.create({
|
||||||
createMany: {
|
data: {
|
||||||
data: recipient.fields.map((field) => ({
|
type: envelopeItem.documentData.type,
|
||||||
documentId: createdDocument.id,
|
data: envelopeItem.documentData.initialData,
|
||||||
type: field.type,
|
initialData: envelopeItem.documentData.initialData,
|
||||||
page: field.page,
|
},
|
||||||
positionX: field.positionX,
|
});
|
||||||
positionY: field.positionY,
|
|
||||||
width: field.width,
|
const duplicatedEnvelopeItem = await prisma.envelopeItem.create({
|
||||||
height: field.height,
|
data: {
|
||||||
customText: '',
|
id: prefixedId('envelope_item'),
|
||||||
inserted: false,
|
title: envelopeItem.title,
|
||||||
fieldMeta: field.fieldMeta as PrismaJson.FieldMeta,
|
envelopeId: duplicatedEnvelope.id,
|
||||||
})),
|
documentDataId: duplicatedDocumentData.id,
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
}));
|
|
||||||
|
oldEnvelopeItemToNewEnvelopeItemIdMap[envelopeItem.id] = duplicatedEnvelopeItem.id;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
const recipients: Recipient[] = [];
|
const recipients: Recipient[] = [];
|
||||||
|
|
||||||
for (const recipientData of recipientsToCreate) {
|
for (const recipient of envelope.recipients) {
|
||||||
const newRecipient = await prisma.recipient.create({
|
const duplicatedRecipient = await prisma.recipient.create({
|
||||||
data: recipientData,
|
data: {
|
||||||
|
envelopeId: duplicatedEnvelope.id,
|
||||||
|
email: recipient.email,
|
||||||
|
name: recipient.name,
|
||||||
|
role: recipient.role,
|
||||||
|
signingOrder: recipient.signingOrder,
|
||||||
|
token: nanoid(),
|
||||||
|
fields: {
|
||||||
|
createMany: {
|
||||||
|
data: recipient.fields.map((field) => ({
|
||||||
|
envelopeId: duplicatedEnvelope.id,
|
||||||
|
envelopeItemId: oldEnvelopeItemToNewEnvelopeItemIdMap[field.envelopeItemId],
|
||||||
|
type: field.type,
|
||||||
|
page: field.page,
|
||||||
|
positionX: field.positionX,
|
||||||
|
positionY: field.positionY,
|
||||||
|
width: field.width,
|
||||||
|
height: field.height,
|
||||||
|
customText: '',
|
||||||
|
inserted: false,
|
||||||
|
fieldMeta: field.fieldMeta as PrismaJson.FieldMeta,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
recipients.push(newRecipient);
|
recipients.push(duplicatedRecipient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const refetchedEnvelope = await prisma.envelope.findFirstOrThrow({
|
||||||
|
where: {
|
||||||
|
id: duplicatedEnvelope.id,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
documentMeta: true,
|
||||||
|
recipients: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
await triggerWebhook({
|
await triggerWebhook({
|
||||||
event: WebhookTriggerEvents.DOCUMENT_CREATED,
|
event: WebhookTriggerEvents.DOCUMENT_CREATED,
|
||||||
data: ZWebhookDocumentSchema.parse({
|
data: ZWebhookDocumentSchema.parse(mapEnvelopeToWebhookDocumentPayload(refetchedEnvelope)),
|
||||||
...mapDocumentToWebhookDocumentPayload(createdDocument),
|
|
||||||
recipients,
|
|
||||||
documentMeta: createdDocument.documentMeta,
|
|
||||||
}),
|
|
||||||
userId: userId,
|
userId: userId,
|
||||||
teamId: teamId,
|
teamId: teamId,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
documentId: createdDocument.id,
|
documentId,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import type { DocumentAuditLog, Prisma } from '@prisma/client';
|
import { type DocumentAuditLog, EnvelopeType, type Prisma } from '@prisma/client';
|
||||||
|
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
@ -6,7 +6,7 @@ import { AppError, AppErrorCode } from '../../errors/app-error';
|
|||||||
import { DOCUMENT_AUDIT_LOG_TYPE } from '../../types/document-audit-logs';
|
import { DOCUMENT_AUDIT_LOG_TYPE } from '../../types/document-audit-logs';
|
||||||
import type { FindResultResponse } from '../../types/search-params';
|
import type { FindResultResponse } from '../../types/search-params';
|
||||||
import { parseDocumentAuditLogData } from '../../utils/document-audit-logs';
|
import { parseDocumentAuditLogData } from '../../utils/document-audit-logs';
|
||||||
import { getDocumentWhereInput } from './get-document-by-id';
|
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||||
|
|
||||||
export interface FindDocumentAuditLogsOptions {
|
export interface FindDocumentAuditLogsOptions {
|
||||||
userId: number;
|
userId: number;
|
||||||
@ -35,22 +35,26 @@ export const findDocumentAuditLogs = async ({
|
|||||||
const orderByColumn = orderBy?.column ?? 'createdAt';
|
const orderByColumn = orderBy?.column ?? 'createdAt';
|
||||||
const orderByDirection = orderBy?.direction ?? 'desc';
|
const orderByDirection = orderBy?.direction ?? 'desc';
|
||||||
|
|
||||||
const { documentWhereInput } = await getDocumentWhereInput({
|
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
||||||
documentId,
|
id: {
|
||||||
|
type: 'documentId',
|
||||||
|
id: documentId,
|
||||||
|
},
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const document = await prisma.document.findFirst({
|
const envelope = await prisma.envelope.findUnique({
|
||||||
where: documentWhereInput,
|
where: envelopeWhereInput,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!document) {
|
if (!envelope) {
|
||||||
throw new AppError(AppErrorCode.NOT_FOUND);
|
throw new AppError(AppErrorCode.NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
const whereClause: Prisma.DocumentAuditLogWhereInput = {
|
const whereClause: Prisma.DocumentAuditLogWhereInput = {
|
||||||
documentId,
|
envelopeId: envelope.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Filter events down to what we consider recent activity.
|
// Filter events down to what we consider recent activity.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import type { Document, DocumentSource, Prisma, Team, TeamEmail, User } from '@prisma/client';
|
import type { DocumentSource, Envelope, Prisma, Team, TeamEmail, User } from '@prisma/client';
|
||||||
import { RecipientRole, SigningStatus, TeamMemberRole } from '@prisma/client';
|
import { EnvelopeType, RecipientRole, SigningStatus, TeamMemberRole } from '@prisma/client';
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
import { match } from 'ts-pattern';
|
import { match } from 'ts-pattern';
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ export type FindDocumentsOptions = {
|
|||||||
page?: number;
|
page?: number;
|
||||||
perPage?: number;
|
perPage?: number;
|
||||||
orderBy?: {
|
orderBy?: {
|
||||||
column: keyof Omit<Document, 'document'>;
|
column: keyof Pick<Envelope, 'createdAt'>;
|
||||||
direction: 'asc' | 'desc';
|
direction: 'asc' | 'desc';
|
||||||
};
|
};
|
||||||
period?: PeriodSelectorValue;
|
period?: PeriodSelectorValue;
|
||||||
@ -69,7 +69,7 @@ export const findDocuments = async ({
|
|||||||
const orderByDirection = orderBy?.direction ?? 'desc';
|
const orderByDirection = orderBy?.direction ?? 'desc';
|
||||||
const teamMemberRole = team?.currentTeamRole ?? null;
|
const teamMemberRole = team?.currentTeamRole ?? null;
|
||||||
|
|
||||||
const searchFilter: Prisma.DocumentWhereInput = {
|
const searchFilter: Prisma.EnvelopeWhereInput = {
|
||||||
OR: [
|
OR: [
|
||||||
{ title: { contains: query, mode: 'insensitive' } },
|
{ title: { contains: query, mode: 'insensitive' } },
|
||||||
{ externalId: { contains: query, mode: 'insensitive' } },
|
{ externalId: { contains: query, mode: 'insensitive' } },
|
||||||
@ -111,7 +111,7 @@ export const findDocuments = async ({
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
let filters: Prisma.DocumentWhereInput | null = findDocumentsFilter(status, user, folderId);
|
let filters: Prisma.EnvelopeWhereInput | null = findDocumentsFilter(status, user, folderId);
|
||||||
|
|
||||||
if (team) {
|
if (team) {
|
||||||
filters = findTeamDocumentsFilter(status, team, visibilityFilters, folderId);
|
filters = findTeamDocumentsFilter(status, team, visibilityFilters, folderId);
|
||||||
@ -127,7 +127,7 @@ export const findDocuments = async ({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let deletedFilter: Prisma.DocumentWhereInput = {
|
let deletedFilter: Prisma.EnvelopeWhereInput = {
|
||||||
AND: {
|
AND: {
|
||||||
OR: [
|
OR: [
|
||||||
{
|
{
|
||||||
@ -180,7 +180,7 @@ export const findDocuments = async ({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const whereAndClause: Prisma.DocumentWhereInput['AND'] = [
|
const whereAndClause: Prisma.EnvelopeWhereInput['AND'] = [
|
||||||
{ ...filters },
|
{ ...filters },
|
||||||
{ ...deletedFilter },
|
{ ...deletedFilter },
|
||||||
{ ...searchFilter },
|
{ ...searchFilter },
|
||||||
@ -198,7 +198,8 @@ export const findDocuments = async ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const whereClause: Prisma.DocumentWhereInput = {
|
const whereClause: Prisma.EnvelopeWhereInput = {
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
AND: whereAndClause,
|
AND: whereAndClause,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -225,7 +226,7 @@ export const findDocuments = async ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const [data, count] = await Promise.all([
|
const [data, count] = await Promise.all([
|
||||||
prisma.document.findMany({
|
prisma.envelope.findMany({
|
||||||
where: whereClause,
|
where: whereClause,
|
||||||
skip: Math.max(page - 1, 0) * perPage,
|
skip: Math.max(page - 1, 0) * perPage,
|
||||||
take: perPage,
|
take: perPage,
|
||||||
@ -249,7 +250,7 @@ export const findDocuments = async ({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
prisma.document.count({
|
prisma.envelope.count({
|
||||||
where: whereClause,
|
where: whereClause,
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
@ -275,7 +276,7 @@ const findDocumentsFilter = (
|
|||||||
user: Pick<User, 'id' | 'email' | 'name'>,
|
user: Pick<User, 'id' | 'email' | 'name'>,
|
||||||
folderId?: string | null,
|
folderId?: string | null,
|
||||||
) => {
|
) => {
|
||||||
return match<ExtendedDocumentStatus, Prisma.DocumentWhereInput>(status)
|
return match<ExtendedDocumentStatus, Prisma.EnvelopeWhereInput>(status)
|
||||||
.with(ExtendedDocumentStatus.ALL, () => ({
|
.with(ExtendedDocumentStatus.ALL, () => ({
|
||||||
OR: [
|
OR: [
|
||||||
{
|
{
|
||||||
@ -414,14 +415,14 @@ const findDocumentsFilter = (
|
|||||||
const findTeamDocumentsFilter = (
|
const findTeamDocumentsFilter = (
|
||||||
status: ExtendedDocumentStatus,
|
status: ExtendedDocumentStatus,
|
||||||
team: Team & { teamEmail: TeamEmail | null },
|
team: Team & { teamEmail: TeamEmail | null },
|
||||||
visibilityFilters: Prisma.DocumentWhereInput[],
|
visibilityFilters: Prisma.EnvelopeWhereInput[],
|
||||||
folderId?: string,
|
folderId?: string,
|
||||||
) => {
|
) => {
|
||||||
const teamEmail = team.teamEmail?.email ?? null;
|
const teamEmail = team.teamEmail?.email ?? null;
|
||||||
|
|
||||||
return match<ExtendedDocumentStatus, Prisma.DocumentWhereInput | null>(status)
|
return match<ExtendedDocumentStatus, Prisma.EnvelopeWhereInput | null>(status)
|
||||||
.with(ExtendedDocumentStatus.ALL, () => {
|
.with(ExtendedDocumentStatus.ALL, () => {
|
||||||
const filter: Prisma.DocumentWhereInput = {
|
const filter: Prisma.EnvelopeWhereInput = {
|
||||||
// Filter to display all documents that belong to the team.
|
// Filter to display all documents that belong to the team.
|
||||||
OR: [
|
OR: [
|
||||||
{
|
{
|
||||||
@ -483,7 +484,7 @@ const findTeamDocumentsFilter = (
|
|||||||
};
|
};
|
||||||
})
|
})
|
||||||
.with(ExtendedDocumentStatus.DRAFT, () => {
|
.with(ExtendedDocumentStatus.DRAFT, () => {
|
||||||
const filter: Prisma.DocumentWhereInput = {
|
const filter: Prisma.EnvelopeWhereInput = {
|
||||||
OR: [
|
OR: [
|
||||||
{
|
{
|
||||||
teamId: team.id,
|
teamId: team.id,
|
||||||
@ -508,7 +509,7 @@ const findTeamDocumentsFilter = (
|
|||||||
return filter;
|
return filter;
|
||||||
})
|
})
|
||||||
.with(ExtendedDocumentStatus.PENDING, () => {
|
.with(ExtendedDocumentStatus.PENDING, () => {
|
||||||
const filter: Prisma.DocumentWhereInput = {
|
const filter: Prisma.EnvelopeWhereInput = {
|
||||||
OR: [
|
OR: [
|
||||||
{
|
{
|
||||||
teamId: team.id,
|
teamId: team.id,
|
||||||
@ -550,7 +551,7 @@ const findTeamDocumentsFilter = (
|
|||||||
return filter;
|
return filter;
|
||||||
})
|
})
|
||||||
.with(ExtendedDocumentStatus.COMPLETED, () => {
|
.with(ExtendedDocumentStatus.COMPLETED, () => {
|
||||||
const filter: Prisma.DocumentWhereInput = {
|
const filter: Prisma.EnvelopeWhereInput = {
|
||||||
status: ExtendedDocumentStatus.COMPLETED,
|
status: ExtendedDocumentStatus.COMPLETED,
|
||||||
OR: [
|
OR: [
|
||||||
{
|
{
|
||||||
@ -582,7 +583,7 @@ const findTeamDocumentsFilter = (
|
|||||||
return filter;
|
return filter;
|
||||||
})
|
})
|
||||||
.with(ExtendedDocumentStatus.REJECTED, () => {
|
.with(ExtendedDocumentStatus.REJECTED, () => {
|
||||||
const filter: Prisma.DocumentWhereInput = {
|
const filter: Prisma.EnvelopeWhereInput = {
|
||||||
status: ExtendedDocumentStatus.REJECTED,
|
status: ExtendedDocumentStatus.REJECTED,
|
||||||
OR: [
|
OR: [
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
|
import { DocumentStatus, EnvelopeType } from '@prisma/client';
|
||||||
|
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
|
import { mapSecondaryIdToDocumentId } from '../../utils/envelope';
|
||||||
|
|
||||||
export type GetDocumentByAccessTokenOptions = {
|
export type GetDocumentByAccessTokenOptions = {
|
||||||
token: string;
|
token: string;
|
||||||
};
|
};
|
||||||
@ -9,30 +13,54 @@ export const getDocumentByAccessToken = async ({ token }: GetDocumentByAccessTok
|
|||||||
throw new Error('Missing token');
|
throw new Error('Missing token');
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await prisma.document.findFirstOrThrow({
|
const result = await prisma.envelope.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
|
status: DocumentStatus.COMPLETED,
|
||||||
qrToken: token,
|
qrToken: token,
|
||||||
},
|
},
|
||||||
|
// Do not provide extra information that is not needed.
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
secondaryId: true,
|
||||||
title: true,
|
title: true,
|
||||||
completedAt: true,
|
completedAt: true,
|
||||||
documentData: {
|
team: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
url: true,
|
||||||
type: true,
|
|
||||||
data: true,
|
|
||||||
initialData: true,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
documentMeta: {
|
envelopeItems: {
|
||||||
select: {
|
select: {
|
||||||
password: true,
|
documentData: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
type: true,
|
||||||
|
data: true,
|
||||||
|
initialData: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
_count: {
|
||||||
|
select: {
|
||||||
|
recipients: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
recipients: true,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
// Todo: Envelopes
|
||||||
|
if (!result.envelopeItems[0].documentData) {
|
||||||
|
throw new Error('Missing document data');
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: mapSecondaryIdToDocumentId(result.secondaryId),
|
||||||
|
title: result.title,
|
||||||
|
completedAt: result.completedAt,
|
||||||
|
documentData: result.envelopeItems[0].documentData,
|
||||||
|
recipientCount: result._count.recipients,
|
||||||
|
documentTeamUrl: result.team.url,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,156 +0,0 @@
|
|||||||
import type { Prisma } from '@prisma/client';
|
|
||||||
import { DocumentStatus, TeamMemberRole } from '@prisma/client';
|
|
||||||
import { match } from 'ts-pattern';
|
|
||||||
|
|
||||||
import { prisma } from '@documenso/prisma';
|
|
||||||
|
|
||||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
|
||||||
import { DocumentVisibility } from '../../types/document-visibility';
|
|
||||||
import { getTeamById } from '../team/get-team';
|
|
||||||
|
|
||||||
export type GetDocumentByIdOptions = {
|
|
||||||
documentId: number;
|
|
||||||
userId: number;
|
|
||||||
teamId: number;
|
|
||||||
folderId?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getDocumentById = async ({
|
|
||||||
documentId,
|
|
||||||
userId,
|
|
||||||
teamId,
|
|
||||||
folderId,
|
|
||||||
}: GetDocumentByIdOptions) => {
|
|
||||||
const { documentWhereInput } = await getDocumentWhereInput({
|
|
||||||
documentId,
|
|
||||||
userId,
|
|
||||||
teamId,
|
|
||||||
});
|
|
||||||
|
|
||||||
const document = await prisma.document.findFirst({
|
|
||||||
where: {
|
|
||||||
...documentWhereInput,
|
|
||||||
folderId,
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
documentData: true,
|
|
||||||
documentMeta: true,
|
|
||||||
user: {
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
email: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
recipients: {
|
|
||||||
select: {
|
|
||||||
email: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
team: {
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
url: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!document) {
|
|
||||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
|
||||||
message: 'Document could not be found',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return document;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type GetDocumentWhereInputOptions = {
|
|
||||||
documentId: number;
|
|
||||||
userId: number;
|
|
||||||
teamId: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate the where input for a given Prisma document query.
|
|
||||||
*
|
|
||||||
* This will return a query that allows a user to get a document if they have valid access to it.
|
|
||||||
*/
|
|
||||||
export const getDocumentWhereInput = async ({
|
|
||||||
documentId,
|
|
||||||
userId,
|
|
||||||
teamId,
|
|
||||||
}: GetDocumentWhereInputOptions) => {
|
|
||||||
const team = await getTeamById({ teamId, userId });
|
|
||||||
|
|
||||||
const user = await prisma.user.findFirstOrThrow({
|
|
||||||
where: {
|
|
||||||
id: userId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const teamVisibilityFilters = match(team.currentTeamRole)
|
|
||||||
.with(TeamMemberRole.ADMIN, () => [
|
|
||||||
DocumentVisibility.EVERYONE,
|
|
||||||
DocumentVisibility.MANAGER_AND_ABOVE,
|
|
||||||
DocumentVisibility.ADMIN,
|
|
||||||
])
|
|
||||||
.with(TeamMemberRole.MANAGER, () => [
|
|
||||||
DocumentVisibility.EVERYONE,
|
|
||||||
DocumentVisibility.MANAGER_AND_ABOVE,
|
|
||||||
])
|
|
||||||
.otherwise(() => [DocumentVisibility.EVERYONE]);
|
|
||||||
|
|
||||||
const documentOrInput: Prisma.DocumentWhereInput[] = [
|
|
||||||
// Allow access if they own the document.
|
|
||||||
{
|
|
||||||
userId,
|
|
||||||
},
|
|
||||||
// Or, if they belong to the team that the document is associated with.
|
|
||||||
{
|
|
||||||
visibility: {
|
|
||||||
in: teamVisibilityFilters,
|
|
||||||
},
|
|
||||||
teamId: team.id,
|
|
||||||
},
|
|
||||||
// Or, if they are a recipient of the document.
|
|
||||||
{
|
|
||||||
status: {
|
|
||||||
not: DocumentStatus.DRAFT,
|
|
||||||
},
|
|
||||||
recipients: {
|
|
||||||
some: {
|
|
||||||
email: user.email,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
// Allow access to documents sent to or from the team email.
|
|
||||||
if (team.teamEmail) {
|
|
||||||
documentOrInput.push(
|
|
||||||
{
|
|
||||||
recipients: {
|
|
||||||
some: {
|
|
||||||
email: team.teamEmail.email,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
user: {
|
|
||||||
email: team.teamEmail.email,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const documentWhereInput: Prisma.DocumentWhereUniqueInput = {
|
|
||||||
id: documentId,
|
|
||||||
OR: documentOrInput,
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
documentWhereInput,
|
|
||||||
team,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@ -1,8 +1,10 @@
|
|||||||
|
import { EnvelopeType } from '@prisma/client';
|
||||||
|
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import type { DocumentWithRecipient } from '@documenso/prisma/types/document-with-recipient';
|
|
||||||
|
|
||||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||||
import type { TDocumentAuthMethods } from '../../types/document-auth';
|
import type { TDocumentAuthMethods } from '../../types/document-auth';
|
||||||
|
import { mapSecondaryIdToDocumentId } from '../../utils/envelope';
|
||||||
import { isRecipientAuthorized } from './is-recipient-authorized';
|
import { isRecipientAuthorized } from './is-recipient-authorized';
|
||||||
|
|
||||||
export interface GetDocumentAndSenderByTokenOptions {
|
export interface GetDocumentAndSenderByTokenOptions {
|
||||||
@ -39,8 +41,9 @@ export const getDocumentByToken = async ({ token }: GetDocumentByTokenOptions) =
|
|||||||
throw new Error('Missing token');
|
throw new Error('Missing token');
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await prisma.document.findFirstOrThrow({
|
const result = await prisma.envelope.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
recipients: {
|
recipients: {
|
||||||
some: {
|
some: {
|
||||||
token,
|
token,
|
||||||
@ -64,8 +67,9 @@ export const getDocumentAndSenderByToken = async ({
|
|||||||
throw new Error('Missing token');
|
throw new Error('Missing token');
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await prisma.document.findFirstOrThrow({
|
const result = await prisma.envelope.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
recipients: {
|
recipients: {
|
||||||
some: {
|
some: {
|
||||||
token,
|
token,
|
||||||
@ -80,13 +84,17 @@ export const getDocumentAndSenderByToken = async ({
|
|||||||
name: true,
|
name: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
documentData: true,
|
|
||||||
documentMeta: true,
|
documentMeta: true,
|
||||||
recipients: {
|
recipients: {
|
||||||
where: {
|
where: {
|
||||||
token,
|
token,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
envelopeItems: {
|
||||||
|
select: {
|
||||||
|
documentData: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
team: {
|
team: {
|
||||||
select: {
|
select: {
|
||||||
name: true,
|
name: true,
|
||||||
@ -102,6 +110,13 @@ export const getDocumentAndSenderByToken = async ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Todo: Envelopes
|
||||||
|
const firstDocumentData = result.envelopeItems[0].documentData;
|
||||||
|
|
||||||
|
if (!firstDocumentData) {
|
||||||
|
throw new Error('Missing document data');
|
||||||
|
}
|
||||||
|
|
||||||
const recipient = result.recipients[0];
|
const recipient = result.recipients[0];
|
||||||
|
|
||||||
// Sanity check, should not be possible.
|
// Sanity check, should not be possible.
|
||||||
@ -127,6 +142,8 @@ export const getDocumentAndSenderByToken = async ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const legacyDocumentId = mapSecondaryIdToDocumentId(result.secondaryId);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...result,
|
...result,
|
||||||
user: {
|
user: {
|
||||||
@ -134,64 +151,7 @@ export const getDocumentAndSenderByToken = async ({
|
|||||||
email: result.user.email,
|
email: result.user.email,
|
||||||
name: result.user.name,
|
name: result.user.name,
|
||||||
},
|
},
|
||||||
|
documentData: firstDocumentData,
|
||||||
|
id: legacyDocumentId,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a Document and a Recipient by the recipient token.
|
|
||||||
*/
|
|
||||||
export const getDocumentAndRecipientByToken = async ({
|
|
||||||
token,
|
|
||||||
userId,
|
|
||||||
accessAuth,
|
|
||||||
requireAccessAuth = true,
|
|
||||||
}: GetDocumentAndRecipientByTokenOptions): Promise<DocumentWithRecipient> => {
|
|
||||||
if (!token) {
|
|
||||||
throw new Error('Missing token');
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await prisma.document.findFirstOrThrow({
|
|
||||||
where: {
|
|
||||||
recipients: {
|
|
||||||
some: {
|
|
||||||
token,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
recipients: {
|
|
||||||
where: {
|
|
||||||
token,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
documentData: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const [recipient] = result.recipients;
|
|
||||||
|
|
||||||
// Sanity check, should not be possible.
|
|
||||||
if (!recipient) {
|
|
||||||
throw new Error('Missing recipient');
|
|
||||||
}
|
|
||||||
|
|
||||||
let documentAccessValid = true;
|
|
||||||
|
|
||||||
if (requireAccessAuth) {
|
|
||||||
documentAccessValid = await isRecipientAuthorized({
|
|
||||||
type: 'ACCESS',
|
|
||||||
documentAuthOptions: result.authOptions,
|
|
||||||
recipient,
|
|
||||||
userId,
|
|
||||||
authOptions: accessAuth,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!documentAccessValid) {
|
|
||||||
throw new AppError(AppErrorCode.UNAUTHORIZED, {
|
|
||||||
message: 'Invalid access values',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|||||||
@ -4,15 +4,15 @@ import { DOCUMENT_AUDIT_LOG_TYPE, DOCUMENT_EMAIL_TYPE } from '../../types/docume
|
|||||||
import { parseDocumentAuditLogData } from '../../utils/document-audit-logs';
|
import { parseDocumentAuditLogData } from '../../utils/document-audit-logs';
|
||||||
|
|
||||||
export type GetDocumentCertificateAuditLogsOptions = {
|
export type GetDocumentCertificateAuditLogsOptions = {
|
||||||
id: number;
|
envelopeId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getDocumentCertificateAuditLogs = async ({
|
export const getDocumentCertificateAuditLogs = async ({
|
||||||
id,
|
envelopeId,
|
||||||
}: GetDocumentCertificateAuditLogsOptions) => {
|
}: GetDocumentCertificateAuditLogsOptions) => {
|
||||||
const rawAuditLogs = await prisma.documentAuditLog.findMany({
|
const rawAuditLogs = await prisma.documentAuditLog.findMany({
|
||||||
where: {
|
where: {
|
||||||
documentId: id,
|
envelopeId,
|
||||||
type: {
|
type: {
|
||||||
in: [
|
in: [
|
||||||
DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_COMPLETED,
|
DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_COMPLETED,
|
||||||
|
|||||||
@ -1,67 +1,52 @@
|
|||||||
import { prisma } from '@documenso/prisma';
|
import { EnvelopeType } from '@prisma/client';
|
||||||
|
|
||||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
import { type EnvelopeIdOptions, mapSecondaryIdToDocumentId } from '../../utils/envelope';
|
||||||
import { getDocumentWhereInput } from './get-document-by-id';
|
import { getEnvelopeById } from '../envelope/get-envelope-by-id';
|
||||||
|
|
||||||
export type GetDocumentWithDetailsByIdOptions = {
|
export type GetDocumentWithDetailsByIdOptions = {
|
||||||
documentId: number;
|
id: EnvelopeIdOptions;
|
||||||
userId: number;
|
userId: number;
|
||||||
teamId: number;
|
teamId: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getDocumentWithDetailsById = async ({
|
export const getDocumentWithDetailsById = async ({
|
||||||
documentId,
|
id,
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
}: GetDocumentWithDetailsByIdOptions) => {
|
}: GetDocumentWithDetailsByIdOptions) => {
|
||||||
const { documentWhereInput } = await getDocumentWhereInput({
|
const envelope = await getEnvelopeById({
|
||||||
documentId,
|
id,
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const document = await prisma.document.findFirst({
|
const legacyDocumentId = mapSecondaryIdToDocumentId(envelope.secondaryId);
|
||||||
where: {
|
|
||||||
...documentWhereInput,
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
documentData: true,
|
|
||||||
documentMeta: true,
|
|
||||||
recipients: true,
|
|
||||||
folder: true,
|
|
||||||
fields: {
|
|
||||||
include: {
|
|
||||||
signature: true,
|
|
||||||
recipient: {
|
|
||||||
select: {
|
|
||||||
name: true,
|
|
||||||
email: true,
|
|
||||||
signingStatus: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
team: {
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
url: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
user: {
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
email: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!document) {
|
// Todo: Envelopes
|
||||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
const firstDocumentData = envelope.envelopeItems[0].documentData;
|
||||||
message: 'Document not found',
|
|
||||||
});
|
if (!firstDocumentData) {
|
||||||
|
throw new Error('Document data not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
return document;
|
return {
|
||||||
|
...envelope,
|
||||||
|
documentData: firstDocumentData,
|
||||||
|
id: legacyDocumentId,
|
||||||
|
fields: envelope.fields.map((field) => ({
|
||||||
|
...field,
|
||||||
|
documentId: legacyDocumentId,
|
||||||
|
})),
|
||||||
|
user: {
|
||||||
|
id: envelope.userId,
|
||||||
|
name: envelope.user.name,
|
||||||
|
email: envelope.user.email,
|
||||||
|
},
|
||||||
|
team: {
|
||||||
|
id: envelope.teamId,
|
||||||
|
url: envelope.team.url,
|
||||||
|
},
|
||||||
|
recipients: envelope.recipients,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -7,7 +7,7 @@ export type GetRecipientOrSenderByShareLinkSlugOptions = {
|
|||||||
export const getRecipientOrSenderByShareLinkSlug = async ({
|
export const getRecipientOrSenderByShareLinkSlug = async ({
|
||||||
slug,
|
slug,
|
||||||
}: GetRecipientOrSenderByShareLinkSlugOptions) => {
|
}: GetRecipientOrSenderByShareLinkSlugOptions) => {
|
||||||
const { documentId, email } = await prisma.documentShareLink.findFirstOrThrow({
|
const { envelopeId, email } = await prisma.documentShareLink.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
slug,
|
slug,
|
||||||
},
|
},
|
||||||
@ -15,7 +15,7 @@ export const getRecipientOrSenderByShareLinkSlug = async ({
|
|||||||
|
|
||||||
const sender = await prisma.user.findFirst({
|
const sender = await prisma.user.findFirst({
|
||||||
where: {
|
where: {
|
||||||
documents: { some: { id: documentId } },
|
envelopes: { some: { id: envelopeId } },
|
||||||
email,
|
email,
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
@ -31,7 +31,7 @@ export const getRecipientOrSenderByShareLinkSlug = async ({
|
|||||||
|
|
||||||
const recipient = await prisma.recipient.findFirst({
|
const recipient = await prisma.recipient.findFirst({
|
||||||
where: {
|
where: {
|
||||||
documentId,
|
envelopeId,
|
||||||
email,
|
email,
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { TeamMemberRole } from '@prisma/client';
|
import { EnvelopeType, TeamMemberRole } from '@prisma/client';
|
||||||
import type { Prisma, User } from '@prisma/client';
|
import type { Prisma, User } from '@prisma/client';
|
||||||
import { SigningStatus } from '@prisma/client';
|
import { SigningStatus } from '@prisma/client';
|
||||||
import { DocumentVisibility } from '@prisma/client';
|
import { DocumentVisibility } from '@prisma/client';
|
||||||
@ -25,7 +25,7 @@ export const getStats = async ({
|
|||||||
folderId,
|
folderId,
|
||||||
...options
|
...options
|
||||||
}: GetStatsInput) => {
|
}: GetStatsInput) => {
|
||||||
let createdAt: Prisma.DocumentWhereInput['createdAt'];
|
let createdAt: Prisma.EnvelopeWhereInput['createdAt'];
|
||||||
|
|
||||||
if (period) {
|
if (period) {
|
||||||
const daysAgo = parseInt(period.replace(/d$/, ''), 10);
|
const daysAgo = parseInt(period.replace(/d$/, ''), 10);
|
||||||
@ -90,13 +90,13 @@ export const getStats = async ({
|
|||||||
|
|
||||||
type GetCountsOption = {
|
type GetCountsOption = {
|
||||||
user: Pick<User, 'id' | 'email'>;
|
user: Pick<User, 'id' | 'email'>;
|
||||||
createdAt: Prisma.DocumentWhereInput['createdAt'];
|
createdAt: Prisma.EnvelopeWhereInput['createdAt'];
|
||||||
search?: string;
|
search?: string;
|
||||||
folderId?: string | null;
|
folderId?: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getCounts = async ({ user, createdAt, search, folderId }: GetCountsOption) => {
|
const getCounts = async ({ user, createdAt, search, folderId }: GetCountsOption) => {
|
||||||
const searchFilter: Prisma.DocumentWhereInput = {
|
const searchFilter: Prisma.EnvelopeWhereInput = {
|
||||||
OR: [
|
OR: [
|
||||||
{ title: { contains: search, mode: 'insensitive' } },
|
{ title: { contains: search, mode: 'insensitive' } },
|
||||||
{ recipients: { some: { name: { contains: search, mode: 'insensitive' } } } },
|
{ recipients: { some: { name: { contains: search, mode: 'insensitive' } } } },
|
||||||
@ -108,12 +108,13 @@ const getCounts = async ({ user, createdAt, search, folderId }: GetCountsOption)
|
|||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
// Owner counts.
|
// Owner counts.
|
||||||
prisma.document.groupBy({
|
prisma.envelope.groupBy({
|
||||||
by: ['status'],
|
by: ['status'],
|
||||||
_count: {
|
_count: {
|
||||||
_all: true,
|
_all: true,
|
||||||
},
|
},
|
||||||
where: {
|
where: {
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
createdAt,
|
createdAt,
|
||||||
deletedAt: null,
|
deletedAt: null,
|
||||||
@ -121,12 +122,13 @@ const getCounts = async ({ user, createdAt, search, folderId }: GetCountsOption)
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
// Not signed counts.
|
// Not signed counts.
|
||||||
prisma.document.groupBy({
|
prisma.envelope.groupBy({
|
||||||
by: ['status'],
|
by: ['status'],
|
||||||
_count: {
|
_count: {
|
||||||
_all: true,
|
_all: true,
|
||||||
},
|
},
|
||||||
where: {
|
where: {
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
status: ExtendedDocumentStatus.PENDING,
|
status: ExtendedDocumentStatus.PENDING,
|
||||||
recipients: {
|
recipients: {
|
||||||
some: {
|
some: {
|
||||||
@ -140,12 +142,13 @@ const getCounts = async ({ user, createdAt, search, folderId }: GetCountsOption)
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
// Has signed counts.
|
// Has signed counts.
|
||||||
prisma.document.groupBy({
|
prisma.envelope.groupBy({
|
||||||
by: ['status'],
|
by: ['status'],
|
||||||
_count: {
|
_count: {
|
||||||
_all: true,
|
_all: true,
|
||||||
},
|
},
|
||||||
where: {
|
where: {
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
createdAt,
|
createdAt,
|
||||||
user: {
|
user: {
|
||||||
email: {
|
email: {
|
||||||
@ -186,7 +189,7 @@ type GetTeamCountsOption = {
|
|||||||
senderIds?: number[];
|
senderIds?: number[];
|
||||||
currentUserEmail: string;
|
currentUserEmail: string;
|
||||||
userId: number;
|
userId: number;
|
||||||
createdAt: Prisma.DocumentWhereInput['createdAt'];
|
createdAt: Prisma.EnvelopeWhereInput['createdAt'];
|
||||||
currentTeamMemberRole?: TeamMemberRole;
|
currentTeamMemberRole?: TeamMemberRole;
|
||||||
search?: string;
|
search?: string;
|
||||||
folderId?: string | null;
|
folderId?: string | null;
|
||||||
@ -197,14 +200,14 @@ const getTeamCounts = async (options: GetTeamCountsOption) => {
|
|||||||
|
|
||||||
const senderIds = options.senderIds ?? [];
|
const senderIds = options.senderIds ?? [];
|
||||||
|
|
||||||
const userIdWhereClause: Prisma.DocumentWhereInput['userId'] =
|
const userIdWhereClause: Prisma.EnvelopeWhereInput['userId'] =
|
||||||
senderIds.length > 0
|
senderIds.length > 0
|
||||||
? {
|
? {
|
||||||
in: senderIds,
|
in: senderIds,
|
||||||
}
|
}
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
const searchFilter: Prisma.DocumentWhereInput = {
|
const searchFilter: Prisma.EnvelopeWhereInput = {
|
||||||
OR: [
|
OR: [
|
||||||
{ title: { contains: options.search, mode: 'insensitive' } },
|
{ title: { contains: options.search, mode: 'insensitive' } },
|
||||||
{ recipients: { some: { name: { contains: options.search, mode: 'insensitive' } } } },
|
{ recipients: { some: { name: { contains: options.search, mode: 'insensitive' } } } },
|
||||||
@ -212,7 +215,8 @@ const getTeamCounts = async (options: GetTeamCountsOption) => {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
let ownerCountsWhereInput: Prisma.DocumentWhereInput = {
|
let ownerCountsWhereInput: Prisma.EnvelopeWhereInput = {
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
userId: userIdWhereClause,
|
userId: userIdWhereClause,
|
||||||
createdAt,
|
createdAt,
|
||||||
teamId,
|
teamId,
|
||||||
@ -223,7 +227,7 @@ const getTeamCounts = async (options: GetTeamCountsOption) => {
|
|||||||
let notSignedCountsGroupByArgs = null;
|
let notSignedCountsGroupByArgs = null;
|
||||||
let hasSignedCountsGroupByArgs = null;
|
let hasSignedCountsGroupByArgs = null;
|
||||||
|
|
||||||
const visibilityFiltersWhereInput: Prisma.DocumentWhereInput = {
|
const visibilityFiltersWhereInput: Prisma.EnvelopeWhereInput = {
|
||||||
AND: [
|
AND: [
|
||||||
{ deletedAt: null },
|
{ deletedAt: null },
|
||||||
{
|
{
|
||||||
@ -267,6 +271,7 @@ const getTeamCounts = async (options: GetTeamCountsOption) => {
|
|||||||
|
|
||||||
if (teamEmail) {
|
if (teamEmail) {
|
||||||
ownerCountsWhereInput = {
|
ownerCountsWhereInput = {
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
userId: userIdWhereClause,
|
userId: userIdWhereClause,
|
||||||
createdAt,
|
createdAt,
|
||||||
OR: [
|
OR: [
|
||||||
@ -288,6 +293,7 @@ const getTeamCounts = async (options: GetTeamCountsOption) => {
|
|||||||
_all: true,
|
_all: true,
|
||||||
},
|
},
|
||||||
where: {
|
where: {
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
userId: userIdWhereClause,
|
userId: userIdWhereClause,
|
||||||
createdAt,
|
createdAt,
|
||||||
folderId,
|
folderId,
|
||||||
@ -301,7 +307,7 @@ const getTeamCounts = async (options: GetTeamCountsOption) => {
|
|||||||
},
|
},
|
||||||
deletedAt: null,
|
deletedAt: null,
|
||||||
},
|
},
|
||||||
} satisfies Prisma.DocumentGroupByArgs;
|
} satisfies Prisma.EnvelopeGroupByArgs;
|
||||||
|
|
||||||
hasSignedCountsGroupByArgs = {
|
hasSignedCountsGroupByArgs = {
|
||||||
by: ['status'],
|
by: ['status'],
|
||||||
@ -309,6 +315,7 @@ const getTeamCounts = async (options: GetTeamCountsOption) => {
|
|||||||
_all: true,
|
_all: true,
|
||||||
},
|
},
|
||||||
where: {
|
where: {
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
userId: userIdWhereClause,
|
userId: userIdWhereClause,
|
||||||
createdAt,
|
createdAt,
|
||||||
folderId,
|
folderId,
|
||||||
@ -336,18 +343,18 @@ const getTeamCounts = async (options: GetTeamCountsOption) => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
} satisfies Prisma.DocumentGroupByArgs;
|
} satisfies Prisma.EnvelopeGroupByArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
prisma.document.groupBy({
|
prisma.envelope.groupBy({
|
||||||
by: ['status'],
|
by: ['status'],
|
||||||
_count: {
|
_count: {
|
||||||
_all: true,
|
_all: true,
|
||||||
},
|
},
|
||||||
where: ownerCountsWhereInput,
|
where: ownerCountsWhereInput,
|
||||||
}),
|
}),
|
||||||
notSignedCountsGroupByArgs ? prisma.document.groupBy(notSignedCountsGroupByArgs) : [],
|
notSignedCountsGroupByArgs ? prisma.envelope.groupBy(notSignedCountsGroupByArgs) : [],
|
||||||
hasSignedCountsGroupByArgs ? prisma.document.groupBy(hasSignedCountsGroupByArgs) : [],
|
hasSignedCountsGroupByArgs ? prisma.envelope.groupBy(hasSignedCountsGroupByArgs) : [],
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import type { Document, Recipient } from '@prisma/client';
|
import type { Envelope, Recipient } from '@prisma/client';
|
||||||
import { verifyAuthenticationResponse } from '@simplewebauthn/server';
|
import { verifyAuthenticationResponse } from '@simplewebauthn/server';
|
||||||
import { match } from 'ts-pattern';
|
import { match } from 'ts-pattern';
|
||||||
|
|
||||||
@ -17,8 +17,8 @@ import { extractDocumentAuthMethods } from '../../utils/document-auth';
|
|||||||
type IsRecipientAuthorizedOptions = {
|
type IsRecipientAuthorizedOptions = {
|
||||||
// !: Probably find a better name than 'ACCESS_2FA' if requirements change.
|
// !: Probably find a better name than 'ACCESS_2FA' if requirements change.
|
||||||
type: 'ACCESS' | 'ACCESS_2FA' | 'ACTION';
|
type: 'ACCESS' | 'ACCESS_2FA' | 'ACTION';
|
||||||
documentAuthOptions: Document['authOptions'];
|
documentAuthOptions: Envelope['authOptions'];
|
||||||
recipient: Pick<Recipient, 'authOptions' | 'email' | 'documentId'>;
|
recipient: Pick<Recipient, 'authOptions' | 'email'>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ID of the user who initiated the request.
|
* The ID of the user who initiated the request.
|
||||||
@ -125,6 +125,7 @@ export const isRecipientAuthorized = async ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'ACCESS_2FA' && method === 'email') {
|
if (type === 'ACCESS_2FA' && method === 'email') {
|
||||||
|
// Todo: Envelopes - Need to pass in the secondary ID to parse the document ID for.
|
||||||
if (!recipient.documentId) {
|
if (!recipient.documentId) {
|
||||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||||
message: 'Document ID is required for email 2FA verification',
|
message: 'Document ID is required for email 2FA verification',
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { SigningStatus } from '@prisma/client';
|
import { EnvelopeType, SigningStatus } from '@prisma/client';
|
||||||
|
|
||||||
import { jobs } from '@documenso/lib/jobs/client';
|
import { jobs } from '@documenso/lib/jobs/client';
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
@ -7,17 +7,19 @@ import { AppError, AppErrorCode } from '../../errors/app-error';
|
|||||||
import { DOCUMENT_AUDIT_LOG_TYPE } from '../../types/document-audit-logs';
|
import { DOCUMENT_AUDIT_LOG_TYPE } from '../../types/document-audit-logs';
|
||||||
import type { RequestMetadata } from '../../universal/extract-request-metadata';
|
import type { RequestMetadata } from '../../universal/extract-request-metadata';
|
||||||
import { createDocumentAuditLogData } from '../../utils/document-audit-logs';
|
import { createDocumentAuditLogData } from '../../utils/document-audit-logs';
|
||||||
|
import type { EnvelopeIdOptions } from '../../utils/envelope';
|
||||||
|
import { mapSecondaryIdToDocumentId, unsafeBuildEnvelopeIdQuery } from '../../utils/envelope';
|
||||||
|
|
||||||
export type RejectDocumentWithTokenOptions = {
|
export type RejectDocumentWithTokenOptions = {
|
||||||
token: string;
|
token: string;
|
||||||
documentId: number;
|
id: EnvelopeIdOptions;
|
||||||
reason: string;
|
reason: string;
|
||||||
requestMetadata?: RequestMetadata;
|
requestMetadata?: RequestMetadata;
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function rejectDocumentWithToken({
|
export async function rejectDocumentWithToken({
|
||||||
token,
|
token,
|
||||||
documentId,
|
id,
|
||||||
reason,
|
reason,
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
}: RejectDocumentWithTokenOptions) {
|
}: RejectDocumentWithTokenOptions) {
|
||||||
@ -25,16 +27,16 @@ export async function rejectDocumentWithToken({
|
|||||||
const recipient = await prisma.recipient.findFirst({
|
const recipient = await prisma.recipient.findFirst({
|
||||||
where: {
|
where: {
|
||||||
token,
|
token,
|
||||||
documentId,
|
envelope: unsafeBuildEnvelopeIdQuery(id, EnvelopeType.DOCUMENT),
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
document: true,
|
envelope: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const document = recipient?.document;
|
const envelope = recipient?.envelope;
|
||||||
|
|
||||||
if (!recipient || !document) {
|
if (!recipient || !envelope) {
|
||||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||||
message: 'Document or recipient not found',
|
message: 'Document or recipient not found',
|
||||||
});
|
});
|
||||||
@ -54,7 +56,7 @@ export async function rejectDocumentWithToken({
|
|||||||
}),
|
}),
|
||||||
prisma.documentAuditLog.create({
|
prisma.documentAuditLog.create({
|
||||||
data: createDocumentAuditLogData({
|
data: createDocumentAuditLogData({
|
||||||
documentId,
|
envelopeId: envelope.id,
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_REJECTED,
|
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_REJECTED,
|
||||||
user: {
|
user: {
|
||||||
name: recipient.name,
|
name: recipient.name,
|
||||||
@ -72,11 +74,13 @@ export async function rejectDocumentWithToken({
|
|||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const legacyDocumentId = mapSecondaryIdToDocumentId(envelope.secondaryId);
|
||||||
|
|
||||||
// Trigger the seal document job to process the document asynchronously
|
// Trigger the seal document job to process the document asynchronously
|
||||||
await jobs.triggerJob({
|
await jobs.triggerJob({
|
||||||
name: 'internal.seal-document',
|
name: 'internal.seal-document',
|
||||||
payload: {
|
payload: {
|
||||||
documentId,
|
documentId: legacyDocumentId,
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -86,7 +90,7 @@ export async function rejectDocumentWithToken({
|
|||||||
name: 'send.signing.rejected.emails',
|
name: 'send.signing.rejected.emails',
|
||||||
payload: {
|
payload: {
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
documentId,
|
documentId: legacyDocumentId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -94,7 +98,7 @@ export async function rejectDocumentWithToken({
|
|||||||
await jobs.triggerJob({
|
await jobs.triggerJob({
|
||||||
name: 'send.document.cancelled.emails',
|
name: 'send.document.cancelled.emails',
|
||||||
payload: {
|
payload: {
|
||||||
documentId,
|
documentId: legacyDocumentId,
|
||||||
cancellationReason: reason,
|
cancellationReason: reason,
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,7 +1,13 @@
|
|||||||
import { createElement } from 'react';
|
import { createElement } from 'react';
|
||||||
|
|
||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { DocumentStatus, OrganisationType, RecipientRole, SigningStatus } from '@prisma/client';
|
import {
|
||||||
|
DocumentStatus,
|
||||||
|
EnvelopeType,
|
||||||
|
OrganisationType,
|
||||||
|
RecipientRole,
|
||||||
|
SigningStatus,
|
||||||
|
} from '@prisma/client';
|
||||||
|
|
||||||
import { mailer } from '@documenso/email/mailer';
|
import { mailer } from '@documenso/email/mailer';
|
||||||
import { DocumentInviteEmailTemplate } from '@documenso/email/templates/document-invite';
|
import { DocumentInviteEmailTemplate } from '@documenso/email/templates/document-invite';
|
||||||
@ -21,7 +27,7 @@ import { extractDerivedDocumentEmailSettings } from '../../types/document-email'
|
|||||||
import { isDocumentCompleted } from '../../utils/document';
|
import { isDocumentCompleted } from '../../utils/document';
|
||||||
import { renderEmailWithI18N } from '../../utils/render-email-with-i18n';
|
import { renderEmailWithI18N } from '../../utils/render-email-with-i18n';
|
||||||
import { getEmailContext } from '../email/get-email-context';
|
import { getEmailContext } from '../email/get-email-context';
|
||||||
import { getDocumentWhereInput } from './get-document-by-id';
|
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||||
|
|
||||||
export type ResendDocumentOptions = {
|
export type ResendDocumentOptions = {
|
||||||
documentId: number;
|
documentId: number;
|
||||||
@ -42,16 +48,25 @@ export const resendDocument = async ({
|
|||||||
where: {
|
where: {
|
||||||
id: userId,
|
id: userId,
|
||||||
},
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
email: true,
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const { documentWhereInput } = await getDocumentWhereInput({
|
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
||||||
documentId,
|
id: {
|
||||||
|
type: 'documentId',
|
||||||
|
id: documentId,
|
||||||
|
},
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const document = await prisma.document.findUnique({
|
const envelope = await prisma.envelope.findUnique({
|
||||||
where: documentWhereInput,
|
where: envelopeWhereInput,
|
||||||
include: {
|
include: {
|
||||||
recipients: true,
|
recipients: true,
|
||||||
documentMeta: true,
|
documentMeta: true,
|
||||||
@ -64,31 +79,29 @@ export const resendDocument = async ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const customEmail = document?.documentMeta;
|
if (!envelope) {
|
||||||
|
|
||||||
if (!document) {
|
|
||||||
throw new Error('Document not found');
|
throw new Error('Document not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document.recipients.length === 0) {
|
if (envelope.recipients.length === 0) {
|
||||||
throw new Error('Document has no recipients');
|
throw new Error('Document has no recipients');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document.status === DocumentStatus.DRAFT) {
|
if (envelope.status === DocumentStatus.DRAFT) {
|
||||||
throw new Error('Can not send draft document');
|
throw new Error('Can not send draft document');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDocumentCompleted(document.status)) {
|
if (isDocumentCompleted(envelope.status)) {
|
||||||
throw new Error('Can not send completed document');
|
throw new Error('Can not send completed document');
|
||||||
}
|
}
|
||||||
|
|
||||||
const recipientsToRemind = document.recipients.filter(
|
const recipientsToRemind = envelope.recipients.filter(
|
||||||
(recipient) =>
|
(recipient) =>
|
||||||
recipients.includes(recipient.id) && recipient.signingStatus === SigningStatus.NOT_SIGNED,
|
recipients.includes(recipient.id) && recipient.signingStatus === SigningStatus.NOT_SIGNED,
|
||||||
);
|
);
|
||||||
|
|
||||||
const isRecipientSigningRequestEmailEnabled = extractDerivedDocumentEmailSettings(
|
const isRecipientSigningRequestEmailEnabled = extractDerivedDocumentEmailSettings(
|
||||||
document.documentMeta,
|
envelope.documentMeta,
|
||||||
).recipientSigningRequest;
|
).recipientSigningRequest;
|
||||||
|
|
||||||
if (!isRecipientSigningRequestEmailEnabled) {
|
if (!isRecipientSigningRequestEmailEnabled) {
|
||||||
@ -100,9 +113,9 @@ export const resendDocument = async ({
|
|||||||
emailType: 'RECIPIENT',
|
emailType: 'RECIPIENT',
|
||||||
source: {
|
source: {
|
||||||
type: 'team',
|
type: 'team',
|
||||||
teamId: document.teamId,
|
teamId: envelope.teamId,
|
||||||
},
|
},
|
||||||
meta: document.documentMeta,
|
meta: envelope.documentMeta,
|
||||||
});
|
});
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
@ -122,42 +135,42 @@ export const resendDocument = async ({
|
|||||||
._(RECIPIENT_ROLES_DESCRIPTION[recipient.role].actionVerb)
|
._(RECIPIENT_ROLES_DESCRIPTION[recipient.role].actionVerb)
|
||||||
.toLowerCase();
|
.toLowerCase();
|
||||||
|
|
||||||
let emailMessage = customEmail?.message || '';
|
let emailMessage = envelope.documentMeta.message || '';
|
||||||
let emailSubject = i18n._(msg`Reminder: Please ${recipientActionVerb} this document`);
|
let emailSubject = i18n._(msg`Reminder: Please ${recipientActionVerb} this document`);
|
||||||
|
|
||||||
if (selfSigner) {
|
if (selfSigner) {
|
||||||
emailMessage = i18n._(
|
emailMessage = i18n._(
|
||||||
msg`You have initiated the document ${`"${document.title}"`} that requires you to ${recipientActionVerb} it.`,
|
msg`You have initiated the document ${`"${envelope.title}"`} that requires you to ${recipientActionVerb} it.`,
|
||||||
);
|
);
|
||||||
emailSubject = i18n._(msg`Reminder: Please ${recipientActionVerb} your document`);
|
emailSubject = i18n._(msg`Reminder: Please ${recipientActionVerb} your document`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (organisationType === OrganisationType.ORGANISATION) {
|
if (organisationType === OrganisationType.ORGANISATION) {
|
||||||
emailSubject = i18n._(
|
emailSubject = i18n._(
|
||||||
msg`Reminder: ${document.team.name} invited you to ${recipientActionVerb} a document`,
|
msg`Reminder: ${envelope.team.name} invited you to ${recipientActionVerb} a document`,
|
||||||
);
|
);
|
||||||
emailMessage =
|
emailMessage =
|
||||||
customEmail?.message ||
|
envelope.documentMeta.message ||
|
||||||
i18n._(
|
i18n._(
|
||||||
msg`${user.name || user.email} on behalf of "${document.team.name}" has invited you to ${recipientActionVerb} the document "${document.title}".`,
|
msg`${user.name || user.email} on behalf of "${envelope.team.name}" has invited you to ${recipientActionVerb} the document "${envelope.title}".`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const customEmailTemplate = {
|
const customEmailTemplate = {
|
||||||
'signer.name': name,
|
'signer.name': name,
|
||||||
'signer.email': email,
|
'signer.email': email,
|
||||||
'document.name': document.title,
|
'document.name': envelope.title,
|
||||||
};
|
};
|
||||||
|
|
||||||
const assetBaseUrl = NEXT_PUBLIC_WEBAPP_URL() || 'http://localhost:3000';
|
const assetBaseUrl = NEXT_PUBLIC_WEBAPP_URL() || 'http://localhost:3000';
|
||||||
const signDocumentLink = `${NEXT_PUBLIC_WEBAPP_URL()}/sign/${recipient.token}`;
|
const signDocumentLink = `${NEXT_PUBLIC_WEBAPP_URL()}/sign/${recipient.token}`;
|
||||||
|
|
||||||
const template = createElement(DocumentInviteEmailTemplate, {
|
const template = createElement(DocumentInviteEmailTemplate, {
|
||||||
documentName: document.title,
|
documentName: envelope.title,
|
||||||
inviterName: user.name || undefined,
|
inviterName: user.name || undefined,
|
||||||
inviterEmail:
|
inviterEmail:
|
||||||
organisationType === OrganisationType.ORGANISATION
|
organisationType === OrganisationType.ORGANISATION
|
||||||
? document.team?.teamEmail?.email || user.email
|
? envelope.team?.teamEmail?.email || user.email
|
||||||
: user.email,
|
: user.email,
|
||||||
assetBaseUrl,
|
assetBaseUrl,
|
||||||
signDocumentLink,
|
signDocumentLink,
|
||||||
@ -165,7 +178,7 @@ export const resendDocument = async ({
|
|||||||
role: recipient.role,
|
role: recipient.role,
|
||||||
selfSigner,
|
selfSigner,
|
||||||
organisationType,
|
organisationType,
|
||||||
teamName: document.team?.name,
|
teamName: envelope.team?.name,
|
||||||
});
|
});
|
||||||
|
|
||||||
const [html, text] = await Promise.all([
|
const [html, text] = await Promise.all([
|
||||||
@ -189,9 +202,9 @@ export const resendDocument = async ({
|
|||||||
},
|
},
|
||||||
from: senderEmail,
|
from: senderEmail,
|
||||||
replyTo: replyToEmail,
|
replyTo: replyToEmail,
|
||||||
subject: customEmail?.subject
|
subject: envelope.documentMeta.subject
|
||||||
? renderCustomEmailTemplate(
|
? renderCustomEmailTemplate(
|
||||||
i18n._(msg`Reminder: ${customEmail.subject}`),
|
i18n._(msg`Reminder: ${envelope.documentMeta.subject}`),
|
||||||
customEmailTemplate,
|
customEmailTemplate,
|
||||||
)
|
)
|
||||||
: emailSubject,
|
: emailSubject,
|
||||||
@ -202,7 +215,7 @@ export const resendDocument = async ({
|
|||||||
await tx.documentAuditLog.create({
|
await tx.documentAuditLog.create({
|
||||||
data: createDocumentAuditLogData({
|
data: createDocumentAuditLogData({
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.EMAIL_SENT,
|
type: DOCUMENT_AUDIT_LOG_TYPE.EMAIL_SENT,
|
||||||
documentId: document.id,
|
envelopeId: envelope.id,
|
||||||
metadata: requestMetadata,
|
metadata: requestMetadata,
|
||||||
data: {
|
data: {
|
||||||
emailType: recipientEmailType,
|
emailType: recipientEmailType,
|
||||||
|
|||||||
@ -1,4 +1,10 @@
|
|||||||
import { DocumentStatus, RecipientRole, SigningStatus, WebhookTriggerEvents } from '@prisma/client';
|
import {
|
||||||
|
DocumentStatus,
|
||||||
|
EnvelopeType,
|
||||||
|
RecipientRole,
|
||||||
|
SigningStatus,
|
||||||
|
WebhookTriggerEvents,
|
||||||
|
} from '@prisma/client';
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { PDFDocument } from 'pdf-lib';
|
import { PDFDocument } from 'pdf-lib';
|
||||||
@ -11,12 +17,17 @@ import { signPdf } from '@documenso/signing';
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
ZWebhookDocumentSchema,
|
ZWebhookDocumentSchema,
|
||||||
mapDocumentToWebhookDocumentPayload,
|
mapEnvelopeToWebhookDocumentPayload,
|
||||||
} from '../../types/webhook-payload';
|
} from '../../types/webhook-payload';
|
||||||
import type { RequestMetadata } from '../../universal/extract-request-metadata';
|
import type { RequestMetadata } from '../../universal/extract-request-metadata';
|
||||||
import { getFileServerSide } from '../../universal/upload/get-file.server';
|
import { getFileServerSide } from '../../universal/upload/get-file.server';
|
||||||
import { putPdfFileServerSide } from '../../universal/upload/put-file.server';
|
import { putPdfFileServerSide } from '../../universal/upload/put-file.server';
|
||||||
import { fieldsContainUnsignedRequiredField } from '../../utils/advanced-fields-helpers';
|
import { fieldsContainUnsignedRequiredField } from '../../utils/advanced-fields-helpers';
|
||||||
|
import {
|
||||||
|
type EnvelopeIdOptions,
|
||||||
|
mapSecondaryIdToDocumentId,
|
||||||
|
unsafeBuildEnvelopeIdQuery,
|
||||||
|
} from '../../utils/envelope';
|
||||||
import { getAuditLogsPdf } from '../htmltopdf/get-audit-logs-pdf';
|
import { getAuditLogsPdf } from '../htmltopdf/get-audit-logs-pdf';
|
||||||
import { getCertificatePdf } from '../htmltopdf/get-certificate-pdf';
|
import { getCertificatePdf } from '../htmltopdf/get-certificate-pdf';
|
||||||
import { addRejectionStampToPdf } from '../pdf/add-rejection-stamp-to-pdf';
|
import { addRejectionStampToPdf } from '../pdf/add-rejection-stamp-to-pdf';
|
||||||
@ -30,49 +41,63 @@ import { triggerWebhook } from '../webhooks/trigger/trigger-webhook';
|
|||||||
import { sendCompletedEmail } from './send-completed-email';
|
import { sendCompletedEmail } from './send-completed-email';
|
||||||
|
|
||||||
export type SealDocumentOptions = {
|
export type SealDocumentOptions = {
|
||||||
documentId: number;
|
id: EnvelopeIdOptions;
|
||||||
sendEmail?: boolean;
|
sendEmail?: boolean;
|
||||||
isResealing?: boolean;
|
isResealing?: boolean;
|
||||||
requestMetadata?: RequestMetadata;
|
requestMetadata?: RequestMetadata;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const sealDocument = async ({
|
export const sealDocument = async ({
|
||||||
documentId,
|
id,
|
||||||
sendEmail = true,
|
sendEmail = true,
|
||||||
isResealing = false,
|
isResealing = false,
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
}: SealDocumentOptions) => {
|
}: SealDocumentOptions) => {
|
||||||
const document = await prisma.document.findFirstOrThrow({
|
const envelope = await prisma.envelope.findFirstOrThrow({
|
||||||
where: {
|
where: unsafeBuildEnvelopeIdQuery(id, EnvelopeType.DOCUMENT),
|
||||||
id: documentId,
|
|
||||||
},
|
|
||||||
include: {
|
include: {
|
||||||
documentData: true,
|
envelopeItems: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
documentData: true,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
field: {
|
||||||
|
include: {
|
||||||
|
signature: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
documentMeta: true,
|
documentMeta: true,
|
||||||
recipients: true,
|
recipients: {
|
||||||
},
|
where: {
|
||||||
});
|
role: {
|
||||||
|
not: RecipientRole.CC,
|
||||||
const { documentData } = document;
|
},
|
||||||
|
},
|
||||||
if (!documentData) {
|
|
||||||
throw new Error(`Document ${document.id} has no document data`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const settings = await getTeamSettings({
|
|
||||||
userId: document.userId,
|
|
||||||
teamId: document.teamId,
|
|
||||||
});
|
|
||||||
|
|
||||||
const recipients = await prisma.recipient.findMany({
|
|
||||||
where: {
|
|
||||||
documentId: document.id,
|
|
||||||
role: {
|
|
||||||
not: RecipientRole.CC,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Todo: Envelopes
|
||||||
|
const envelopeItemToSeal = envelope.envelopeItems[0];
|
||||||
|
|
||||||
|
// Todo: Envelopes
|
||||||
|
if (envelope.envelopeItems.length !== 1 || !envelopeItemToSeal) {
|
||||||
|
throw new Error(`Document ${envelope.id} needs exactly 1 envelope item`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const legacyDocumentId = mapSecondaryIdToDocumentId(envelope.secondaryId);
|
||||||
|
const documentData = envelopeItemToSeal.documentData;
|
||||||
|
const fields = envelopeItemToSeal.field; // Todo: Envelopes - This only takes in the first envelope item fields.
|
||||||
|
const recipients = envelope.recipients;
|
||||||
|
|
||||||
|
const settings = await getTeamSettings({
|
||||||
|
userId: envelope.userId,
|
||||||
|
teamId: envelope.teamId,
|
||||||
|
});
|
||||||
|
|
||||||
// Determine if the document has been rejected by checking if any recipient has rejected it
|
// Determine if the document has been rejected by checking if any recipient has rejected it
|
||||||
const rejectedRecipient = recipients.find(
|
const rejectedRecipient = recipients.find(
|
||||||
(recipient) => recipient.signingStatus === SigningStatus.REJECTED,
|
(recipient) => recipient.signingStatus === SigningStatus.REJECTED,
|
||||||
@ -88,21 +113,12 @@ export const sealDocument = async ({
|
|||||||
!isRejected &&
|
!isRejected &&
|
||||||
recipients.some((recipient) => recipient.signingStatus !== SigningStatus.SIGNED)
|
recipients.some((recipient) => recipient.signingStatus !== SigningStatus.SIGNED)
|
||||||
) {
|
) {
|
||||||
throw new Error(`Document ${document.id} has unsigned recipients`);
|
throw new Error(`Envelope ${envelope.id} has unsigned recipients`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const fields = await prisma.field.findMany({
|
|
||||||
where: {
|
|
||||||
documentId: document.id,
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
signature: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// Skip the field check if the document is rejected
|
// Skip the field check if the document is rejected
|
||||||
if (!isRejected && fieldsContainUnsignedRequiredField(fields)) {
|
if (!isRejected && fieldsContainUnsignedRequiredField(fields)) {
|
||||||
throw new Error(`Document ${document.id} has unsigned required fields`);
|
throw new Error(`Document ${envelope.id} has unsigned required fields`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isResealing) {
|
if (isResealing) {
|
||||||
@ -116,8 +132,8 @@ export const sealDocument = async ({
|
|||||||
|
|
||||||
const certificateData = settings.includeSigningCertificate
|
const certificateData = settings.includeSigningCertificate
|
||||||
? await getCertificatePdf({
|
? await getCertificatePdf({
|
||||||
documentId,
|
documentId: legacyDocumentId,
|
||||||
language: document.documentMeta?.language,
|
language: envelope.documentMeta.language,
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.log('Failed to get certificate PDF');
|
console.log('Failed to get certificate PDF');
|
||||||
console.error(e);
|
console.error(e);
|
||||||
@ -128,8 +144,8 @@ export const sealDocument = async ({
|
|||||||
|
|
||||||
const auditLogData = settings.includeAuditLog
|
const auditLogData = settings.includeAuditLog
|
||||||
? await getAuditLogsPdf({
|
? await getAuditLogsPdf({
|
||||||
documentId,
|
documentId: legacyDocumentId,
|
||||||
language: document.documentMeta?.language,
|
language: envelope.documentMeta.language,
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.log('Failed to get audit logs PDF');
|
console.log('Failed to get audit logs PDF');
|
||||||
console.error(e);
|
console.error(e);
|
||||||
@ -171,7 +187,7 @@ export const sealDocument = async ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const field of fields) {
|
for (const field of fields) {
|
||||||
document.useLegacyFieldInsertion
|
envelope.useLegacyFieldInsertion
|
||||||
? await legacy_insertFieldInPDF(doc, field)
|
? await legacy_insertFieldInPDF(doc, field)
|
||||||
: await insertFieldInPDF(doc, field);
|
: await insertFieldInPDF(doc, field);
|
||||||
}
|
}
|
||||||
@ -183,7 +199,8 @@ export const sealDocument = async ({
|
|||||||
|
|
||||||
const pdfBuffer = await signPdf({ pdf: Buffer.from(pdfBytes) });
|
const pdfBuffer = await signPdf({ pdf: Buffer.from(pdfBytes) });
|
||||||
|
|
||||||
const { name } = path.parse(document.title);
|
// Todo: Envelopes use EnvelopeItem title instead.
|
||||||
|
const { name } = path.parse(envelope.title);
|
||||||
|
|
||||||
// Add suffix based on document status
|
// Add suffix based on document status
|
||||||
const suffix = isRejected ? '_rejected.pdf' : '_signed.pdf';
|
const suffix = isRejected ? '_rejected.pdf' : '_signed.pdf';
|
||||||
@ -201,16 +218,16 @@ export const sealDocument = async ({
|
|||||||
distinctId: nanoid(),
|
distinctId: nanoid(),
|
||||||
event: 'App: Document Sealed',
|
event: 'App: Document Sealed',
|
||||||
properties: {
|
properties: {
|
||||||
documentId: document.id,
|
documentId: envelope.id,
|
||||||
isRejected,
|
isRejected,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await prisma.$transaction(async (tx) => {
|
await prisma.$transaction(async (tx) => {
|
||||||
await tx.document.update({
|
await tx.envelope.update({
|
||||||
where: {
|
where: {
|
||||||
id: document.id,
|
id: envelope.id,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
status: isRejected ? DocumentStatus.REJECTED : DocumentStatus.COMPLETED,
|
status: isRejected ? DocumentStatus.REJECTED : DocumentStatus.COMPLETED,
|
||||||
@ -230,7 +247,7 @@ export const sealDocument = async ({
|
|||||||
await tx.documentAuditLog.create({
|
await tx.documentAuditLog.create({
|
||||||
data: createDocumentAuditLogData({
|
data: createDocumentAuditLogData({
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_COMPLETED,
|
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_COMPLETED,
|
||||||
documentId: document.id,
|
envelopeId: envelope.id,
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
user: null,
|
user: null,
|
||||||
data: {
|
data: {
|
||||||
@ -242,15 +259,14 @@ export const sealDocument = async ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (sendEmail && !isResealing) {
|
if (sendEmail && !isResealing) {
|
||||||
await sendCompletedEmail({ documentId, requestMetadata });
|
await sendCompletedEmail({ id, requestMetadata });
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedDocument = await prisma.document.findFirstOrThrow({
|
const updatedDocument = await prisma.envelope.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
id: document.id,
|
id: envelope.id,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
documentData: true,
|
|
||||||
documentMeta: true,
|
documentMeta: true,
|
||||||
recipients: true,
|
recipients: true,
|
||||||
},
|
},
|
||||||
@ -260,8 +276,8 @@ export const sealDocument = async ({
|
|||||||
event: isRejected
|
event: isRejected
|
||||||
? WebhookTriggerEvents.DOCUMENT_REJECTED
|
? WebhookTriggerEvents.DOCUMENT_REJECTED
|
||||||
: WebhookTriggerEvents.DOCUMENT_COMPLETED,
|
: WebhookTriggerEvents.DOCUMENT_COMPLETED,
|
||||||
data: ZWebhookDocumentSchema.parse(mapDocumentToWebhookDocumentPayload(updatedDocument)),
|
data: ZWebhookDocumentSchema.parse(mapEnvelopeToWebhookDocumentPayload(updatedDocument)),
|
||||||
userId: document.userId,
|
userId: envelope.userId,
|
||||||
teamId: document.teamId ?? undefined,
|
teamId: envelope.teamId ?? undefined,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import type { Document, Recipient, User } from '@prisma/client';
|
import { DocumentStatus, EnvelopeType } from '@prisma/client';
|
||||||
import { DocumentStatus, DocumentVisibility, TeamMemberRole } from '@prisma/client';
|
import type { Envelope, Recipient, User } from '@prisma/client';
|
||||||
|
import { DocumentVisibility, TeamMemberRole } from '@prisma/client';
|
||||||
import { match } from 'ts-pattern';
|
import { match } from 'ts-pattern';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -9,6 +10,8 @@ import {
|
|||||||
} from '@documenso/lib/utils/teams';
|
} from '@documenso/lib/utils/teams';
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
|
import { mapSecondaryIdToDocumentId } from '../../utils/envelope';
|
||||||
|
|
||||||
export type SearchDocumentsWithKeywordOptions = {
|
export type SearchDocumentsWithKeywordOptions = {
|
||||||
query: string;
|
query: string;
|
||||||
userId: number;
|
userId: number;
|
||||||
@ -26,8 +29,9 @@ export const searchDocumentsWithKeyword = async ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const documents = await prisma.document.findMany({
|
const envelopes = await prisma.envelope.findMany({
|
||||||
where: {
|
where: {
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
OR: [
|
OR: [
|
||||||
{
|
{
|
||||||
title: {
|
title: {
|
||||||
@ -128,26 +132,26 @@ export const searchDocumentsWithKeyword = async ({
|
|||||||
take: limit,
|
take: limit,
|
||||||
});
|
});
|
||||||
|
|
||||||
const isOwner = (document: Document, user: User) => document.userId === user.id;
|
const isOwner = (envelope: Envelope, user: User) => envelope.userId === user.id;
|
||||||
|
|
||||||
const getSigningLink = (recipients: Recipient[], user: User) =>
|
const getSigningLink = (recipients: Recipient[], user: User) =>
|
||||||
`/sign/${recipients.find((r) => r.email === user.email)?.token}`;
|
`/sign/${recipients.find((r) => r.email === user.email)?.token}`;
|
||||||
|
|
||||||
const maskedDocuments = documents
|
const maskedDocuments = envelopes
|
||||||
.filter((document) => {
|
.filter((envelope) => {
|
||||||
if (!document.teamId || isOwner(document, user)) {
|
if (!envelope.teamId || isOwner(envelope, user)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const teamMemberRole = getHighestTeamRoleInGroup(
|
const teamMemberRole = getHighestTeamRoleInGroup(
|
||||||
document.team.teamGroups.filter((tg) => tg.teamId === document.teamId),
|
envelope.team.teamGroups.filter((tg) => tg.teamId === envelope.teamId),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!teamMemberRole) {
|
if (!teamMemberRole) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const canAccessDocument = match([document.visibility, teamMemberRole])
|
const canAccessDocument = match([envelope.visibility, teamMemberRole])
|
||||||
.with([DocumentVisibility.EVERYONE, TeamMemberRole.ADMIN], () => true)
|
.with([DocumentVisibility.EVERYONE, TeamMemberRole.ADMIN], () => true)
|
||||||
.with([DocumentVisibility.EVERYONE, TeamMemberRole.MANAGER], () => true)
|
.with([DocumentVisibility.EVERYONE, TeamMemberRole.MANAGER], () => true)
|
||||||
.with([DocumentVisibility.EVERYONE, TeamMemberRole.MEMBER], () => true)
|
.with([DocumentVisibility.EVERYONE, TeamMemberRole.MEMBER], () => true)
|
||||||
@ -158,23 +162,29 @@ export const searchDocumentsWithKeyword = async ({
|
|||||||
|
|
||||||
return canAccessDocument;
|
return canAccessDocument;
|
||||||
})
|
})
|
||||||
.map((document) => {
|
.map((envelope) => {
|
||||||
const { recipients, ...documentWithoutRecipient } = document;
|
const { recipients, ...documentWithoutRecipient } = envelope;
|
||||||
|
|
||||||
let documentPath;
|
let documentPath;
|
||||||
|
|
||||||
if (isOwner(document, user)) {
|
const legacyDocumentId = mapSecondaryIdToDocumentId(envelope.secondaryId);
|
||||||
documentPath = `${formatDocumentsPath(document.team?.url)}/${document.id}`;
|
|
||||||
} else if (document.teamId && document.team.teamGroups.length > 0) {
|
if (isOwner(envelope, user)) {
|
||||||
documentPath = `${formatDocumentsPath(document.team.url)}/${document.id}`;
|
documentPath = `${formatDocumentsPath(envelope.team.url)}/${legacyDocumentId}`;
|
||||||
|
} else if (envelope.teamId && envelope.team.teamGroups.length > 0) {
|
||||||
|
documentPath = `${formatDocumentsPath(envelope.team.url)}/${legacyDocumentId}`;
|
||||||
} else {
|
} else {
|
||||||
documentPath = getSigningLink(recipients, user);
|
documentPath = getSigningLink(recipients, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...documentWithoutRecipient,
|
...documentWithoutRecipient,
|
||||||
|
team: {
|
||||||
|
id: envelope.teamId,
|
||||||
|
url: envelope.team.url,
|
||||||
|
},
|
||||||
path: documentPath,
|
path: documentPath,
|
||||||
value: [document.id, document.title, ...document.recipients.map((r) => r.email)].join(' '),
|
value: [envelope.id, envelope.title, ...envelope.recipients.map((r) => r.email)].join(' '),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { createElement } from 'react';
|
import { createElement } from 'react';
|
||||||
|
|
||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { DocumentSource } from '@prisma/client';
|
import { DocumentSource, EnvelopeType } from '@prisma/client';
|
||||||
|
|
||||||
import { mailer } from '@documenso/email/mailer';
|
import { mailer } from '@documenso/email/mailer';
|
||||||
import { DocumentCompletedEmailTemplate } from '@documenso/email/templates/document-completed';
|
import { DocumentCompletedEmailTemplate } from '@documenso/email/templates/document-completed';
|
||||||
@ -14,23 +14,33 @@ import { extractDerivedDocumentEmailSettings } from '../../types/document-email'
|
|||||||
import type { RequestMetadata } from '../../universal/extract-request-metadata';
|
import type { RequestMetadata } from '../../universal/extract-request-metadata';
|
||||||
import { getFileServerSide } from '../../universal/upload/get-file.server';
|
import { getFileServerSide } from '../../universal/upload/get-file.server';
|
||||||
import { createDocumentAuditLogData } from '../../utils/document-audit-logs';
|
import { createDocumentAuditLogData } from '../../utils/document-audit-logs';
|
||||||
|
import type { EnvelopeIdOptions } from '../../utils/envelope';
|
||||||
|
import { unsafeBuildEnvelopeIdQuery } from '../../utils/envelope';
|
||||||
import { renderCustomEmailTemplate } from '../../utils/render-custom-email-template';
|
import { renderCustomEmailTemplate } from '../../utils/render-custom-email-template';
|
||||||
import { renderEmailWithI18N } from '../../utils/render-email-with-i18n';
|
import { renderEmailWithI18N } from '../../utils/render-email-with-i18n';
|
||||||
import { formatDocumentsPath } from '../../utils/teams';
|
import { formatDocumentsPath } from '../../utils/teams';
|
||||||
import { getEmailContext } from '../email/get-email-context';
|
import { getEmailContext } from '../email/get-email-context';
|
||||||
|
|
||||||
export interface SendDocumentOptions {
|
export interface SendDocumentOptions {
|
||||||
documentId: number;
|
id: EnvelopeIdOptions;
|
||||||
requestMetadata?: RequestMetadata;
|
requestMetadata?: RequestMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const sendCompletedEmail = async ({ documentId, requestMetadata }: SendDocumentOptions) => {
|
export const sendCompletedEmail = async ({ id, requestMetadata }: SendDocumentOptions) => {
|
||||||
const document = await prisma.document.findUnique({
|
const envelope = await prisma.envelope.findUnique({
|
||||||
where: {
|
where: unsafeBuildEnvelopeIdQuery(id, EnvelopeType.DOCUMENT),
|
||||||
id: documentId,
|
|
||||||
},
|
|
||||||
include: {
|
include: {
|
||||||
documentData: true,
|
envelopeItems: {
|
||||||
|
include: {
|
||||||
|
documentData: {
|
||||||
|
select: {
|
||||||
|
type: true,
|
||||||
|
id: true,
|
||||||
|
data: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
documentMeta: true,
|
documentMeta: true,
|
||||||
recipients: true,
|
recipients: true,
|
||||||
user: {
|
user: {
|
||||||
@ -49,13 +59,13 @@ export const sendCompletedEmail = async ({ documentId, requestMetadata }: SendDo
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!document) {
|
if (!envelope) {
|
||||||
throw new Error('Document not found');
|
throw new Error('Document not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
const isDirectTemplate = document?.source === DocumentSource.TEMPLATE_DIRECT_LINK;
|
const isDirectTemplate = envelope?.source === DocumentSource.TEMPLATE_DIRECT_LINK;
|
||||||
|
|
||||||
if (document.recipients.length === 0) {
|
if (envelope.recipients.length === 0) {
|
||||||
throw new Error('Document has no recipients');
|
throw new Error('Document has no recipients');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,28 +73,37 @@ export const sendCompletedEmail = async ({ documentId, requestMetadata }: SendDo
|
|||||||
emailType: 'RECIPIENT',
|
emailType: 'RECIPIENT',
|
||||||
source: {
|
source: {
|
||||||
type: 'team',
|
type: 'team',
|
||||||
teamId: document.teamId,
|
teamId: envelope.teamId,
|
||||||
},
|
},
|
||||||
meta: document.documentMeta,
|
meta: envelope.documentMeta,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { user: owner } = document;
|
const { user: owner } = envelope;
|
||||||
|
|
||||||
const completedDocument = await getFileServerSide(document.documentData);
|
const completedDocumentEmailAttachments = await Promise.all(
|
||||||
|
envelope.envelopeItems.map(async (document) => {
|
||||||
|
const file = await getFileServerSide(document.documentData);
|
||||||
|
|
||||||
|
return {
|
||||||
|
fileName: document.title.endsWith('.pdf') ? document.title : document.title + '.pdf',
|
||||||
|
content: Buffer.from(file),
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
const assetBaseUrl = NEXT_PUBLIC_WEBAPP_URL() || 'http://localhost:3000';
|
const assetBaseUrl = NEXT_PUBLIC_WEBAPP_URL() || 'http://localhost:3000';
|
||||||
|
|
||||||
let documentOwnerDownloadLink = `${NEXT_PUBLIC_WEBAPP_URL()}${formatDocumentsPath(
|
let documentOwnerDownloadLink = `${NEXT_PUBLIC_WEBAPP_URL()}${formatDocumentsPath(
|
||||||
document.team?.url,
|
envelope.team?.url,
|
||||||
)}/${document.id}`;
|
)}/${envelope.id}`;
|
||||||
|
|
||||||
if (document.team?.url) {
|
if (envelope.team?.url) {
|
||||||
documentOwnerDownloadLink = `${NEXT_PUBLIC_WEBAPP_URL()}/t/${document.team.url}/documents/${
|
documentOwnerDownloadLink = `${NEXT_PUBLIC_WEBAPP_URL()}/t/${envelope.team.url}/documents/${
|
||||||
document.id
|
envelope.id
|
||||||
}`;
|
}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const emailSettings = extractDerivedDocumentEmailSettings(document.documentMeta);
|
const emailSettings = extractDerivedDocumentEmailSettings(envelope.documentMeta);
|
||||||
const isDocumentCompletedEmailEnabled = emailSettings.documentCompleted;
|
const isDocumentCompletedEmailEnabled = emailSettings.documentCompleted;
|
||||||
const isOwnerDocumentCompletedEmailEnabled = emailSettings.ownerDocumentCompleted;
|
const isOwnerDocumentCompletedEmailEnabled = emailSettings.ownerDocumentCompleted;
|
||||||
|
|
||||||
@ -95,11 +114,11 @@ export const sendCompletedEmail = async ({ documentId, requestMetadata }: SendDo
|
|||||||
// - Recipient emails are disabled
|
// - Recipient emails are disabled
|
||||||
if (
|
if (
|
||||||
isOwnerDocumentCompletedEmailEnabled &&
|
isOwnerDocumentCompletedEmailEnabled &&
|
||||||
(!document.recipients.find((recipient) => recipient.email === owner.email) ||
|
(!envelope.recipients.find((recipient) => recipient.email === owner.email) ||
|
||||||
!isDocumentCompletedEmailEnabled)
|
!isDocumentCompletedEmailEnabled)
|
||||||
) {
|
) {
|
||||||
const template = createElement(DocumentCompletedEmailTemplate, {
|
const template = createElement(DocumentCompletedEmailTemplate, {
|
||||||
documentName: document.title,
|
documentName: envelope.title,
|
||||||
assetBaseUrl,
|
assetBaseUrl,
|
||||||
downloadLink: documentOwnerDownloadLink,
|
downloadLink: documentOwnerDownloadLink,
|
||||||
});
|
});
|
||||||
@ -127,18 +146,13 @@ export const sendCompletedEmail = async ({ documentId, requestMetadata }: SendDo
|
|||||||
subject: i18n._(msg`Signing Complete!`),
|
subject: i18n._(msg`Signing Complete!`),
|
||||||
html,
|
html,
|
||||||
text,
|
text,
|
||||||
attachments: [
|
attachments: completedDocumentEmailAttachments,
|
||||||
{
|
|
||||||
filename: document.title.endsWith('.pdf') ? document.title : document.title + '.pdf',
|
|
||||||
content: Buffer.from(completedDocument),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await prisma.documentAuditLog.create({
|
await prisma.documentAuditLog.create({
|
||||||
data: createDocumentAuditLogData({
|
data: createDocumentAuditLogData({
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.EMAIL_SENT,
|
type: DOCUMENT_AUDIT_LOG_TYPE.EMAIL_SENT,
|
||||||
documentId: document.id,
|
envelopeId: envelope.id,
|
||||||
user: null,
|
user: null,
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
data: {
|
data: {
|
||||||
@ -158,22 +172,22 @@ export const sendCompletedEmail = async ({ documentId, requestMetadata }: SendDo
|
|||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
document.recipients.map(async (recipient) => {
|
envelope.recipients.map(async (recipient) => {
|
||||||
const customEmailTemplate = {
|
const customEmailTemplate = {
|
||||||
'signer.name': recipient.name,
|
'signer.name': recipient.name,
|
||||||
'signer.email': recipient.email,
|
'signer.email': recipient.email,
|
||||||
'document.name': document.title,
|
'document.name': envelope.title,
|
||||||
};
|
};
|
||||||
|
|
||||||
const downloadLink = `${NEXT_PUBLIC_WEBAPP_URL()}/sign/${recipient.token}/complete`;
|
const downloadLink = `${NEXT_PUBLIC_WEBAPP_URL()}/sign/${recipient.token}/complete`;
|
||||||
|
|
||||||
const template = createElement(DocumentCompletedEmailTemplate, {
|
const template = createElement(DocumentCompletedEmailTemplate, {
|
||||||
documentName: document.title,
|
documentName: envelope.title,
|
||||||
assetBaseUrl,
|
assetBaseUrl,
|
||||||
downloadLink: recipient.email === owner.email ? documentOwnerDownloadLink : downloadLink,
|
downloadLink: recipient.email === owner.email ? documentOwnerDownloadLink : downloadLink,
|
||||||
customBody:
|
customBody:
|
||||||
isDirectTemplate && document.documentMeta?.message
|
isDirectTemplate && envelope.documentMeta?.message
|
||||||
? renderCustomEmailTemplate(document.documentMeta.message, customEmailTemplate)
|
? renderCustomEmailTemplate(envelope.documentMeta.message, customEmailTemplate)
|
||||||
: undefined,
|
: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -198,23 +212,18 @@ export const sendCompletedEmail = async ({ documentId, requestMetadata }: SendDo
|
|||||||
from: senderEmail,
|
from: senderEmail,
|
||||||
replyTo: replyToEmail,
|
replyTo: replyToEmail,
|
||||||
subject:
|
subject:
|
||||||
isDirectTemplate && document.documentMeta?.subject
|
isDirectTemplate && envelope.documentMeta?.subject
|
||||||
? renderCustomEmailTemplate(document.documentMeta.subject, customEmailTemplate)
|
? renderCustomEmailTemplate(envelope.documentMeta.subject, customEmailTemplate)
|
||||||
: i18n._(msg`Signing Complete!`),
|
: i18n._(msg`Signing Complete!`),
|
||||||
html,
|
html,
|
||||||
text,
|
text,
|
||||||
attachments: [
|
attachments: completedDocumentEmailAttachments,
|
||||||
{
|
|
||||||
filename: document.title.endsWith('.pdf') ? document.title : document.title + '.pdf',
|
|
||||||
content: Buffer.from(completedDocument),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await prisma.documentAuditLog.create({
|
await prisma.documentAuditLog.create({
|
||||||
data: createDocumentAuditLogData({
|
data: createDocumentAuditLogData({
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.EMAIL_SENT,
|
type: DOCUMENT_AUDIT_LOG_TYPE.EMAIL_SENT,
|
||||||
documentId: document.id,
|
envelopeId: envelope.id,
|
||||||
user: null,
|
user: null,
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
@ -14,14 +14,15 @@ import { renderEmailWithI18N } from '../../utils/render-email-with-i18n';
|
|||||||
import { getEmailContext } from '../email/get-email-context';
|
import { getEmailContext } from '../email/get-email-context';
|
||||||
|
|
||||||
export interface SendDeleteEmailOptions {
|
export interface SendDeleteEmailOptions {
|
||||||
documentId: number;
|
envelopeId: string;
|
||||||
reason: string;
|
reason: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const sendDeleteEmail = async ({ documentId, reason }: SendDeleteEmailOptions) => {
|
// Note: Currently only sent by Admin function
|
||||||
const document = await prisma.document.findFirst({
|
export const sendDeleteEmail = async ({ envelopeId, reason }: SendDeleteEmailOptions) => {
|
||||||
|
const envelope = await prisma.envelope.findFirst({
|
||||||
where: {
|
where: {
|
||||||
id: documentId,
|
id: envelopeId,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
user: {
|
user: {
|
||||||
@ -35,14 +36,14 @@ export const sendDeleteEmail = async ({ documentId, reason }: SendDeleteEmailOpt
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!document) {
|
if (!envelope) {
|
||||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||||
message: 'Document not found',
|
message: 'Document not found',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const isDocumentDeletedEmailEnabled = extractDerivedDocumentEmailSettings(
|
const isDocumentDeletedEmailEnabled = extractDerivedDocumentEmailSettings(
|
||||||
document.documentMeta,
|
envelope.documentMeta,
|
||||||
).documentDeleted;
|
).documentDeleted;
|
||||||
|
|
||||||
if (!isDocumentDeletedEmailEnabled) {
|
if (!isDocumentDeletedEmailEnabled) {
|
||||||
@ -53,17 +54,17 @@ export const sendDeleteEmail = async ({ documentId, reason }: SendDeleteEmailOpt
|
|||||||
emailType: 'INTERNAL',
|
emailType: 'INTERNAL',
|
||||||
source: {
|
source: {
|
||||||
type: 'team',
|
type: 'team',
|
||||||
teamId: document.teamId,
|
teamId: envelope.teamId,
|
||||||
},
|
},
|
||||||
meta: document.documentMeta,
|
meta: envelope.documentMeta,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { email, name } = document.user;
|
const { email, name } = envelope.user;
|
||||||
|
|
||||||
const assetBaseUrl = NEXT_PUBLIC_WEBAPP_URL() || 'http://localhost:3000';
|
const assetBaseUrl = NEXT_PUBLIC_WEBAPP_URL() || 'http://localhost:3000';
|
||||||
|
|
||||||
const template = createElement(DocumentSuperDeleteEmailTemplate, {
|
const template = createElement(DocumentSuperDeleteEmailTemplate, {
|
||||||
documentName: document.title,
|
documentName: envelope.title,
|
||||||
reason,
|
reason,
|
||||||
assetBaseUrl,
|
assetBaseUrl,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
DocumentSigningOrder,
|
DocumentSigningOrder,
|
||||||
DocumentStatus,
|
DocumentStatus,
|
||||||
|
EnvelopeType,
|
||||||
RecipientRole,
|
RecipientRole,
|
||||||
SendStatus,
|
SendStatus,
|
||||||
SigningStatus,
|
SigningStatus,
|
||||||
@ -16,17 +17,18 @@ import { jobs } from '../../jobs/client';
|
|||||||
import { extractDerivedDocumentEmailSettings } from '../../types/document-email';
|
import { extractDerivedDocumentEmailSettings } from '../../types/document-email';
|
||||||
import {
|
import {
|
||||||
ZWebhookDocumentSchema,
|
ZWebhookDocumentSchema,
|
||||||
mapDocumentToWebhookDocumentPayload,
|
mapEnvelopeToWebhookDocumentPayload,
|
||||||
} from '../../types/webhook-payload';
|
} from '../../types/webhook-payload';
|
||||||
import { getFileServerSide } from '../../universal/upload/get-file.server';
|
import { getFileServerSide } from '../../universal/upload/get-file.server';
|
||||||
import { putPdfFileServerSide } from '../../universal/upload/put-file.server';
|
import { putPdfFileServerSide } from '../../universal/upload/put-file.server';
|
||||||
import { isDocumentCompleted } from '../../utils/document';
|
import { isDocumentCompleted } from '../../utils/document';
|
||||||
|
import { type EnvelopeIdOptions, mapSecondaryIdToDocumentId } from '../../utils/envelope';
|
||||||
|
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||||
import { insertFormValuesInPdf } from '../pdf/insert-form-values-in-pdf';
|
import { insertFormValuesInPdf } from '../pdf/insert-form-values-in-pdf';
|
||||||
import { triggerWebhook } from '../webhooks/trigger/trigger-webhook';
|
import { triggerWebhook } from '../webhooks/trigger/trigger-webhook';
|
||||||
import { getDocumentWhereInput } from './get-document-by-id';
|
|
||||||
|
|
||||||
export type SendDocumentOptions = {
|
export type SendDocumentOptions = {
|
||||||
documentId: number;
|
id: EnvelopeIdOptions;
|
||||||
userId: number;
|
userId: number;
|
||||||
teamId: number;
|
teamId: number;
|
||||||
sendEmail?: boolean;
|
sendEmail?: boolean;
|
||||||
@ -34,75 +36,92 @@ export type SendDocumentOptions = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const sendDocument = async ({
|
export const sendDocument = async ({
|
||||||
documentId,
|
id,
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
sendEmail,
|
sendEmail,
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
}: SendDocumentOptions) => {
|
}: SendDocumentOptions) => {
|
||||||
const { documentWhereInput } = await getDocumentWhereInput({
|
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
||||||
documentId,
|
id,
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const document = await prisma.document.findFirst({
|
const envelope = await prisma.envelope.findFirst({
|
||||||
where: documentWhereInput,
|
where: envelopeWhereInput,
|
||||||
include: {
|
include: {
|
||||||
recipients: {
|
recipients: {
|
||||||
orderBy: [{ signingOrder: { sort: 'asc', nulls: 'last' } }, { id: 'asc' }],
|
orderBy: [{ signingOrder: { sort: 'asc', nulls: 'last' } }, { id: 'asc' }],
|
||||||
},
|
},
|
||||||
documentMeta: true,
|
documentMeta: true,
|
||||||
documentData: true,
|
envelopeItems: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
documentData: {
|
||||||
|
select: {
|
||||||
|
type: true,
|
||||||
|
id: true,
|
||||||
|
data: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!document) {
|
if (!envelope) {
|
||||||
throw new Error('Document not found');
|
throw new Error('Document not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document.recipients.length === 0) {
|
if (envelope.recipients.length === 0) {
|
||||||
throw new Error('Document has no recipients');
|
throw new Error('Document has no recipients');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDocumentCompleted(document.status)) {
|
if (isDocumentCompleted(envelope.status)) {
|
||||||
throw new Error('Can not send completed document');
|
throw new Error('Can not send completed document');
|
||||||
}
|
}
|
||||||
|
|
||||||
const signingOrder = document.documentMeta?.signingOrder || DocumentSigningOrder.PARALLEL;
|
const legacyDocumentId = mapSecondaryIdToDocumentId(envelope.secondaryId);
|
||||||
|
|
||||||
let recipientsToNotify = document.recipients;
|
const signingOrder = envelope.documentMeta?.signingOrder || DocumentSigningOrder.PARALLEL;
|
||||||
|
|
||||||
|
let recipientsToNotify = envelope.recipients;
|
||||||
|
|
||||||
if (signingOrder === DocumentSigningOrder.SEQUENTIAL) {
|
if (signingOrder === DocumentSigningOrder.SEQUENTIAL) {
|
||||||
// Get the currently active recipient.
|
// Get the currently active recipient.
|
||||||
recipientsToNotify = document.recipients
|
recipientsToNotify = envelope.recipients
|
||||||
.filter((r) => r.signingStatus === SigningStatus.NOT_SIGNED && r.role !== RecipientRole.CC)
|
.filter((r) => r.signingStatus === SigningStatus.NOT_SIGNED && r.role !== RecipientRole.CC)
|
||||||
.slice(0, 1);
|
.slice(0, 1);
|
||||||
|
|
||||||
// Secondary filter so we aren't resending if the current active recipient has already
|
// Secondary filter so we aren't resending if the current active recipient has already
|
||||||
// received the document.
|
// received the envelope.
|
||||||
recipientsToNotify.filter((r) => r.sendStatus !== SendStatus.SENT);
|
recipientsToNotify.filter((r) => r.sendStatus !== SendStatus.SENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { documentData } = document;
|
const envelopeItem = envelope.envelopeItems[0];
|
||||||
|
const documentData = envelopeItem?.documentData;
|
||||||
|
|
||||||
if (!documentData.data) {
|
// Todo: Envelopes
|
||||||
throw new Error('Document data not found');
|
if (!envelopeItem || !documentData || envelope.envelopeItems.length !== 1) {
|
||||||
|
throw new Error('Invalid document data');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document.formValues) {
|
// Todo: Envelopes need to support multiple envelope items.
|
||||||
|
if (envelope.formValues) {
|
||||||
const file = await getFileServerSide(documentData);
|
const file = await getFileServerSide(documentData);
|
||||||
|
|
||||||
const prefilled = await insertFormValuesInPdf({
|
const prefilled = await insertFormValuesInPdf({
|
||||||
pdf: Buffer.from(file),
|
pdf: Buffer.from(file),
|
||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||||
formValues: document.formValues as Record<string, string | number | boolean>,
|
formValues: envelope.formValues as Record<string, string | number | boolean>,
|
||||||
});
|
});
|
||||||
|
|
||||||
let fileName = document.title;
|
let fileName = envelope.title;
|
||||||
|
|
||||||
if (!document.title.endsWith('.pdf')) {
|
if (!envelope.title.endsWith('.pdf')) {
|
||||||
fileName = `${document.title}.pdf`;
|
fileName = `${envelope.title}.pdf`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newDocumentData = await putPdfFileServerSide({
|
const newDocumentData = await putPdfFileServerSide({
|
||||||
@ -111,9 +130,9 @@ export const sendDocument = async ({
|
|||||||
arrayBuffer: async () => Promise.resolve(prefilled),
|
arrayBuffer: async () => Promise.resolve(prefilled),
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await prisma.document.update({
|
const result = await prisma.envelopeItem.update({
|
||||||
where: {
|
where: {
|
||||||
id: document.id,
|
id: envelopeItem.id,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
documentDataId: newDocumentData.id,
|
documentDataId: newDocumentData.id,
|
||||||
@ -133,7 +152,7 @@ export const sendDocument = async ({
|
|||||||
// const fieldsWithSignerEmail = fields.map((field) => ({
|
// const fieldsWithSignerEmail = fields.map((field) => ({
|
||||||
// ...field,
|
// ...field,
|
||||||
// signerEmail:
|
// signerEmail:
|
||||||
// document.Recipient.find((recipient) => recipient.id === field.recipientId)?.email ?? '',
|
// envelope.Recipient.find((recipient) => recipient.id === field.recipientId)?.email ?? '',
|
||||||
// }));
|
// }));
|
||||||
|
|
||||||
// const everySignerHasSignature = document?.Recipient.every(
|
// const everySignerHasSignature = document?.Recipient.every(
|
||||||
@ -148,7 +167,7 @@ export const sendDocument = async ({
|
|||||||
// throw new Error('Some signers have not been assigned a signature field.');
|
// throw new Error('Some signers have not been assigned a signature field.');
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const allRecipientsHaveNoActionToTake = document.recipients.every(
|
const allRecipientsHaveNoActionToTake = envelope.recipients.every(
|
||||||
(recipient) =>
|
(recipient) =>
|
||||||
recipient.role === RecipientRole.CC || recipient.signingStatus === SigningStatus.SIGNED,
|
recipient.role === RecipientRole.CC || recipient.signingStatus === SigningStatus.SIGNED,
|
||||||
);
|
);
|
||||||
@ -157,15 +176,15 @@ export const sendDocument = async ({
|
|||||||
await jobs.triggerJob({
|
await jobs.triggerJob({
|
||||||
name: 'internal.seal-document',
|
name: 'internal.seal-document',
|
||||||
payload: {
|
payload: {
|
||||||
documentId,
|
documentId: legacyDocumentId,
|
||||||
requestMetadata: requestMetadata?.requestMetadata,
|
requestMetadata: requestMetadata?.requestMetadata,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Keep the return type the same for the `sendDocument` method
|
// Keep the return type the same for the `sendDocument` method
|
||||||
return await prisma.document.findFirstOrThrow({
|
return await prisma.envelope.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
id: documentId,
|
id: envelope.id,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
documentMeta: true,
|
documentMeta: true,
|
||||||
@ -174,21 +193,21 @@ export const sendDocument = async ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedDocument = await prisma.$transaction(async (tx) => {
|
const updatedEnvelope = await prisma.$transaction(async (tx) => {
|
||||||
if (document.status === DocumentStatus.DRAFT) {
|
if (envelope.status === DocumentStatus.DRAFT) {
|
||||||
await tx.documentAuditLog.create({
|
await tx.documentAuditLog.create({
|
||||||
data: createDocumentAuditLogData({
|
data: createDocumentAuditLogData({
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_SENT,
|
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_SENT,
|
||||||
documentId: document.id,
|
envelopeId: envelope.id,
|
||||||
metadata: requestMetadata,
|
metadata: requestMetadata,
|
||||||
data: {},
|
data: {},
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return await tx.document.update({
|
return await tx.envelope.update({
|
||||||
where: {
|
where: {
|
||||||
id: documentId,
|
id: envelope.id,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
status: DocumentStatus.PENDING,
|
status: DocumentStatus.PENDING,
|
||||||
@ -201,7 +220,7 @@ export const sendDocument = async ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const isRecipientSigningRequestEmailEnabled = extractDerivedDocumentEmailSettings(
|
const isRecipientSigningRequestEmailEnabled = extractDerivedDocumentEmailSettings(
|
||||||
document.documentMeta,
|
envelope.documentMeta,
|
||||||
).recipientSigningRequest;
|
).recipientSigningRequest;
|
||||||
|
|
||||||
// Only send email if one of the following is true:
|
// Only send email if one of the following is true:
|
||||||
@ -218,7 +237,7 @@ export const sendDocument = async ({
|
|||||||
name: 'send.signing.requested.email',
|
name: 'send.signing.requested.email',
|
||||||
payload: {
|
payload: {
|
||||||
userId,
|
userId,
|
||||||
documentId,
|
documentId: legacyDocumentId,
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
requestMetadata: requestMetadata?.requestMetadata,
|
requestMetadata: requestMetadata?.requestMetadata,
|
||||||
},
|
},
|
||||||
@ -229,10 +248,10 @@ export const sendDocument = async ({
|
|||||||
|
|
||||||
await triggerWebhook({
|
await triggerWebhook({
|
||||||
event: WebhookTriggerEvents.DOCUMENT_SENT,
|
event: WebhookTriggerEvents.DOCUMENT_SENT,
|
||||||
data: ZWebhookDocumentSchema.parse(mapDocumentToWebhookDocumentPayload(updatedDocument)),
|
data: ZWebhookDocumentSchema.parse(mapEnvelopeToWebhookDocumentPayload(updatedEnvelope)),
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
});
|
});
|
||||||
|
|
||||||
return updatedDocument;
|
return updatedEnvelope;
|
||||||
};
|
};
|
||||||
@ -1,6 +1,7 @@
|
|||||||
import { createElement } from 'react';
|
import { createElement } from 'react';
|
||||||
|
|
||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
|
import { EnvelopeType } from '@prisma/client';
|
||||||
|
|
||||||
import { mailer } from '@documenso/email/mailer';
|
import { mailer } from '@documenso/email/mailer';
|
||||||
import { DocumentPendingEmailTemplate } from '@documenso/email/templates/document-pending';
|
import { DocumentPendingEmailTemplate } from '@documenso/email/templates/document-pending';
|
||||||
@ -9,18 +10,20 @@ import { prisma } from '@documenso/prisma';
|
|||||||
import { getI18nInstance } from '../../client-only/providers/i18n-server';
|
import { getI18nInstance } from '../../client-only/providers/i18n-server';
|
||||||
import { NEXT_PUBLIC_WEBAPP_URL } from '../../constants/app';
|
import { NEXT_PUBLIC_WEBAPP_URL } from '../../constants/app';
|
||||||
import { extractDerivedDocumentEmailSettings } from '../../types/document-email';
|
import { extractDerivedDocumentEmailSettings } from '../../types/document-email';
|
||||||
|
import type { EnvelopeIdOptions } from '../../utils/envelope';
|
||||||
|
import { unsafeBuildEnvelopeIdQuery } from '../../utils/envelope';
|
||||||
import { renderEmailWithI18N } from '../../utils/render-email-with-i18n';
|
import { renderEmailWithI18N } from '../../utils/render-email-with-i18n';
|
||||||
import { getEmailContext } from '../email/get-email-context';
|
import { getEmailContext } from '../email/get-email-context';
|
||||||
|
|
||||||
export interface SendPendingEmailOptions {
|
export interface SendPendingEmailOptions {
|
||||||
documentId: number;
|
id: EnvelopeIdOptions;
|
||||||
recipientId: number;
|
recipientId: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const sendPendingEmail = async ({ documentId, recipientId }: SendPendingEmailOptions) => {
|
export const sendPendingEmail = async ({ id, recipientId }: SendPendingEmailOptions) => {
|
||||||
const document = await prisma.document.findFirst({
|
const envelope = await prisma.envelope.findFirst({
|
||||||
where: {
|
where: {
|
||||||
id: documentId,
|
...unsafeBuildEnvelopeIdQuery(id, EnvelopeType.DOCUMENT),
|
||||||
recipients: {
|
recipients: {
|
||||||
some: {
|
some: {
|
||||||
id: recipientId,
|
id: recipientId,
|
||||||
@ -37,11 +40,11 @@ export const sendPendingEmail = async ({ documentId, recipientId }: SendPendingE
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!document) {
|
if (!envelope) {
|
||||||
throw new Error('Document not found');
|
throw new Error('Document not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document.recipients.length === 0) {
|
if (envelope.recipients.length === 0) {
|
||||||
throw new Error('Document has no recipients');
|
throw new Error('Document has no recipients');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,27 +52,27 @@ export const sendPendingEmail = async ({ documentId, recipientId }: SendPendingE
|
|||||||
emailType: 'RECIPIENT',
|
emailType: 'RECIPIENT',
|
||||||
source: {
|
source: {
|
||||||
type: 'team',
|
type: 'team',
|
||||||
teamId: document.teamId,
|
teamId: envelope.teamId,
|
||||||
},
|
},
|
||||||
meta: document.documentMeta,
|
meta: envelope.documentMeta,
|
||||||
});
|
});
|
||||||
|
|
||||||
const isDocumentPendingEmailEnabled = extractDerivedDocumentEmailSettings(
|
const isDocumentPendingEmailEnabled = extractDerivedDocumentEmailSettings(
|
||||||
document.documentMeta,
|
envelope.documentMeta,
|
||||||
).documentPending;
|
).documentPending;
|
||||||
|
|
||||||
if (!isDocumentPendingEmailEnabled) {
|
if (!isDocumentPendingEmailEnabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [recipient] = document.recipients;
|
const [recipient] = envelope.recipients;
|
||||||
|
|
||||||
const { email, name } = recipient;
|
const { email, name } = recipient;
|
||||||
|
|
||||||
const assetBaseUrl = NEXT_PUBLIC_WEBAPP_URL() || 'http://localhost:3000';
|
const assetBaseUrl = NEXT_PUBLIC_WEBAPP_URL() || 'http://localhost:3000';
|
||||||
|
|
||||||
const template = createElement(DocumentPendingEmailTemplate, {
|
const template = createElement(DocumentPendingEmailTemplate, {
|
||||||
documentName: document.title,
|
documentName: envelope.title,
|
||||||
assetBaseUrl,
|
assetBaseUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { DocumentVisibility } from '@prisma/client';
|
import type { DocumentVisibility, Prisma } from '@prisma/client';
|
||||||
import { DocumentStatus, TeamMemberRole } from '@prisma/client';
|
import { EnvelopeType, FolderType } from '@prisma/client';
|
||||||
|
import { DocumentStatus } from '@prisma/client';
|
||||||
import { isDeepEqual } from 'remeda';
|
import { isDeepEqual } from 'remeda';
|
||||||
import { match } from 'ts-pattern';
|
|
||||||
|
|
||||||
import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-logs';
|
import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-logs';
|
||||||
import type { ApiRequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
|
import type { ApiRequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
|
||||||
@ -9,10 +9,12 @@ import type { CreateDocumentAuditLogDataResponse } from '@documenso/lib/utils/do
|
|||||||
import { createDocumentAuditLogData } from '@documenso/lib/utils/document-audit-logs';
|
import { createDocumentAuditLogData } from '@documenso/lib/utils/document-audit-logs';
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
|
import { TEAM_DOCUMENT_VISIBILITY_MAP } from '../../constants/teams';
|
||||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||||
import type { TDocumentAccessAuthTypes, TDocumentActionAuthTypes } from '../../types/document-auth';
|
import type { TDocumentAccessAuthTypes, TDocumentActionAuthTypes } from '../../types/document-auth';
|
||||||
import { createDocumentAuthOptions, extractDocumentAuthMethods } from '../../utils/document-auth';
|
import { createDocumentAuthOptions, extractDocumentAuthMethods } from '../../utils/document-auth';
|
||||||
import { getDocumentWhereInput } from './get-document-by-id';
|
import { buildTeamWhereQuery, canAccessTeamDocument } from '../../utils/teams';
|
||||||
|
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||||
|
|
||||||
export type UpdateDocumentOptions = {
|
export type UpdateDocumentOptions = {
|
||||||
userId: number;
|
userId: number;
|
||||||
@ -25,6 +27,7 @@ export type UpdateDocumentOptions = {
|
|||||||
globalAccessAuth?: TDocumentAccessAuthTypes[];
|
globalAccessAuth?: TDocumentAccessAuthTypes[];
|
||||||
globalActionAuth?: TDocumentActionAuthTypes[];
|
globalActionAuth?: TDocumentActionAuthTypes[];
|
||||||
useLegacyFieldInsertion?: boolean;
|
useLegacyFieldInsertion?: boolean;
|
||||||
|
folderId?: string | null;
|
||||||
};
|
};
|
||||||
requestMetadata: ApiRequestMetadata;
|
requestMetadata: ApiRequestMetadata;
|
||||||
};
|
};
|
||||||
@ -36,14 +39,18 @@ export const updateDocument = async ({
|
|||||||
data,
|
data,
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
}: UpdateDocumentOptions) => {
|
}: UpdateDocumentOptions) => {
|
||||||
const { documentWhereInput, team } = await getDocumentWhereInput({
|
const { envelopeWhereInput, team } = await getEnvelopeWhereInput({
|
||||||
documentId,
|
id: {
|
||||||
|
type: 'documentId',
|
||||||
|
id: documentId,
|
||||||
|
},
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const document = await prisma.document.findFirst({
|
const envelope = await prisma.envelope.findFirst({
|
||||||
where: documentWhereInput,
|
where: envelopeWhereInput,
|
||||||
include: {
|
include: {
|
||||||
team: {
|
team: {
|
||||||
select: {
|
select: {
|
||||||
@ -57,57 +64,70 @@ export const updateDocument = async ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!document) {
|
if (!envelope) {
|
||||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||||
message: 'Document not found',
|
message: 'Document not found',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const isDocumentOwner = document.userId === userId;
|
const isEnvelopeOwner = envelope.userId === userId;
|
||||||
const requestedVisibility = data?.visibility;
|
|
||||||
|
|
||||||
if (!isDocumentOwner) {
|
// Validate whether the new visibility setting is allowed for the current user.
|
||||||
match(team.currentTeamRole)
|
if (
|
||||||
.with(TeamMemberRole.ADMIN, () => true)
|
!isEnvelopeOwner &&
|
||||||
.with(TeamMemberRole.MANAGER, () => {
|
data?.visibility &&
|
||||||
const allowedVisibilities: DocumentVisibility[] = [
|
!canAccessTeamDocument(team.currentTeamRole, data.visibility)
|
||||||
DocumentVisibility.EVERYONE,
|
) {
|
||||||
DocumentVisibility.MANAGER_AND_ABOVE,
|
throw new AppError(AppErrorCode.UNAUTHORIZED, {
|
||||||
];
|
message: 'You do not have permission to update the document visibility',
|
||||||
|
});
|
||||||
if (
|
|
||||||
!allowedVisibilities.includes(document.visibility) ||
|
|
||||||
(requestedVisibility && !allowedVisibilities.includes(requestedVisibility))
|
|
||||||
) {
|
|
||||||
throw new AppError(AppErrorCode.UNAUTHORIZED, {
|
|
||||||
message: 'You do not have permission to update the document visibility',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.with(TeamMemberRole.MEMBER, () => {
|
|
||||||
if (
|
|
||||||
document.visibility !== DocumentVisibility.EVERYONE ||
|
|
||||||
(requestedVisibility && requestedVisibility !== DocumentVisibility.EVERYONE)
|
|
||||||
) {
|
|
||||||
throw new AppError(AppErrorCode.UNAUTHORIZED, {
|
|
||||||
message: 'You do not have permission to update the document visibility',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.otherwise(() => {
|
|
||||||
throw new AppError(AppErrorCode.UNAUTHORIZED, {
|
|
||||||
message: 'You do not have permission to update the document',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no data just return the document since this function is normally chained after a meta update.
|
// If no data just return the document since this function is normally chained after a meta update.
|
||||||
if (!data || Object.values(data).length === 0) {
|
if (!data || Object.values(data).length === 0) {
|
||||||
return document;
|
return envelope;
|
||||||
|
}
|
||||||
|
|
||||||
|
let folderUpdateQuery: Prisma.FolderUpdateOneWithoutEnvelopesNestedInput | undefined = undefined;
|
||||||
|
|
||||||
|
// Validate folder ID.
|
||||||
|
if (data.folderId) {
|
||||||
|
const folder = await prisma.folder.findFirst({
|
||||||
|
where: {
|
||||||
|
id: data.folderId,
|
||||||
|
team: buildTeamWhereQuery({
|
||||||
|
teamId,
|
||||||
|
userId,
|
||||||
|
}),
|
||||||
|
type: FolderType.DOCUMENT,
|
||||||
|
visibility: {
|
||||||
|
in: TEAM_DOCUMENT_VISIBILITY_MAP[team.currentTeamRole],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!folder) {
|
||||||
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||||
|
message: 'Folder not found',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
folderUpdateQuery = {
|
||||||
|
connect: {
|
||||||
|
id: data.folderId,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move to root folder if folderId is null.
|
||||||
|
if (data.folderId === null) {
|
||||||
|
folderUpdateQuery = {
|
||||||
|
disconnect: true,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const { documentAuthOption } = extractDocumentAuthMethods({
|
const { documentAuthOption } = extractDocumentAuthMethods({
|
||||||
documentAuth: document.authOptions,
|
documentAuth: envelope.authOptions,
|
||||||
});
|
});
|
||||||
|
|
||||||
const documentGlobalAccessAuth = documentAuthOption?.globalAccessAuth ?? null;
|
const documentGlobalAccessAuth = documentAuthOption?.globalAccessAuth ?? null;
|
||||||
@ -120,14 +140,14 @@ export const updateDocument = async ({
|
|||||||
data?.globalActionAuth === undefined ? documentGlobalActionAuth : data.globalActionAuth;
|
data?.globalActionAuth === undefined ? documentGlobalActionAuth : data.globalActionAuth;
|
||||||
|
|
||||||
// Check if user has permission to set the global action auth.
|
// Check if user has permission to set the global action auth.
|
||||||
if (newGlobalActionAuth.length > 0 && !document.team.organisation.organisationClaim.flags.cfr21) {
|
if (newGlobalActionAuth.length > 0 && !envelope.team.organisation.organisationClaim.flags.cfr21) {
|
||||||
throw new AppError(AppErrorCode.UNAUTHORIZED, {
|
throw new AppError(AppErrorCode.UNAUTHORIZED, {
|
||||||
message: 'You do not have permission to set the action auth',
|
message: 'You do not have permission to set the action auth',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const isTitleSame = data.title === undefined || data.title === document.title;
|
const isTitleSame = data.title === undefined || data.title === envelope.title;
|
||||||
const isExternalIdSame = data.externalId === undefined || data.externalId === document.externalId;
|
const isExternalIdSame = data.externalId === undefined || data.externalId === envelope.externalId;
|
||||||
const isGlobalAccessSame =
|
const isGlobalAccessSame =
|
||||||
documentGlobalAccessAuth === undefined ||
|
documentGlobalAccessAuth === undefined ||
|
||||||
isDeepEqual(documentGlobalAccessAuth, newGlobalAccessAuth);
|
isDeepEqual(documentGlobalAccessAuth, newGlobalAccessAuth);
|
||||||
@ -135,11 +155,12 @@ export const updateDocument = async ({
|
|||||||
documentGlobalActionAuth === undefined ||
|
documentGlobalActionAuth === undefined ||
|
||||||
isDeepEqual(documentGlobalActionAuth, newGlobalActionAuth);
|
isDeepEqual(documentGlobalActionAuth, newGlobalActionAuth);
|
||||||
const isDocumentVisibilitySame =
|
const isDocumentVisibilitySame =
|
||||||
data.visibility === undefined || data.visibility === document.visibility;
|
data.visibility === undefined || data.visibility === envelope.visibility;
|
||||||
|
const isFolderSame = data.folderId === undefined || data.folderId === envelope.folderId;
|
||||||
|
|
||||||
const auditLogs: CreateDocumentAuditLogDataResponse[] = [];
|
const auditLogs: CreateDocumentAuditLogDataResponse[] = [];
|
||||||
|
|
||||||
if (!isTitleSame && document.status !== DocumentStatus.DRAFT) {
|
if (!isTitleSame && envelope.status !== DocumentStatus.DRAFT) {
|
||||||
throw new AppError(AppErrorCode.INVALID_BODY, {
|
throw new AppError(AppErrorCode.INVALID_BODY, {
|
||||||
message: 'You cannot update the title if the document has been sent',
|
message: 'You cannot update the title if the document has been sent',
|
||||||
});
|
});
|
||||||
@ -149,10 +170,10 @@ export const updateDocument = async ({
|
|||||||
auditLogs.push(
|
auditLogs.push(
|
||||||
createDocumentAuditLogData({
|
createDocumentAuditLogData({
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_TITLE_UPDATED,
|
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_TITLE_UPDATED,
|
||||||
documentId,
|
envelopeId: envelope.id,
|
||||||
metadata: requestMetadata,
|
metadata: requestMetadata,
|
||||||
data: {
|
data: {
|
||||||
from: document.title,
|
from: envelope.title,
|
||||||
to: data.title || '',
|
to: data.title || '',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@ -163,10 +184,10 @@ export const updateDocument = async ({
|
|||||||
auditLogs.push(
|
auditLogs.push(
|
||||||
createDocumentAuditLogData({
|
createDocumentAuditLogData({
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_EXTERNAL_ID_UPDATED,
|
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_EXTERNAL_ID_UPDATED,
|
||||||
documentId,
|
envelopeId: envelope.id,
|
||||||
metadata: requestMetadata,
|
metadata: requestMetadata,
|
||||||
data: {
|
data: {
|
||||||
from: document.externalId,
|
from: envelope.externalId,
|
||||||
to: data.externalId || '',
|
to: data.externalId || '',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@ -177,7 +198,7 @@ export const updateDocument = async ({
|
|||||||
auditLogs.push(
|
auditLogs.push(
|
||||||
createDocumentAuditLogData({
|
createDocumentAuditLogData({
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_GLOBAL_AUTH_ACCESS_UPDATED,
|
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_GLOBAL_AUTH_ACCESS_UPDATED,
|
||||||
documentId,
|
envelopeId: envelope.id,
|
||||||
metadata: requestMetadata,
|
metadata: requestMetadata,
|
||||||
data: {
|
data: {
|
||||||
from: documentGlobalAccessAuth,
|
from: documentGlobalAccessAuth,
|
||||||
@ -191,7 +212,7 @@ export const updateDocument = async ({
|
|||||||
auditLogs.push(
|
auditLogs.push(
|
||||||
createDocumentAuditLogData({
|
createDocumentAuditLogData({
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_GLOBAL_AUTH_ACTION_UPDATED,
|
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_GLOBAL_AUTH_ACTION_UPDATED,
|
||||||
documentId,
|
envelopeId: envelope.id,
|
||||||
metadata: requestMetadata,
|
metadata: requestMetadata,
|
||||||
data: {
|
data: {
|
||||||
from: documentGlobalActionAuth,
|
from: documentGlobalActionAuth,
|
||||||
@ -205,19 +226,34 @@ export const updateDocument = async ({
|
|||||||
auditLogs.push(
|
auditLogs.push(
|
||||||
createDocumentAuditLogData({
|
createDocumentAuditLogData({
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_VISIBILITY_UPDATED,
|
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_VISIBILITY_UPDATED,
|
||||||
documentId,
|
envelopeId: envelope.id,
|
||||||
metadata: requestMetadata,
|
metadata: requestMetadata,
|
||||||
data: {
|
data: {
|
||||||
from: document.visibility,
|
from: envelope.visibility,
|
||||||
to: data.visibility || '',
|
to: data.visibility || '',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Todo: Decide if we want to log moving the document around.
|
||||||
|
// if (!isFolderSame) {
|
||||||
|
// auditLogs.push(
|
||||||
|
// createDocumentAuditLogData({
|
||||||
|
// type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_FOLDER_UPDATED,
|
||||||
|
// envelopeId: envelope.id,
|
||||||
|
// metadata: requestMetadata,
|
||||||
|
// data: {
|
||||||
|
// from: envelope.folderId,
|
||||||
|
// to: data.folderId || '',
|
||||||
|
// },
|
||||||
|
// }),
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
// Early return if nothing is required.
|
// Early return if nothing is required.
|
||||||
if (auditLogs.length === 0 && data.useLegacyFieldInsertion === undefined) {
|
if (auditLogs.length === 0 && data.useLegacyFieldInsertion === undefined && isFolderSame) {
|
||||||
return document;
|
return envelope;
|
||||||
}
|
}
|
||||||
|
|
||||||
return await prisma.$transaction(async (tx) => {
|
return await prisma.$transaction(async (tx) => {
|
||||||
@ -226,9 +262,10 @@ export const updateDocument = async ({
|
|||||||
globalActionAuth: newGlobalActionAuth,
|
globalActionAuth: newGlobalActionAuth,
|
||||||
});
|
});
|
||||||
|
|
||||||
const updatedDocument = await tx.document.update({
|
const updatedDocument = await tx.envelope.update({
|
||||||
where: {
|
where: {
|
||||||
id: documentId,
|
id: envelope.id,
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
title: data.title,
|
title: data.title,
|
||||||
@ -236,6 +273,7 @@ export const updateDocument = async ({
|
|||||||
visibility: data.visibility as DocumentVisibility,
|
visibility: data.visibility as DocumentVisibility,
|
||||||
useLegacyFieldInsertion: data.useLegacyFieldInsertion,
|
useLegacyFieldInsertion: data.useLegacyFieldInsertion,
|
||||||
authOptions,
|
authOptions,
|
||||||
|
folder: folderUpdateQuery,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user