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

@ -22,7 +22,5 @@ export const findTemplateAttachments = async ({
},
});
console.log('attachments', 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 { AppError } 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 = {
documentId: number;
attachments: Pick<Attachment, 'id' | 'label' | 'url' | 'type'>[];
user: Pick<User, 'id' | 'email' | 'name'>;
requestMetadata: RequestMetadata;
};
export const setDocumentAttachments = async ({
documentId,
attachments,
user,
requestMetadata,
}: CreateAttachmentsOptions) => {
const document = await prisma.document.findUnique({
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;
};

View File

@ -1435,7 +1435,8 @@ msgstr "Unterstützend"
msgid "At least one signature type must be enabled"
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"
msgstr ""
@ -4414,6 +4415,10 @@ msgstr "Nein"
msgid "No active drafts"
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/document-move-to-folder-dialog.tsx
msgid "No folders found"
@ -7651,6 +7656,10 @@ msgstr "Betrachten"
msgid "View activity"
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
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"

View File

@ -1430,7 +1430,8 @@ msgstr "Assisting"
msgid "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"
msgstr "Attachments"
@ -4409,6 +4410,10 @@ msgstr "No"
msgid "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/document-move-to-folder-dialog.tsx
msgid "No folders found"
@ -7658,6 +7663,10 @@ msgstr "View"
msgid "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
msgid "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"
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"
msgstr ""
@ -4414,6 +4415,10 @@ msgstr "No"
msgid "No active drafts"
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/document-move-to-folder-dialog.tsx
msgid "No folders found"
@ -7653,6 +7658,10 @@ msgstr "Ver"
msgid "View activity"
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
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"

View File

@ -1435,7 +1435,8 @@ msgstr "En assistance"
msgid "At least one signature type must be enabled"
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"
msgstr ""
@ -4414,6 +4415,10 @@ msgstr "Non"
msgid "No active drafts"
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/document-move-to-folder-dialog.tsx
msgid "No folders found"
@ -7651,6 +7656,10 @@ msgstr "Voir"
msgid "View activity"
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
msgid "View all documents sent to and from this email address"
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"
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"
msgstr ""
@ -4414,6 +4415,10 @@ msgstr "No"
msgid "No active drafts"
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/document-move-to-folder-dialog.tsx
msgid "No folders found"
@ -7663,6 +7668,10 @@ msgstr "Visualizza"
msgid "View activity"
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
msgid "View all documents sent to and from this email address"
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"
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"
msgstr ""
@ -4414,6 +4415,10 @@ msgstr "Nie"
msgid "No active drafts"
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/document-move-to-folder-dialog.tsx
msgid "No folders found"
@ -7651,6 +7656,10 @@ msgstr "Widok"
msgid "View activity"
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
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"

View File

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