From 30a26b02f49c7d5f605fd899d001b30e1c16ecbb Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Tue, 19 Jan 2021 19:14:18 -0500 Subject: [PATCH] Remove deprecated floodgate --- .../Controller/CreateDiscussionController.php | 17 +----- .../Api/Controller/CreatePostController.php | 17 +----- .../src/Post/Event/CheckingForFlooding.php | 31 ---------- framework/core/src/Post/Floodgate.php | 60 ------------------- 4 files changed, 2 insertions(+), 123 deletions(-) delete mode 100644 framework/core/src/Post/Event/CheckingForFlooding.php delete mode 100644 framework/core/src/Post/Floodgate.php diff --git a/framework/core/src/Api/Controller/CreateDiscussionController.php b/framework/core/src/Api/Controller/CreateDiscussionController.php index e4c8b7717..16d9443c2 100644 --- a/framework/core/src/Api/Controller/CreateDiscussionController.php +++ b/framework/core/src/Api/Controller/CreateDiscussionController.php @@ -12,7 +12,6 @@ namespace Flarum\Api\Controller; use Flarum\Api\Serializer\DiscussionSerializer; use Flarum\Discussion\Command\ReadDiscussion; use Flarum\Discussion\Command\StartDiscussion; -use Flarum\Post\Floodgate; use Illuminate\Contracts\Bus\Dispatcher; use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface; @@ -41,19 +40,12 @@ class CreateDiscussionController extends AbstractCreateController */ protected $bus; - /** - * @var Floodgate - */ - protected $floodgate; - /** * @param Dispatcher $bus - * @param Floodgate $floodgate */ - public function __construct(Dispatcher $bus, Floodgate $floodgate) + public function __construct(Dispatcher $bus) { $this->bus = $bus; - $this->floodgate = $floodgate; } /** @@ -64,13 +56,6 @@ class CreateDiscussionController extends AbstractCreateController $actor = $request->getAttribute('actor'); $ipAddress = Arr::get($request->getServerParams(), 'REMOTE_ADDR', '127.0.0.1'); - /** - * @deprecated, remove in beta 15. - */ - if (! $request->getAttribute('bypassFloodgate')) { - $this->floodgate->assertNotFlooding($actor); - } - $discussion = $this->bus->dispatch( new StartDiscussion($actor, Arr::get($request->getParsedBody(), 'data', []), $ipAddress) ); diff --git a/framework/core/src/Api/Controller/CreatePostController.php b/framework/core/src/Api/Controller/CreatePostController.php index 8209daede..171130955 100644 --- a/framework/core/src/Api/Controller/CreatePostController.php +++ b/framework/core/src/Api/Controller/CreatePostController.php @@ -12,7 +12,6 @@ namespace Flarum\Api\Controller; use Flarum\Api\Serializer\PostSerializer; use Flarum\Discussion\Command\ReadDiscussion; use Flarum\Post\Command\PostReply; -use Flarum\Post\Floodgate; use Illuminate\Contracts\Bus\Dispatcher; use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface; @@ -40,19 +39,12 @@ class CreatePostController extends AbstractCreateController */ protected $bus; - /** - * @var \Flarum\Post\Floodgate - */ - protected $floodgate; - /** * @param Dispatcher $bus - * @param \Flarum\Post\Floodgate $floodgate */ - public function __construct(Dispatcher $bus, Floodgate $floodgate) + public function __construct(Dispatcher $bus) { $this->bus = $bus; - $this->floodgate = $floodgate; } /** @@ -65,13 +57,6 @@ class CreatePostController extends AbstractCreateController $discussionId = Arr::get($data, 'relationships.discussion.data.id'); $ipAddress = Arr::get($request->getServerParams(), 'REMOTE_ADDR', '127.0.0.1'); - /** - * @deprecated, remove in beta 15. - */ - if (! $request->getAttribute('bypassFloodgate')) { - $this->floodgate->assertNotFlooding($actor); - } - $post = $this->bus->dispatch( new PostReply($discussionId, $actor, $data, $ipAddress) ); diff --git a/framework/core/src/Post/Event/CheckingForFlooding.php b/framework/core/src/Post/Event/CheckingForFlooding.php deleted file mode 100644 index c46a920d5..000000000 --- a/framework/core/src/Post/Event/CheckingForFlooding.php +++ /dev/null @@ -1,31 +0,0 @@ -actor = $actor; - } -} diff --git a/framework/core/src/Post/Floodgate.php b/framework/core/src/Post/Floodgate.php deleted file mode 100644 index 55374964f..000000000 --- a/framework/core/src/Post/Floodgate.php +++ /dev/null @@ -1,60 +0,0 @@ -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(); - } -}