Use RequestUtil for accessing actor

This commit is contained in:
Alexander Skvortsov 2021-04-08 00:02:11 -04:00
parent 9936681634
commit f80a88d45b
4 changed files with 8 additions and 4 deletions

View File

@ -12,6 +12,7 @@ namespace Flarum\Flags\Api\Controller;
use Flarum\Api\Controller\AbstractCreateController;
use Flarum\Flags\Api\Serializer\FlagSerializer;
use Flarum\Flags\Command\CreateFlag;
use Flarum\Http\RequestUtil;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
@ -51,7 +52,7 @@ class CreateFlagController extends AbstractCreateController
protected function data(ServerRequestInterface $request, Document $document)
{
return $this->bus->dispatch(
new CreateFlag($request->getAttribute('actor'), Arr::get($request->getParsedBody(), 'data', []))
new CreateFlag(RequestUtil::getActor($request), Arr::get($request->getParsedBody(), 'data', []))
);
}
}

View File

@ -11,6 +11,7 @@ namespace Flarum\Flags\Api\Controller;
use Flarum\Api\Controller\AbstractDeleteController;
use Flarum\Flags\Command\DeleteFlags;
use Flarum\Http\RequestUtil;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
@ -36,7 +37,7 @@ class DeleteFlagsController extends AbstractDeleteController
protected function delete(ServerRequestInterface $request)
{
$this->bus->dispatch(
new DeleteFlags(Arr::get($request->getQueryParams(), 'id'), $request->getAttribute('actor'), $request->getParsedBody())
new DeleteFlags(Arr::get($request->getQueryParams(), 'id'), RequestUtil::getActor($request), $request->getParsedBody())
);
}
}

View File

@ -12,6 +12,7 @@ namespace Flarum\Flags\Api\Controller;
use Flarum\Api\Controller\AbstractListController;
use Flarum\Flags\Api\Serializer\FlagSerializer;
use Flarum\Flags\Flag;
use Flarum\Http\RequestUtil;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;
@ -37,7 +38,7 @@ class ListFlagsController extends AbstractListController
*/
protected function data(ServerRequestInterface $request, Document $document)
{
$actor = $request->getAttribute('actor');
$actor = RequestUtil::getActor($request);
$include = $this->extractInclude($request);
$actor->assertRegistered();

View File

@ -11,6 +11,7 @@ namespace Flarum\Flags;
use Flarum\Api\Controller;
use Flarum\Flags\Api\Controller\CreateFlagController;
use Flarum\Http\RequestUtil;
use Illuminate\Database\Eloquent\Collection;
use Psr\Http\Message\ServerRequestInterface;
@ -41,7 +42,7 @@ class PrepareFlagsApiData
}
if (isset($posts)) {
$actor = $request->getAttribute('actor');
$actor = RequestUtil::getActor($request);
$postsWithPermission = [];
foreach ($posts as $post) {