From 4dd055a959e584c249d609e2760f12565f01e042 Mon Sep 17 00:00:00 2001 From: IanM Date: Wed, 8 Jul 2026 13:39:01 +0100 Subject: [PATCH 1/3] feat: optional flarum/audit integration --- composer.json | 1 + extend.php | 8 ++++ resources/locale/en.yml | 9 +++++ tests/integration/AuditTest.php | 68 +++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 tests/integration/AuditTest.php diff --git a/composer.json b/composer.json index aedf28f..fc0a38b 100644 --- a/composer.json +++ b/composer.json @@ -65,6 +65,7 @@ } }, "require-dev": { + "flarum/audit": "*", "flarum/bbcode": "^2.0.0", "flarum/testing": "^2.0.0", "flarum/phpstan": "^2.0.0", diff --git a/extend.php b/extend.php index 0aadfcc..87cbb08 100644 --- a/extend.php +++ b/extend.php @@ -16,6 +16,7 @@ use Flarum\Settings\Event\Saved; use Flarum\User\Event\Saving; use Flarum\User\User; +use FoF\UserBio\Event\BioChanged; return [ (new Flarum\Frontend('forum')) @@ -56,4 +57,11 @@ (new \Flarum\Gdpr\Extend\UserData()) ->addType(Data\UserBioData::class), ]), + + (new Flarum\Conditional()) + ->whenExtensionEnabled('flarum-audit', fn () => [ + (new \Flarum\Audit\Extend\Audit()) + ->group('fof-user-bio') + ->listen(BioChanged::class, 'user.bio_changed', fn ($e) => ['user_id' => $e->user->id]), + ]), ]; diff --git a/resources/locale/en.yml b/resources/locale/en.yml index 3eed591..3abe316 100644 --- a/resources/locale/en.yml +++ b/resources/locale/en.yml @@ -19,3 +19,12 @@ fof-user-bio: cancel_button: Cancel save_button: Save edit_bio_label: Edit bio + +# Labels for the audit log entries this extension produces, rendered by the (optional) +# flarum/audit browser. Defined under the flarum-audit namespace so the audit frontend +# resolves them, but shipped here so they travel with the extension that owns the actions. +flarum-audit: + lib: + browser: + user: + bio_changed: Edited {username}'s bio diff --git a/tests/integration/AuditTest.php b/tests/integration/AuditTest.php new file mode 100644 index 0000000..37edb2d --- /dev/null +++ b/tests/integration/AuditTest.php @@ -0,0 +1,68 @@ +extension('flarum-audit', 'fof-user-bio'); + + $this->prepareDatabase([ + 'audit_log' => [], + User::class => [ + [ + 'id' => 3, + 'username' => 'user3', + 'email' => 'user3@example.com', + ], + ], + ]); + } + + #[Test] + public function update() + { + $response = $this->send($this->request('PATCH', '/api/users/3', [ + 'authenticatedAs' => 1, + 'json' => [ + 'data' => [ + 'attributes' => [ + 'bio' => 'Hello World', + ], + ], + ], + ])); + + $this->assertEquals(200, $response->getStatusCode(), $response->getBody()->getContents()); + + $log = AuditLog::query()->where('action', 'user.bio_changed')->first(); + $this->assertNotNull($log); + $this->assertEquals(1, $log->actor_id); + $this->assertEquals(['user_id' => 3], $log->payload); + $this->assertEquals('127.0.0.1', $log->ip_address); + } +} From 3cd01fa7ebd60626858f6949a5bdef7b354f0f8c Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 8 Jul 2026 13:06:42 +0000 Subject: [PATCH 2/3] Apply fixes from StyleCI --- tests/integration/AuditTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/AuditTest.php b/tests/integration/AuditTest.php index 37edb2d..6f06622 100644 --- a/tests/integration/AuditTest.php +++ b/tests/integration/AuditTest.php @@ -48,7 +48,7 @@ public function update() { $response = $this->send($this->request('PATCH', '/api/users/3', [ 'authenticatedAs' => 1, - 'json' => [ + 'json' => [ 'data' => [ 'attributes' => [ 'bio' => 'Hello World', From 79c23ffa0b1eafe9df72e25abec758a189ef7fd8 Mon Sep 17 00:00:00 2001 From: IanM Date: Wed, 8 Jul 2026 15:23:18 +0100 Subject: [PATCH 3/3] chore: track flarum/audit 2.x-dev --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fc0a38b..e3c0c6b 100644 --- a/composer.json +++ b/composer.json @@ -65,7 +65,7 @@ } }, "require-dev": { - "flarum/audit": "*", + "flarum/audit": "2.x-dev", "flarum/bbcode": "^2.0.0", "flarum/testing": "^2.0.0", "flarum/phpstan": "^2.0.0",