mirror of
https://github.com/documenso/documenso.git
synced 2025-11-20 19:51:32 +10:00
feat: include audit logs
This commit is contained in:
@ -13,6 +13,7 @@ import { signPdf } from '@documenso/signing';
|
|||||||
|
|
||||||
import { sendCompletedEmail } from '../../../server-only/document/send-completed-email';
|
import { sendCompletedEmail } from '../../../server-only/document/send-completed-email';
|
||||||
import PostHogServerClient from '../../../server-only/feature-flags/get-post-hog-server-client';
|
import PostHogServerClient from '../../../server-only/feature-flags/get-post-hog-server-client';
|
||||||
|
import { getAuditLogsPdf } from '../../../server-only/htmltopdf/get-audit-logs-pdf';
|
||||||
import { getCertificatePdf } from '../../../server-only/htmltopdf/get-certificate-pdf';
|
import { getCertificatePdf } from '../../../server-only/htmltopdf/get-certificate-pdf';
|
||||||
import { flattenAnnotations } from '../../../server-only/pdf/flatten-annotations';
|
import { flattenAnnotations } from '../../../server-only/pdf/flatten-annotations';
|
||||||
import { flattenForm } from '../../../server-only/pdf/flatten-form';
|
import { flattenForm } from '../../../server-only/pdf/flatten-form';
|
||||||
@ -129,6 +130,11 @@ export const run = async ({
|
|||||||
}).catch(() => null)
|
}).catch(() => null)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
const auditLogData = await getAuditLogsPdf({
|
||||||
|
documentId,
|
||||||
|
language: document.documentMeta?.language,
|
||||||
|
}).catch(() => null);
|
||||||
|
|
||||||
const newDataId = await io.runTask('decorate-and-sign-pdf', async () => {
|
const newDataId = await io.runTask('decorate-and-sign-pdf', async () => {
|
||||||
const pdfDoc = await PDFDocument.load(pdfData);
|
const pdfDoc = await PDFDocument.load(pdfData);
|
||||||
|
|
||||||
@ -150,6 +156,16 @@ export const run = async ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (auditLogData) {
|
||||||
|
const auditLog = await PDFDocument.load(auditLogData);
|
||||||
|
|
||||||
|
const auditLogPages = await pdfDoc.copyPages(auditLog, auditLog.getPageIndices());
|
||||||
|
|
||||||
|
auditLogPages.forEach((page) => {
|
||||||
|
pdfDoc.addPage(page);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
for (const field of fields) {
|
for (const field of fields) {
|
||||||
if (field.inserted) {
|
if (field.inserted) {
|
||||||
await insertFieldInPDF(pdfDoc, field);
|
await insertFieldInPDF(pdfDoc, field);
|
||||||
|
|||||||
@ -118,9 +118,10 @@ export const sealDocument = async ({
|
|||||||
}).catch(() => null)
|
}).catch(() => null)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
const auditLogData = await getAuditLogsPdf({ documentId }).catch(() => null);
|
const auditLogData = await getAuditLogsPdf({
|
||||||
|
documentId,
|
||||||
console.log({ auditLogData });
|
language: document.documentMeta?.language,
|
||||||
|
}).catch(() => null);
|
||||||
|
|
||||||
const doc = await PDFDocument.load(pdfData);
|
const doc = await PDFDocument.load(pdfData);
|
||||||
|
|
||||||
|
|||||||
@ -2,13 +2,16 @@ import { DateTime } from 'luxon';
|
|||||||
import type { Browser } from 'playwright';
|
import type { Browser } from 'playwright';
|
||||||
|
|
||||||
import { NEXT_PUBLIC_WEBAPP_URL } from '../../constants/app';
|
import { NEXT_PUBLIC_WEBAPP_URL } from '../../constants/app';
|
||||||
|
import { type SupportedLanguageCodes, isValidLanguageCode } from '../../constants/i18n';
|
||||||
import { encryptSecondaryData } from '../crypto/encrypt';
|
import { encryptSecondaryData } from '../crypto/encrypt';
|
||||||
|
|
||||||
export type GetAuditLogsPdfParams = {
|
export type GetAuditLogsPdfParams = {
|
||||||
documentId: number;
|
documentId: number;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
|
language?: SupportedLanguageCodes | (string & {});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getAuditLogsPdf = async ({ documentId }: GetAuditLogsPdfParams) => {
|
export const getAuditLogsPdf = async ({ documentId, language }: GetAuditLogsPdfParams) => {
|
||||||
const { chromium } = await import('playwright');
|
const { chromium } = await import('playwright');
|
||||||
|
|
||||||
const encryptedId = encryptSecondaryData({
|
const encryptedId = encryptSecondaryData({
|
||||||
@ -36,6 +39,17 @@ export const getAuditLogsPdf = async ({ documentId }: GetAuditLogsPdfParams) =>
|
|||||||
|
|
||||||
const page = await browserContext.newPage();
|
const page = await browserContext.newPage();
|
||||||
|
|
||||||
|
const lang = isValidLanguageCode(language) ? language : 'en';
|
||||||
|
|
||||||
|
await page.context().addCookies([
|
||||||
|
{
|
||||||
|
name: 'language',
|
||||||
|
value: lang,
|
||||||
|
url: NEXT_PUBLIC_WEBAPP_URL(),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
try {
|
||||||
await page.goto(`${NEXT_PUBLIC_WEBAPP_URL()}/__htmltopdf/audit-log?d=${encryptedId}`, {
|
await page.goto(`${NEXT_PUBLIC_WEBAPP_URL()}/__htmltopdf/audit-log?d=${encryptedId}`, {
|
||||||
waitUntil: 'networkidle',
|
waitUntil: 'networkidle',
|
||||||
timeout: 10_000,
|
timeout: 10_000,
|
||||||
@ -50,4 +64,11 @@ export const getAuditLogsPdf = async ({ documentId }: GetAuditLogsPdfParams) =>
|
|||||||
void browser.close();
|
void browser.close();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
await browserContext.close();
|
||||||
|
|
||||||
|
void browser.close();
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user