Skip to content
This repository has been archived by the owner on Nov 26, 2023. It is now read-only.

Commit

Permalink
fix: user not suspended when marked as spammer (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland authored Nov 16, 2023
1 parent 1fa4d61 commit 259c196
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Controllers/MarkAsSpammerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
Expand Down
22 changes: 22 additions & 0 deletions tests/integration/api/SpamblockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 259c196

Please sign in to comment.