Skip to content

Commit e697d38

Browse files
committed
docs: enhance audit log with action badges and additional actions
1 parent 5962110 commit e697d38

3 files changed

Lines changed: 55 additions & 18 deletions

File tree

‎dev-demo/resources/auditLogs.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import AuditLogPlugin from "../../plugins/adminforth-audit-log/index.js";
33
import { AdminForthDataTypes } from "../../adminforth/index.js";
44
import { randomUUID } from "crypto";
55

6+
const actionBadge = {
7+
file: '@/renderers/EnumBadge.vue',
8+
meta: { variants: { create: 'success', edit: 'accent', delete: 'danger' } },
9+
};
10+
611
export default {
712
dataSource: 'sqlite',
813
table: 'audit_logs',
@@ -20,7 +25,21 @@ export default {
2025
foreignResource: {
2126
resourceId: 'adminuser',
2227
} },
23-
{ name: 'action', required: false },
28+
{ name: 'action', required: false,
29+
enum: [
30+
{ value: 'create', label: 'Create' },
31+
{ value: 'edit', label: 'Edit' },
32+
{ value: 'delete', label: 'Delete' },
33+
// logged by the import-export plugin
34+
{ value: 'import', label: 'Import' },
35+
{ value: 'export', label: 'Export' },
36+
// custom action of the cars resources
37+
{ value: 'visitedDashboard', label: 'Visited dashboard' },
38+
],
39+
components: {
40+
list: actionBadge,
41+
show: actionBadge,
42+
} },
2443
{ name: 'diff', required: false, type: AdminForthDataTypes.JSON, showIn: {
2544
list: false,
2645
edit: false,

‎documentation/docs/tutorial/09-Plugins/04-AuditLog.md‎

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ import AuditLogPlugin from "@adminforth/audit-log/index.js";
6363
import { AdminForthDataTypes } from "adminforth";
6464
import { randomUUID } from "crypto";
6565

66+
const actionBadge = {
67+
file: '@/renderers/EnumBadge.vue',
68+
meta: { variants: { create: 'success', edit: 'accent', delete: 'danger' } },
69+
};
70+
6671
export default {
6772
dataSource: 'maindb',
6873
table: 'audit_logs',
@@ -80,7 +85,16 @@ export default {
8085
foreignResource: {
8186
resourceId: 'adminuser',
8287
} },
83-
{ name: 'action', required: false },
88+
{ name: 'action', required: false,
89+
enum: [
90+
{ value: 'create', label: 'Create' },
91+
{ value: 'edit', label: 'Edit' },
92+
{ value: 'delete', label: 'Delete' },
93+
],
94+
components: {
95+
list: actionBadge,
96+
show: actionBadge,
97+
} },
8498
{ name: 'diff', required: false, type: AdminForthDataTypes.JSON, showIn: {
8599
list: false,
86100
edit: false,
@@ -113,6 +127,8 @@ export default {
113127
}
114128
```
115129
130+
The action is shown as a colored badge by the [Enum Badge](../03-Customization/02-customFieldRendering.md#enum-badge) renderer. The `enum` of the `action` column must list every action which gets logged: a log record with an action out of the `enum` fails validation and is not saved. Add the ids of your [custom actions](#logging-custom-actions), and `import` and `export` if you use the [Import Export](./08-import-export.md) plugin.
131+
116132
Then you need to import `./resources/auditLogs`:
117133
118134
```ts title="./index.ts"
@@ -186,10 +202,12 @@ plugins: [
186202
187203
`@adminforth/agent` records `af-agent`. `@adminforth/mcp` records the detected client, its version, and the auth secret name, for example `codex@1.2.3 | Production Codex`. Regular user actions leave the column empty. Existing configurations without `resourceExecutedByColumnName` keep their current behavior.
188204
205+
The list and the show page render the column with the logo of the agent: Claude Code, Codex or Gemini, or a bot icon for `af-agent` and other MCP clients, e.g. `codex@1.2.3 · Production Codex` with the Codex logo. Set your own `components` on the column to render it differently.
206+
189207
190208
## Logging custom actions
191209
192-
Audit log is able to catch only standard actions like `create`, `update`, `delete` or custom bulk actions.
210+
Audit log is able to catch only standard actions like `create`, `edit`, `delete` or custom bulk actions.
193211
194212
If you have a custom, self coded actions in your API, you can log them by calling `logCustomAction` method of `AuditLogPlugin` instance:
195213
@@ -217,6 +235,20 @@ app.get(`${ADMIN_BASE_URL}/api/dashboard/`,
217235

218236
```
219237
238+
Add the `actionId` to the `enum` of the `action` column, otherwise the log record is not saved:
239+
240+
```ts title='./resources/auditLogs.ts'
241+
{ name: 'action', required: false,
242+
enum: [
243+
{ value: 'create', label: 'Create' },
244+
{ value: 'edit', label: 'Edit' },
245+
{ value: 'delete', label: 'Delete' },
246+
//diff-add
247+
{ value: 'visitedDashboard', label: 'Visited dashboard' },
248+
],
249+
...
250+
```
251+
220252
## Logging client ip address
221253
222254
Audit log can also log the client's IP address if needed.
@@ -251,13 +283,6 @@ Also, update the resource configuration in `./resources/auditLogs.ts`:
251283
table: 'audit_logs',
252284
columns: [
253285
...
254-
{ name: 'action', required: false },
255-
{ name: 'diff', required: false, type: AdminForthDataTypes.JSON, showIn: {
256-
list: false,
257-
edit: false,
258-
create: false,
259-
filter: false,
260-
} },
261286
{ name: 'record_id', required: false },
262287
//diff-add
263288
{ name: 'ip_address', required: false },
@@ -317,13 +342,6 @@ Update the resource configuration in `./resources/auditLogs.ts`:
317342
table: 'audit_logs',
318343
columns: [
319344
...
320-
{ name: 'action', required: false },
321-
{ name: 'diff', required: false, type: AdminForthDataTypes.JSON, showIn: {
322-
list: false,
323-
edit: false,
324-
create: false,
325-
filter: false,
326-
} },
327345
{ name: 'record_id', required: false },
328346
{ name: 'ip_address', required: false },
329347
//diff-add

‎documentation/docs/tutorial/09-Plugins/30-mcp.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,4 +363,4 @@ new AuditLogPlugin({
363363
});
364364
```
365365

366-
MCP actions store the agent, version, and auth secret name, for example `codex@1.2.3 | Production Codex`. Actions from `@adminforth/agent` store `af-agent`. Regular user actions leave the field empty. If the mapping is omitted, Audit Log behavior remains unchanged.
366+
MCP actions store the agent, version, and auth secret name, for example `codex@1.2.3 | Production Codex`. Actions from `@adminforth/agent` store `af-agent`. Regular user actions leave the field empty. If the mapping is omitted, Audit Log behavior remains unchanged. Audit Log shows the value with the logo of the agent, see [Logging actions executed by agents](./04-AuditLog.md#logging-actions-executed-by-agents).

0 commit comments

Comments
 (0)