1
0
mirror of https://github.com/flarum/core.git synced 2025-10-18 18:26:07 +02:00

Remove deprecated floodgate

This commit is contained in:
Alexander Skvortsov
2021-01-19 19:14:18 -05:00
parent bbb7679417
commit 86d39fb003
4 changed files with 2 additions and 123 deletions

View File

@@ -1,31 +0,0 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Post\Event;
use Flarum\User\User;
/**
* @deprecated beta 15, remove beta 16
*/
class CheckingForFlooding
{
/**
* @var User
*/
public $actor;
/**
* @param User|null $actor
*/
public function __construct(User $actor = null)
{
$this->actor = $actor;
}
}

View File

@@ -1,60 +0,0 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Post;
use DateTime;
use Flarum\Post\Event\CheckingForFlooding;
use Flarum\Post\Exception\FloodingException;
use Flarum\User\User;
use Illuminate\Contracts\Events\Dispatcher;
/**
* @deprecated beta 14, removed beta 15 in favor of Floodgate middleware
*/
class Floodgate
{
/**
* @var Dispatcher
*/
protected $events;
public function __construct(Dispatcher $events)
{
$this->events = $events;
}
/**
* @param User $actor
* @throws FloodingException
*/
public function assertNotFlooding(User $actor)
{
if ($actor->can('postWithoutThrottle')) {
return;
}
if ($this->isFlooding($actor)) {
throw new FloodingException;
}
}
/**
* @param User $actor
* @return bool
*/
public function isFlooding(User $actor): bool
{
$isFlooding = $this->events->until(
new CheckingForFlooding($actor)
);
return $isFlooding ?? Post::where('user_id', $actor->id)->where('created_at', '>=', new DateTime('-10 seconds'))->exists();
}
}