mirror of
https://github.com/flarum/core.git
synced 2025-05-06 07:25:22 +02:00
Remove deprecated floodgate
This commit is contained in:
parent
bbb7679417
commit
86d39fb003
@ -12,7 +12,6 @@ namespace Flarum\Api\Controller;
|
|||||||
use Flarum\Api\Serializer\DiscussionSerializer;
|
use Flarum\Api\Serializer\DiscussionSerializer;
|
||||||
use Flarum\Discussion\Command\ReadDiscussion;
|
use Flarum\Discussion\Command\ReadDiscussion;
|
||||||
use Flarum\Discussion\Command\StartDiscussion;
|
use Flarum\Discussion\Command\StartDiscussion;
|
||||||
use Flarum\Post\Floodgate;
|
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
@ -41,19 +40,12 @@ class CreateDiscussionController extends AbstractCreateController
|
|||||||
*/
|
*/
|
||||||
protected $bus;
|
protected $bus;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Floodgate
|
|
||||||
*/
|
|
||||||
protected $floodgate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Dispatcher $bus
|
* @param Dispatcher $bus
|
||||||
* @param Floodgate $floodgate
|
|
||||||
*/
|
*/
|
||||||
public function __construct(Dispatcher $bus, Floodgate $floodgate)
|
public function __construct(Dispatcher $bus)
|
||||||
{
|
{
|
||||||
$this->bus = $bus;
|
$this->bus = $bus;
|
||||||
$this->floodgate = $floodgate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,13 +56,6 @@ class CreateDiscussionController extends AbstractCreateController
|
|||||||
$actor = $request->getAttribute('actor');
|
$actor = $request->getAttribute('actor');
|
||||||
$ipAddress = Arr::get($request->getServerParams(), 'REMOTE_ADDR', '127.0.0.1');
|
$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(
|
$discussion = $this->bus->dispatch(
|
||||||
new StartDiscussion($actor, Arr::get($request->getParsedBody(), 'data', []), $ipAddress)
|
new StartDiscussion($actor, Arr::get($request->getParsedBody(), 'data', []), $ipAddress)
|
||||||
);
|
);
|
||||||
|
@ -12,7 +12,6 @@ namespace Flarum\Api\Controller;
|
|||||||
use Flarum\Api\Serializer\PostSerializer;
|
use Flarum\Api\Serializer\PostSerializer;
|
||||||
use Flarum\Discussion\Command\ReadDiscussion;
|
use Flarum\Discussion\Command\ReadDiscussion;
|
||||||
use Flarum\Post\Command\PostReply;
|
use Flarum\Post\Command\PostReply;
|
||||||
use Flarum\Post\Floodgate;
|
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
@ -40,19 +39,12 @@ class CreatePostController extends AbstractCreateController
|
|||||||
*/
|
*/
|
||||||
protected $bus;
|
protected $bus;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Flarum\Post\Floodgate
|
|
||||||
*/
|
|
||||||
protected $floodgate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Dispatcher $bus
|
* @param Dispatcher $bus
|
||||||
* @param \Flarum\Post\Floodgate $floodgate
|
|
||||||
*/
|
*/
|
||||||
public function __construct(Dispatcher $bus, Floodgate $floodgate)
|
public function __construct(Dispatcher $bus)
|
||||||
{
|
{
|
||||||
$this->bus = $bus;
|
$this->bus = $bus;
|
||||||
$this->floodgate = $floodgate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,13 +57,6 @@ class CreatePostController extends AbstractCreateController
|
|||||||
$discussionId = Arr::get($data, 'relationships.discussion.data.id');
|
$discussionId = Arr::get($data, 'relationships.discussion.data.id');
|
||||||
$ipAddress = Arr::get($request->getServerParams(), 'REMOTE_ADDR', '127.0.0.1');
|
$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(
|
$post = $this->bus->dispatch(
|
||||||
new PostReply($discussionId, $actor, $data, $ipAddress)
|
new PostReply($discussionId, $actor, $data, $ipAddress)
|
||||||
);
|
);
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user