fix: audit logs

This commit is contained in:
Ephraim Atta-Duncan
2024-10-16 23:05:44 +00:00
parent cc8b972fbc
commit bb805ea93b
7 changed files with 34 additions and 6 deletions

View File

@ -335,6 +335,16 @@ export const DocumentHistorySheet = ({
]}
/>
))
.with({ type: DOCUMENT_AUDIT_LOG_TYPE.SELF_SIGN }, ({ data }) => (
<DocumentHistorySheetChanges
values={[
{
key: 'Signed by',
value: data.recipientEmail,
},
]}
/>
))
.with(
{ type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_VISIBILITY_UPDATED },
({ data }) => (

View File

@ -122,12 +122,16 @@ export const selfSignDocument = async ({
if (document.status === DocumentStatus.DRAFT) {
await tx.documentAuditLog.create({
data: createDocumentAuditLogData({
// todo: use a different audit log type
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_SENT,
type: DOCUMENT_AUDIT_LOG_TYPE.SELF_SIGN,
documentId: document.id,
requestMetadata,
user,
data: {},
data: {
recipientId: document.Recipient[0].id,
recipientEmail: document.Recipient[0].email,
recipientName: document.Recipient[0].name,
recipientRole: document.Recipient[0].role,
},
}),
});
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -13,6 +13,7 @@ import { ZRecipientActionAuthTypesSchema } from './document-auth';
export const ZDocumentAuditLogTypeSchema = z.enum([
// Document actions.
'EMAIL_SENT',
'SELF_SIGN',
// Document modification events.
'FIELD_CREATED',
@ -178,6 +179,14 @@ export const ZDocumentAuditLogEventEmailSentSchema = z.object({
}),
});
/**
* Event: Self sign
*/
export const ZDocumentAuditLogSelfSignSchema = z.object({
type: z.literal(DOCUMENT_AUDIT_LOG_TYPE.SELF_SIGN),
data: ZBaseRecipientDataSchema,
});
/**
* Event: Document completed.
*/
@ -475,6 +484,7 @@ export const ZDocumentAuditLogBaseSchema = z.object({
export const ZDocumentAuditLogSchema = ZDocumentAuditLogBaseSchema.and(
z.union([
ZDocumentAuditLogEventEmailSentSchema,
ZDocumentAuditLogSelfSignSchema,
ZDocumentAuditLogEventDocumentCompletedSchema,
ZDocumentAuditLogEventDocumentCreatedSchema,
ZDocumentAuditLogEventDocumentDeletedSchema,

View File

@ -364,6 +364,10 @@ export const formatDocumentAuditLogAction = (auditLog: TDocumentAuditLog, userId
anonymous: `Email ${data.isResending ? 'resent' : 'sent'}`,
identified: `${data.isResending ? 'resent' : 'sent'} an email to ${data.recipientEmail}`,
}))
.with({ type: DOCUMENT_AUDIT_LOG_TYPE.SELF_SIGN }, () => ({
anonymous: "You've signed the document",
identified: 'signed the document',
}))
.with({ type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_COMPLETED }, () => {
// Clear the prefix since this should be considered an 'anonymous' event.
prefix = '';