mirror of
https://github.com/flarum/framework.git
synced 2025-05-25 08:09:57 +08:00
Move flood control from core to API layer
This means that flood control can be disabled depending on the nature of the request (i.e. when authenticated using a master API key). The particular use case for this is to allow using the API to migrate data from an old forum.
This commit is contained in:
@ -12,6 +12,7 @@ namespace Flarum\Api\Controller;
|
||||
|
||||
use Flarum\Core\Command\PostReply;
|
||||
use Flarum\Core\Command\ReadDiscussion;
|
||||
use Flarum\Core\Post\Floodgate;
|
||||
use Illuminate\Contracts\Bus\Dispatcher;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Tobscure\JsonApi\Document;
|
||||
@ -39,11 +40,18 @@ class CreatePostController extends AbstractCreateController
|
||||
protected $bus;
|
||||
|
||||
/**
|
||||
* @param Dispatcher $bus
|
||||
* @var Floodgate
|
||||
*/
|
||||
public function __construct(Dispatcher $bus)
|
||||
protected $floodgate;
|
||||
|
||||
/**
|
||||
* @param Dispatcher $bus
|
||||
* @param Floodgate $floodgate
|
||||
*/
|
||||
public function __construct(Dispatcher $bus, Floodgate $floodgate)
|
||||
{
|
||||
$this->bus = $bus;
|
||||
$this->floodgate = $floodgate;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,6 +64,10 @@ class CreatePostController extends AbstractCreateController
|
||||
$discussionId = array_get($data, 'relationships.discussion.data.id');
|
||||
$ipAddress = array_get($request->getServerParams(), 'REMOTE_ADDR', '127.0.0.1');
|
||||
|
||||
if (! $request->getAttribute('bypassFloodgate')) {
|
||||
$this->floodgate->assertNotFlooding($actor);
|
||||
}
|
||||
|
||||
$post = $this->bus->dispatch(
|
||||
new PostReply($discussionId, $actor, $data, $ipAddress)
|
||||
);
|
||||
|
Reference in New Issue
Block a user