Use RequestUtil to access actor

This commit is contained in:
Alexander Skvortsov 2021-04-08 00:07:14 -04:00
parent a1ba21ec69
commit 5235dda1e4
7 changed files with 14 additions and 7 deletions

View File

@ -10,6 +10,7 @@
namespace Flarum\Tags\Api\Controller;
use Flarum\Api\Controller\AbstractCreateController;
use Flarum\Http\RequestUtil;
use Flarum\Tags\Api\Serializer\TagSerializer;
use Flarum\Tags\Command\CreateTag;
use Illuminate\Contracts\Bus\Dispatcher;
@ -48,7 +49,7 @@ class CreateTagController extends AbstractCreateController
protected function data(ServerRequestInterface $request, Document $document)
{
return $this->bus->dispatch(
new CreateTag($request->getAttribute('actor'), Arr::get($request->getParsedBody(), 'data', []))
new CreateTag(RequestUtil::getActor($request), Arr::get($request->getParsedBody(), 'data', []))
);
}
}

View File

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

View File

@ -10,6 +10,7 @@
namespace Flarum\Tags\Api\Controller;
use Flarum\Api\Controller\AbstractListController;
use Flarum\Http\RequestUtil;
use Flarum\Tags\Api\Serializer\TagSerializer;
use Flarum\Tags\Tag;
use Psr\Http\Message\ServerRequestInterface;
@ -54,7 +55,7 @@ class ListTagsController extends AbstractListController
*/
protected function data(ServerRequestInterface $request, Document $document)
{
$actor = $request->getAttribute('actor');
$actor = RequestUtil::getActor($request);
$include = $this->extractInclude($request);
$tags = $this->tags->whereVisibleTo($actor)->withStateFor($actor)->get();

View File

@ -9,6 +9,7 @@
namespace Flarum\Tags\Api\Controller;
use Flarum\Http\RequestUtil;
use Flarum\Tags\Tag;
use Illuminate\Support\Arr;
use Laminas\Diactoros\Response\EmptyResponse;
@ -23,7 +24,7 @@ class OrderTagsController implements RequestHandlerInterface
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
$request->getAttribute('actor')->assertAdmin();
RequestUtil::getActor($request)->assertAdmin();
$order = Arr::get($request->getParsedBody(), 'order');

View File

@ -10,6 +10,7 @@
namespace Flarum\Tags\Api\Controller;
use Flarum\Api\Controller\AbstractShowController;
use Flarum\Http\RequestUtil;
use Flarum\Tags\Api\Serializer\TagSerializer;
use Flarum\Tags\Command\EditTag;
use Illuminate\Contracts\Bus\Dispatcher;
@ -43,7 +44,7 @@ class UpdateTagController extends AbstractShowController
protected function data(ServerRequestInterface $request, Document $document)
{
$id = Arr::get($request->getQueryParams(), 'id');
$actor = $request->getAttribute('actor');
$actor = RequestUtil::getActor($request);
$data = Arr::get($request->getParsedBody(), 'data', []);
return $this->bus->dispatch(

View File

@ -12,6 +12,7 @@ namespace Flarum\Tags\Content;
use Flarum\Api\Client;
use Flarum\Api\Controller\ListDiscussionsController;
use Flarum\Frontend\Document;
use Flarum\Http\RequestUtil;
use Flarum\Tags\TagRepository;
use Flarum\User\User;
use Illuminate\Contracts\Translation\Translator;
@ -58,7 +59,7 @@ class Tag
public function __invoke(Document $document, Request $request)
{
$queryParams = $request->getQueryParams();
$actor = $request->getAttribute('actor');
$actor = RequestUtil::getActor($request);
$slug = Arr::pull($queryParams, 'slug');
$sort = Arr::pull($queryParams, 'sort');

View File

@ -10,6 +10,7 @@
namespace Flarum\Tags;
use Flarum\Api\Controller\ShowForumController;
use Flarum\Http\RequestUtil;
use Psr\Http\Message\ServerRequestInterface;
class LoadForumTagsRelationship
@ -21,7 +22,7 @@ class LoadForumTagsRelationship
*/
public function __invoke(ShowForumController $controller, &$data, ServerRequestInterface $request)
{
$actor = $request->getAttribute('actor');
$actor = RequestUtil::getActor($request);
// Expose the complete tag list to clients by adding it as a
// relationship to the /api endpoint. Since the Forum model