From 70a1aaedd3dc23d23ac4f072dd8f29236a1c04cd Mon Sep 17 00:00:00 2001 From: Lone Iversen <108085781+loivsen@users.noreply.github.com> Date: Tue, 9 Jan 2024 16:12:12 +0100 Subject: [PATCH] audit log handlers mock --- .../src/mocks/browser-handlers.ts | 2 + .../src/mocks/data/audit-log.data.ts | 48 ++++++++++++++++++- .../src/mocks/e2e-handlers.ts | 2 + .../src/mocks/handlers/audit-log.handlers.ts | 28 +++++++++-- 4 files changed, 75 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/mocks/browser-handlers.ts b/src/Umbraco.Web.UI.Client/src/mocks/browser-handlers.ts index f40b3f7e15..242756529b 100644 --- a/src/Umbraco.Web.UI.Client/src/mocks/browser-handlers.ts +++ b/src/Umbraco.Web.UI.Client/src/mocks/browser-handlers.ts @@ -1,3 +1,4 @@ +import { handlers as auditLogHandlers } from './handlers/audit-log.handlers.js'; import { handlers as dataTypeHandlers } from './handlers/data-type/index.js'; import { handlers as relationTypeHandlers } from './handlers/relation-type.handlers.js'; import { handlers as documentTypeHandlers } from './handlers/document-type/index.js'; @@ -37,6 +38,7 @@ import { handlers as scriptHandlers } from './handlers/scripts.handlers.js'; const handlers = [ serverHandlers.serverVersionHandler, + ...auditLogHandlers, ...configHandlers, ...cultureHandlers, ...dataTypeHandlers, diff --git a/src/Umbraco.Web.UI.Client/src/mocks/data/audit-log.data.ts b/src/Umbraco.Web.UI.Client/src/mocks/data/audit-log.data.ts index 843b6b7678..214cf9df86 100644 --- a/src/Umbraco.Web.UI.Client/src/mocks/data/audit-log.data.ts +++ b/src/Umbraco.Web.UI.Client/src/mocks/data/audit-log.data.ts @@ -1,3 +1,47 @@ -import { AuditLogResponseModel } from '@umbraco-cms/backoffice/backend-api'; +import { data as userData } from './user/user.data.js'; +import { data as documentData } from './document.data.js'; +import { AuditLogResponseModel, AuditTypeModel } from '@umbraco-cms/backoffice/backend-api'; -export const logs: Array = []; +const userId = userData[0].id; +const userName = userData[0].name; + +const documentId = documentData[0].id; + +export const logs: Array = [ + { + userId: userId, + entityId: documentId, + entityType: 'Document', + timestamp: '2021-09-14T09:32:49.0000000Z', + logType: AuditTypeModel.SAVE, + comment: undefined, + parameters: undefined, + }, + { + userId: userId, + entityId: documentId, + entityType: 'Document', + timestamp: '2022-09-14T11:30:49.0000000Z', + logType: AuditTypeModel.SAVE, + comment: undefined, + parameters: undefined, + }, + { + userId: userId, + entityId: documentId, + entityType: 'Document', + timestamp: '2022-09-15T09:35:49.0000000Z', + logType: AuditTypeModel.SAVE, + comment: undefined, + parameters: undefined, + }, + { + userId: userId, + entityId: documentId, + entityType: 'Document', + timestamp: '2023-01-09T12:00:00.0000000Z', + logType: AuditTypeModel.PUBLISH, + comment: undefined, + parameters: undefined, + }, +]; diff --git a/src/Umbraco.Web.UI.Client/src/mocks/e2e-handlers.ts b/src/Umbraco.Web.UI.Client/src/mocks/e2e-handlers.ts index 08393460d2..de0db89e66 100644 --- a/src/Umbraco.Web.UI.Client/src/mocks/e2e-handlers.ts +++ b/src/Umbraco.Web.UI.Client/src/mocks/e2e-handlers.ts @@ -1,3 +1,4 @@ +import { handlers as auditLogHandlers } from './handlers/audit-log.handlers.js'; import { handlers as dataTypeHandlers } from './handlers/data-type/index.js'; import { handlers as documentTypeHandlers } from './handlers/document-type/index.js'; import { handlers as installHandlers } from './handlers/install.handlers.js'; @@ -21,6 +22,7 @@ export const handlers = [ serverHandlers.serverRunningHandler, serverHandlers.serverVersionHandler, manifestsHandlers.manifestEmptyHandler, + ...auditLogHandlers, ...installHandlers, ...upgradeHandlers, ...userHandlers, diff --git a/src/Umbraco.Web.UI.Client/src/mocks/handlers/audit-log.handlers.ts b/src/Umbraco.Web.UI.Client/src/mocks/handlers/audit-log.handlers.ts index 6afe821ba2..e8ea2bc3cc 100644 --- a/src/Umbraco.Web.UI.Client/src/mocks/handlers/audit-log.handlers.ts +++ b/src/Umbraco.Web.UI.Client/src/mocks/handlers/audit-log.handlers.ts @@ -8,12 +8,34 @@ import { export const handlers = [ rest.get(umbracoPath('/audit-log'), (_req, res, ctx) => { - return res(ctx.status(200), ctx.json({ total: 0, items: [] })); + PagedAuditLog = { + total: logs.length, + items: logs, + }; + return res(ctx.status(200), ctx.json(PagedAuditLog)); }), rest.get(umbracoPath('/audit-log/:id'), (_req, res, ctx) => { - return res(ctx.status(200), ctx.json({ total: 0, items: [] })); + const id = _req.params.id as string; + if (!id) return; + + const foundLogs = logs.filter((log) => log.entityId === id); + PagedAuditLog = { + total: foundLogs.length, + items: foundLogs, + }; + + return res(ctx.status(200), ctx.json(PagedAuditLog)); }), rest.get(umbracoPath('/audit-log/type/:logType'), (_req, res, ctx) => { - return res(ctx.status(200), ctx.json({ total: 0, items: [] })); + const logType = _req.params.logType as string; + if (!logType) return; + + const foundLogs = logs.filter((log) => log.entityType === logType); + PagedAuditLog = { + total: foundLogs.length, + items: foundLogs, + }; + + return res(ctx.status(200), ctx.json(PagedAuditLog)); }), ];