From 02ced2265d9b298e54b84275330cc9c4b419b559 Mon Sep 17 00:00:00 2001 From: tesaide Date: Wed, 24 Dec 2025 14:26:11 +0200 Subject: [PATCH 1/2] feat: add documentation for country IP --- .../docs/tutorial/07-Plugins/01-AuditLog.md | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/adminforth/documentation/docs/tutorial/07-Plugins/01-AuditLog.md b/adminforth/documentation/docs/tutorial/07-Plugins/01-AuditLog.md index 0398f8fd9..52c9f5594 100644 --- a/adminforth/documentation/docs/tutorial/07-Plugins/01-AuditLog.md +++ b/adminforth/documentation/docs/tutorial/07-Plugins/01-AuditLog.md @@ -244,4 +244,72 @@ Also, update the resource configuration in `./resources/auditLogs.ts`: }), ], } +``` +## Logging client ip country + +Audit log can also log the client's country if needed. + +Also, you need to migrate the `audit_logs` table in `./schema.prisma`: + +```ts title='./schema.prisma' +model audit_logs { + id String @id + created_at DateTime /// timestamp of applied change + resource_id String /// identifier of resource where change were applied + user_id String /// identifier of user who made the changes + action String /// type of change (create, edit, delete) + diff String? /// delta betwen before/after versions + record_id String? /// identifier of record that been changed + ip_address String? /// client ip address +//diff-add + country String? /// client country + +//diff-add + @@index([ip_address]) /// index for fast lookups by IP +} +``` + +And `prisma migrate`: + +```bash +npm run makemigration -- --name add-ip-address-to-audit-logs ; npm run migrate:local +``` + +Update the resource configuration in `./resources/auditLogs.ts`: + +```ts title='./resources/auditLogs.ts' + export default { + dataSource: 'maindb', + table: 'audit_logs', + columns: [ + ... + { name: 'action', required: false }, + { name: 'diff', required: false, type: AdminForthDataTypes.JSON, showIn: { + list: false, + edit: false, + create: false, + filter: false, + } }, + { name: 'record_id', required: false }, + { name: 'ip_address', required: false }, + //diff-add + { name: "country", required: false }, + ], + ... + plugins: [ + new AuditLogPlugin({ + resourceColumns: { + resourceIdColumnName: 'resource_id', + resourceActionColumnName: 'action', + resourceDataColumnName: 'diff', + resourceUserIdColumnName: 'user_id', + resourceRecordIdColumnName: 'record_id', + resourceCreatedColumnName: 'created_at' + resourceIpColumnName: "ip_address", +//diff-add + resourceCountryColumnName: "country", + } + }), + ], + } ``` \ No newline at end of file From b1bd97922a7b13d2730b6863c6dbba0fe445bcc8 Mon Sep 17 00:00:00 2001 From: tesaide Date: Wed, 24 Dec 2025 14:37:29 +0200 Subject: [PATCH 2/2] feat: add documentation for country IP --- .../documentation/docs/tutorial/07-Plugins/01-AuditLog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adminforth/documentation/docs/tutorial/07-Plugins/01-AuditLog.md b/adminforth/documentation/docs/tutorial/07-Plugins/01-AuditLog.md index 52c9f5594..a230d7d21 100644 --- a/adminforth/documentation/docs/tutorial/07-Plugins/01-AuditLog.md +++ b/adminforth/documentation/docs/tutorial/07-Plugins/01-AuditLog.md @@ -249,7 +249,7 @@ Also, update the resource configuration in `./resources/auditLogs.ts`: Audit log can also log the client's country if needed. -Also, you need to migrate the `audit_logs` table in `./schema.prisma`: +First, you need to migrate the `audit_logs` table in `./schema.prisma`: ```ts title='./schema.prisma' model audit_logs {