chore: document audit log

This commit is contained in:
Catalin Pit
2025-07-07 16:10:41 +03:00
parent 1511d2288c
commit 34caad2641
10 changed files with 95 additions and 9 deletions

View File

@ -43,6 +43,7 @@ export const DocumentSigningAttachmentsDialog = ({
<Trans>No attachments available.</Trans> <Trans>No attachments available.</Trans>
</span> </span>
)} )}
{attachments.map((attachment, idx) => ( {attachments.map((attachment, idx) => (
<a <a
key={attachment.id || idx} key={attachment.id || idx}

View File

@ -22,7 +22,5 @@ export const findTemplateAttachments = async ({
}, },
}); });
console.log('attachments', attachments);
return attachments; return attachments;
}; };

View File

@ -1,18 +1,25 @@
import type { Attachment } from '@prisma/client'; import type { Attachment, User } from '@prisma/client';
import type { RequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
import { prisma } from '@documenso/prisma'; import { prisma } from '@documenso/prisma';
import { AppError } from '../../errors/app-error'; import { AppError } from '../../errors/app-error';
import { AppErrorCode } from '../../errors/app-error'; import { AppErrorCode } from '../../errors/app-error';
import { DOCUMENT_AUDIT_LOG_TYPE } from '../../types/document-audit-logs';
import { createDocumentAuditLogData } from '../../utils/document-audit-logs';
export type CreateAttachmentsOptions = { export type CreateAttachmentsOptions = {
documentId: number; documentId: number;
attachments: Pick<Attachment, 'id' | 'label' | 'url' | 'type'>[]; attachments: Pick<Attachment, 'id' | 'label' | 'url' | 'type'>[];
user: Pick<User, 'id' | 'email' | 'name'>;
requestMetadata: RequestMetadata;
}; };
export const setDocumentAttachments = async ({ export const setDocumentAttachments = async ({
documentId, documentId,
attachments, attachments,
user,
requestMetadata,
}: CreateAttachmentsOptions) => { }: CreateAttachmentsOptions) => {
const document = await prisma.document.findUnique({ const document = await prisma.document.findUnique({
where: { where: {
@ -75,5 +82,29 @@ export const setDocumentAttachments = async ({
} }
} }
const isAttachmentsSame = upsertedAttachments.every((attachment) => {
const existingAttachment = existingAttachments.find((a) => a.id === attachment.id);
return (
existingAttachment?.label === attachment.label &&
existingAttachment?.url === attachment.url &&
existingAttachment?.type === attachment.type
);
});
if (!isAttachmentsSame) {
await prisma.documentAuditLog.create({
data: createDocumentAuditLogData({
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_ATTACHMENTS_UPDATED,
documentId: document.id,
user,
data: {
from: existingAttachments,
to: upsertedAttachments,
},
requestMetadata,
}),
});
}
return upsertedAttachments; return upsertedAttachments;
}; };

View File

@ -1435,7 +1435,8 @@ msgstr "Unterstützend"
msgid "At least one signature type must be enabled" msgid "At least one signature type must be enabled"
msgstr "Mindestens ein Signaturtyp muss aktiviert sein" msgstr "Mindestens ein Signaturtyp muss aktiviert sein"
#: apps/remix/app/components/general/document-signing/document-signing-form.tsx #: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
#: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
msgid "Attachments" msgid "Attachments"
msgstr "" msgstr ""
@ -4414,6 +4415,10 @@ msgstr "Nein"
msgid "No active drafts" msgid "No active drafts"
msgstr "Keine aktiven Entwürfe" msgstr "Keine aktiven Entwürfe"
#: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
msgid "No attachments available."
msgstr ""
#: apps/remix/app/components/dialogs/template-move-to-folder-dialog.tsx #: apps/remix/app/components/dialogs/template-move-to-folder-dialog.tsx
#: apps/remix/app/components/dialogs/document-move-to-folder-dialog.tsx #: apps/remix/app/components/dialogs/document-move-to-folder-dialog.tsx
msgid "No folders found" msgid "No folders found"
@ -7651,6 +7656,10 @@ msgstr "Betrachten"
msgid "View activity" msgid "View activity"
msgstr "Aktivität ansehen" msgstr "Aktivität ansehen"
#: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
msgid "View all attachments for this document."
msgstr ""
#: packages/email/templates/confirm-team-email.tsx #: packages/email/templates/confirm-team-email.tsx
msgid "View all documents sent to and from this email address" msgid "View all documents sent to and from this email address"
msgstr "Sehen Sie sich alle Dokumente an, die an diese E-Mail-Adresse gesendet wurden und von dieser E-Mail-Adresse gesendet wurden" msgstr "Sehen Sie sich alle Dokumente an, die an diese E-Mail-Adresse gesendet wurden und von dieser E-Mail-Adresse gesendet wurden"

View File

@ -1430,7 +1430,8 @@ msgstr "Assisting"
msgid "At least one signature type must be enabled" msgid "At least one signature type must be enabled"
msgstr "At least one signature type must be enabled" msgstr "At least one signature type must be enabled"
#: apps/remix/app/components/general/document-signing/document-signing-form.tsx #: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
#: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
msgid "Attachments" msgid "Attachments"
msgstr "Attachments" msgstr "Attachments"
@ -4409,6 +4410,10 @@ msgstr "No"
msgid "No active drafts" msgid "No active drafts"
msgstr "No active drafts" msgstr "No active drafts"
#: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
msgid "No attachments available."
msgstr "No attachments available."
#: apps/remix/app/components/dialogs/template-move-to-folder-dialog.tsx #: apps/remix/app/components/dialogs/template-move-to-folder-dialog.tsx
#: apps/remix/app/components/dialogs/document-move-to-folder-dialog.tsx #: apps/remix/app/components/dialogs/document-move-to-folder-dialog.tsx
msgid "No folders found" msgid "No folders found"
@ -7658,6 +7663,10 @@ msgstr "View"
msgid "View activity" msgid "View activity"
msgstr "View activity" msgstr "View activity"
#: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
msgid "View all attachments for this document."
msgstr "View all attachments for this document."
#: packages/email/templates/confirm-team-email.tsx #: packages/email/templates/confirm-team-email.tsx
msgid "View all documents sent to and from this email address" msgid "View all documents sent to and from this email address"
msgstr "View all documents sent to and from this email address" msgstr "View all documents sent to and from this email address"

View File

@ -1435,7 +1435,8 @@ msgstr "Asistiendo"
msgid "At least one signature type must be enabled" msgid "At least one signature type must be enabled"
msgstr "Al menos un tipo de firma debe estar habilitado" msgstr "Al menos un tipo de firma debe estar habilitado"
#: apps/remix/app/components/general/document-signing/document-signing-form.tsx #: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
#: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
msgid "Attachments" msgid "Attachments"
msgstr "" msgstr ""
@ -4414,6 +4415,10 @@ msgstr "No"
msgid "No active drafts" msgid "No active drafts"
msgstr "No hay borradores activos" msgstr "No hay borradores activos"
#: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
msgid "No attachments available."
msgstr ""
#: apps/remix/app/components/dialogs/template-move-to-folder-dialog.tsx #: apps/remix/app/components/dialogs/template-move-to-folder-dialog.tsx
#: apps/remix/app/components/dialogs/document-move-to-folder-dialog.tsx #: apps/remix/app/components/dialogs/document-move-to-folder-dialog.tsx
msgid "No folders found" msgid "No folders found"
@ -7653,6 +7658,10 @@ msgstr "Ver"
msgid "View activity" msgid "View activity"
msgstr "Ver actividad" msgstr "Ver actividad"
#: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
msgid "View all attachments for this document."
msgstr ""
#: packages/email/templates/confirm-team-email.tsx #: packages/email/templates/confirm-team-email.tsx
msgid "View all documents sent to and from this email address" msgid "View all documents sent to and from this email address"
msgstr "Ver todos los documentos enviados hacia y desde esta dirección de correo electrónico" msgstr "Ver todos los documentos enviados hacia y desde esta dirección de correo electrónico"

View File

@ -1435,7 +1435,8 @@ msgstr "En assistance"
msgid "At least one signature type must be enabled" msgid "At least one signature type must be enabled"
msgstr "Au moins un type de signature doit être activé" msgstr "Au moins un type de signature doit être activé"
#: apps/remix/app/components/general/document-signing/document-signing-form.tsx #: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
#: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
msgid "Attachments" msgid "Attachments"
msgstr "" msgstr ""
@ -4414,6 +4415,10 @@ msgstr "Non"
msgid "No active drafts" msgid "No active drafts"
msgstr "Pas de brouillons actifs" msgstr "Pas de brouillons actifs"
#: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
msgid "No attachments available."
msgstr ""
#: apps/remix/app/components/dialogs/template-move-to-folder-dialog.tsx #: apps/remix/app/components/dialogs/template-move-to-folder-dialog.tsx
#: apps/remix/app/components/dialogs/document-move-to-folder-dialog.tsx #: apps/remix/app/components/dialogs/document-move-to-folder-dialog.tsx
msgid "No folders found" msgid "No folders found"
@ -7651,6 +7656,10 @@ msgstr "Voir"
msgid "View activity" msgid "View activity"
msgstr "Voir l'activité" msgstr "Voir l'activité"
#: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
msgid "View all attachments for this document."
msgstr ""
#: packages/email/templates/confirm-team-email.tsx #: packages/email/templates/confirm-team-email.tsx
msgid "View all documents sent to and from this email address" msgid "View all documents sent to and from this email address"
msgstr "Voir tous les documents envoyés à et depuis cette adresse e-mail" msgstr "Voir tous les documents envoyés à et depuis cette adresse e-mail"

View File

@ -1435,7 +1435,8 @@ msgstr "Assistenza in corso"
msgid "At least one signature type must be enabled" msgid "At least one signature type must be enabled"
msgstr "Deve essere abilitato almeno un tipo di firma" msgstr "Deve essere abilitato almeno un tipo di firma"
#: apps/remix/app/components/general/document-signing/document-signing-form.tsx #: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
#: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
msgid "Attachments" msgid "Attachments"
msgstr "" msgstr ""
@ -4414,6 +4415,10 @@ msgstr "No"
msgid "No active drafts" msgid "No active drafts"
msgstr "Nessuna bozza attiva" msgstr "Nessuna bozza attiva"
#: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
msgid "No attachments available."
msgstr ""
#: apps/remix/app/components/dialogs/template-move-to-folder-dialog.tsx #: apps/remix/app/components/dialogs/template-move-to-folder-dialog.tsx
#: apps/remix/app/components/dialogs/document-move-to-folder-dialog.tsx #: apps/remix/app/components/dialogs/document-move-to-folder-dialog.tsx
msgid "No folders found" msgid "No folders found"
@ -7663,6 +7668,10 @@ msgstr "Visualizza"
msgid "View activity" msgid "View activity"
msgstr "Visualizza attività" msgstr "Visualizza attività"
#: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
msgid "View all attachments for this document."
msgstr ""
#: packages/email/templates/confirm-team-email.tsx #: packages/email/templates/confirm-team-email.tsx
msgid "View all documents sent to and from this email address" msgid "View all documents sent to and from this email address"
msgstr "Visualizza tutti i documenti inviati a o da questo indirizzo email" msgstr "Visualizza tutti i documenti inviati a o da questo indirizzo email"

View File

@ -1435,7 +1435,8 @@ msgstr "Asystowanie"
msgid "At least one signature type must be enabled" msgid "At least one signature type must be enabled"
msgstr "Przynajmniej jeden typ podpisu musi być włączony" msgstr "Przynajmniej jeden typ podpisu musi być włączony"
#: apps/remix/app/components/general/document-signing/document-signing-form.tsx #: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
#: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
msgid "Attachments" msgid "Attachments"
msgstr "" msgstr ""
@ -4414,6 +4415,10 @@ msgstr "Nie"
msgid "No active drafts" msgid "No active drafts"
msgstr "Brak aktywnych szkiców" msgstr "Brak aktywnych szkiców"
#: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
msgid "No attachments available."
msgstr ""
#: apps/remix/app/components/dialogs/template-move-to-folder-dialog.tsx #: apps/remix/app/components/dialogs/template-move-to-folder-dialog.tsx
#: apps/remix/app/components/dialogs/document-move-to-folder-dialog.tsx #: apps/remix/app/components/dialogs/document-move-to-folder-dialog.tsx
msgid "No folders found" msgid "No folders found"
@ -7651,6 +7656,10 @@ msgstr "Widok"
msgid "View activity" msgid "View activity"
msgstr "Wyświetl aktywność" msgstr "Wyświetl aktywność"
#: apps/remix/app/components/general/document-signing/document-signing-attachments-dialog.tsx
msgid "View all attachments for this document."
msgstr ""
#: packages/email/templates/confirm-team-email.tsx #: packages/email/templates/confirm-team-email.tsx
msgid "View all documents sent to and from this email address" msgid "View all documents sent to and from this email address"
msgstr "Wyświetl wszystkie dokumenty wysłane do i z tego adresu e-mail" msgstr "Wyświetl wszystkie dokumenty wysłane do i z tego adresu e-mail"

View File

@ -46,6 +46,8 @@ export const attachmentRouter = router({
const updatedAttachments = await setDocumentAttachments({ const updatedAttachments = await setDocumentAttachments({
documentId, documentId,
attachments, attachments,
user: ctx.user,
requestMetadata: ctx.metadata.requestMetadata,
}); });
return updatedAttachments; return updatedAttachments;