1
0
mirror of https://github.com/flarum/core.git synced 2025-06-27 13:14:46 +02: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:
Toby Zerner
2016-01-02 15:22:16 +10:30
parent c8027d344a
commit 07a20a10fd
6 changed files with 69 additions and 80 deletions

View File

@ -12,6 +12,7 @@ namespace Flarum\Api\Controller;
use Flarum\Core\Command\StartDiscussion;
use Flarum\Core\Command\ReadDiscussion;
use Flarum\Core\Post\Floodgate;
use Illuminate\Contracts\Bus\Dispatcher;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;
@ -40,11 +41,18 @@ class CreateDiscussionController 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;
}
/**
@ -54,6 +62,10 @@ class CreateDiscussionController extends AbstractCreateController
{
$actor = $request->getAttribute('actor');
if (! $request->getAttribute('bypassFloodgate')) {
$this->floodgate->assertNotFlooding($actor);
}
$discussion = $this->bus->dispatch(
new StartDiscussion($actor, array_get($request->getParsedBody(), 'data', []))
);