From 259c1966f9fecca1b90012807fb18745f091961c Mon Sep 17 00:00:00 2001 From: IanM <16573496+imorland@users.noreply.github.com> Date: Thu, 16 Nov 2023 08:27:02 +0000 Subject: [PATCH] fix: user not suspended when marked as spammer (#29) --- src/Controllers/MarkAsSpammerController.php | 2 +- tests/integration/api/SpamblockTest.php | 22 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Controllers/MarkAsSpammerController.php b/src/Controllers/MarkAsSpammerController.php index c7ca3bb..60a53f5 100644 --- a/src/Controllers/MarkAsSpammerController.php +++ b/src/Controllers/MarkAsSpammerController.php @@ -76,7 +76,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface $flarumFlags = $this->extensions->isEnabled('flarum-flags'); /** @phpstan-ignore-next-line */ - if ($this->extensions->isEnabled('flarum-suspend') && $user->suspended_until !== null) { + if ($this->extensions->isEnabled('flarum-suspend') && $user->suspended_until === null) { $this->bus->dispatch( new EditUser($user->id, $actor, [ 'attributes' => ['suspendedUntil' => Carbon::now()->addYears(20)], diff --git a/tests/integration/api/SpamblockTest.php b/tests/integration/api/SpamblockTest.php index aa9b126..376f842 100644 --- a/tests/integration/api/SpamblockTest.php +++ b/tests/integration/api/SpamblockTest.php @@ -15,6 +15,7 @@ use Flarum\Group\Group; use Flarum\Post\CommentPost; use Flarum\Testing\integration\TestCase; +use Flarum\User\User; class SpamblockTest extends TestCase { @@ -46,6 +47,27 @@ protected function setup(): void ]); } + /** + * @test + */ + public function user_is_also_suspended_when_suspend_is_enabled() + { + $this->extension('flarum-suspend'); + + $response = $this->send( + $this->request('POST', 'api/users/5/spamblock', [ + 'authenticatedAs' => 3, + ]) + ); + + $this->assertEquals(204, $response->getStatusCode()); + + $user = User::find(5); + + $this->assertNotNull($user->suspended_until); + $this->assertTrue(Carbon::parse($user->suspended_until)->greaterThan(Carbon::now()->addYears(19))); + } + /** * @test */