From 02ced2265d9b298e54b84275330cc9c4b419b559 Mon Sep 17 00:00:00 2001 From: tesaide Date: Wed, 24 Dec 2025 14:26:11 +0200 Subject: [PATCH 1/3] 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/3] 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 { From 750a224dc0265d28c885ffcdb6f484606f1a0ec6 Mon Sep 17 00:00:00 2001 From: yaroslav8765 Date: Fri, 9 Jan 2026 12:07:25 +0200 Subject: [PATCH 3/3] docs: update docs for the audit log --- .../docs/tutorial/07-Plugins/01-AuditLog.md | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/adminforth/documentation/docs/tutorial/07-Plugins/01-AuditLog.md b/adminforth/documentation/docs/tutorial/07-Plugins/01-AuditLog.md index a230d7d21..b62001e2b 100644 --- a/adminforth/documentation/docs/tutorial/07-Plugins/01-AuditLog.md +++ b/adminforth/documentation/docs/tutorial/07-Plugins/01-AuditLog.md @@ -292,8 +292,22 @@ Update the resource configuration in `./resources/auditLogs.ts`: } }, { name: 'record_id', required: false }, { name: 'ip_address', required: false }, - //diff-add - { name: "country", required: false }, + //diff-add + { + //diff-add + name: "country", + //diff-add + required: false, + //diff-add + components: { + //diff-add + list: '@/renderers/CountryFlag.vue' + //diff-add + show: '@/renderers/CountryFlag.vue' + //diff-add + }, + //diff-add + }, ], ... plugins: [ @@ -312,4 +326,27 @@ Update the resource configuration in `./resources/auditLogs.ts`: }), ], } +``` + +### Providing Country Headers + +If your deployed app has header with user country in ISO 3166-1 alpha-2 format, you can specify this header, so country will be taken from it: + +```ts +plugins: [ + new AuditLogPlugin({ + //diff-add + isoCountryCodeRequestHeader: 'CF-IPCountry', + resourceColumns: { + resourceIdColumnName: 'resource_id', + resourceActionColumnName: 'action', + resourceDataColumnName: 'diff', + resourceUserIdColumnName: 'user_id', + resourceRecordIdColumnName: 'record_id', + resourceCreatedColumnName: 'created_at' + resourceIpColumnName: "ip_address", + resourceCountryColumnName: "country", + } + }), + ], ``` \ No newline at end of file