mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +10:00
Add ability to enable or disable allowed signature types: - Drawn - Typed - Uploaded **Tabbed style signature dialog**  **Document settings**  **Team preferences**  - Add multiselect to select allowed signatures in document and templates settings tab - Add multiselect to select allowed signatures in teams preferences - Removed "Enable typed signatures" from document/template edit page - Refactored signature pad to use tabs instead of an all in one signature pad Added E2E tests to check settings are applied correctly for documents and templates
146 lines
3.5 KiB
TypeScript
146 lines
3.5 KiB
TypeScript
import type { DocumentDistributionMethod, DocumentSigningOrder } from '@prisma/client';
|
|
|
|
import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-logs';
|
|
import type { ApiRequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
|
|
import {
|
|
createDocumentAuditLogData,
|
|
diffDocumentMetaChanges,
|
|
} from '@documenso/lib/utils/document-audit-logs';
|
|
import { prisma } from '@documenso/prisma';
|
|
|
|
import type { SupportedLanguageCodes } from '../../constants/i18n';
|
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
|
import type { TDocumentEmailSettings } from '../../types/document-email';
|
|
|
|
export type CreateDocumentMetaOptions = {
|
|
userId: number;
|
|
teamId?: number;
|
|
documentId: number;
|
|
subject?: string;
|
|
message?: string;
|
|
timezone?: string;
|
|
password?: string;
|
|
dateFormat?: string;
|
|
redirectUrl?: string;
|
|
emailSettings?: TDocumentEmailSettings;
|
|
signingOrder?: DocumentSigningOrder;
|
|
allowDictateNextSigner?: boolean;
|
|
distributionMethod?: DocumentDistributionMethod;
|
|
typedSignatureEnabled?: boolean;
|
|
uploadSignatureEnabled?: boolean;
|
|
drawSignatureEnabled?: boolean;
|
|
language?: SupportedLanguageCodes;
|
|
requestMetadata: ApiRequestMetadata;
|
|
};
|
|
|
|
export const upsertDocumentMeta = async ({
|
|
userId,
|
|
teamId,
|
|
subject,
|
|
message,
|
|
timezone,
|
|
dateFormat,
|
|
documentId,
|
|
password,
|
|
redirectUrl,
|
|
signingOrder,
|
|
allowDictateNextSigner,
|
|
emailSettings,
|
|
distributionMethod,
|
|
typedSignatureEnabled,
|
|
uploadSignatureEnabled,
|
|
drawSignatureEnabled,
|
|
language,
|
|
requestMetadata,
|
|
}: CreateDocumentMetaOptions) => {
|
|
const document = await prisma.document.findFirst({
|
|
where: {
|
|
id: documentId,
|
|
...(teamId
|
|
? {
|
|
team: {
|
|
id: teamId,
|
|
members: {
|
|
some: {
|
|
userId,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
: {
|
|
userId,
|
|
teamId: null,
|
|
}),
|
|
},
|
|
include: {
|
|
documentMeta: true,
|
|
},
|
|
});
|
|
|
|
if (!document) {
|
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
|
message: 'Document not found',
|
|
});
|
|
}
|
|
|
|
const { documentMeta: originalDocumentMeta } = document;
|
|
|
|
return await prisma.$transaction(async (tx) => {
|
|
const upsertedDocumentMeta = await tx.documentMeta.upsert({
|
|
where: {
|
|
documentId,
|
|
},
|
|
create: {
|
|
subject,
|
|
message,
|
|
password,
|
|
dateFormat,
|
|
timezone,
|
|
documentId,
|
|
redirectUrl,
|
|
signingOrder,
|
|
allowDictateNextSigner,
|
|
emailSettings,
|
|
distributionMethod,
|
|
typedSignatureEnabled,
|
|
uploadSignatureEnabled,
|
|
drawSignatureEnabled,
|
|
language,
|
|
},
|
|
update: {
|
|
subject,
|
|
message,
|
|
password,
|
|
dateFormat,
|
|
timezone,
|
|
redirectUrl,
|
|
signingOrder,
|
|
allowDictateNextSigner,
|
|
emailSettings,
|
|
distributionMethod,
|
|
typedSignatureEnabled,
|
|
uploadSignatureEnabled,
|
|
drawSignatureEnabled,
|
|
language,
|
|
},
|
|
});
|
|
|
|
const changes = diffDocumentMetaChanges(originalDocumentMeta ?? {}, upsertedDocumentMeta);
|
|
|
|
if (changes.length > 0) {
|
|
await tx.documentAuditLog.create({
|
|
data: createDocumentAuditLogData({
|
|
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_META_UPDATED,
|
|
documentId,
|
|
metadata: requestMetadata,
|
|
data: {
|
|
changes: diffDocumentMetaChanges(originalDocumentMeta ?? {}, upsertedDocumentMeta),
|
|
},
|
|
}),
|
|
});
|
|
}
|
|
|
|
return upsertedDocumentMeta;
|
|
});
|
|
};
|