From 5235dda1e45ff41cb0750e56733d6751fcca5b4f Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Thu, 8 Apr 2021 00:07:14 -0400 Subject: [PATCH] Use RequestUtil to access actor --- extensions/tags/src/Api/Controller/CreateTagController.php | 3 ++- extensions/tags/src/Api/Controller/DeleteTagController.php | 3 ++- extensions/tags/src/Api/Controller/ListTagsController.php | 3 ++- extensions/tags/src/Api/Controller/OrderTagsController.php | 3 ++- extensions/tags/src/Api/Controller/UpdateTagController.php | 3 ++- extensions/tags/src/Content/Tag.php | 3 ++- extensions/tags/src/LoadForumTagsRelationship.php | 3 ++- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/extensions/tags/src/Api/Controller/CreateTagController.php b/extensions/tags/src/Api/Controller/CreateTagController.php index fb1b7f9d5..7c5c75417 100644 --- a/extensions/tags/src/Api/Controller/CreateTagController.php +++ b/extensions/tags/src/Api/Controller/CreateTagController.php @@ -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', [])) ); } } diff --git a/extensions/tags/src/Api/Controller/DeleteTagController.php b/extensions/tags/src/Api/Controller/DeleteTagController.php index 971ce4feb..910a6a8ec 100644 --- a/extensions/tags/src/Api/Controller/DeleteTagController.php +++ b/extensions/tags/src/Api/Controller/DeleteTagController.php @@ -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)) ); } } diff --git a/extensions/tags/src/Api/Controller/ListTagsController.php b/extensions/tags/src/Api/Controller/ListTagsController.php index 966492973..9571f1e10 100644 --- a/extensions/tags/src/Api/Controller/ListTagsController.php +++ b/extensions/tags/src/Api/Controller/ListTagsController.php @@ -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(); diff --git a/extensions/tags/src/Api/Controller/OrderTagsController.php b/extensions/tags/src/Api/Controller/OrderTagsController.php index b1441ad37..41b0e2f44 100644 --- a/extensions/tags/src/Api/Controller/OrderTagsController.php +++ b/extensions/tags/src/Api/Controller/OrderTagsController.php @@ -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'); diff --git a/extensions/tags/src/Api/Controller/UpdateTagController.php b/extensions/tags/src/Api/Controller/UpdateTagController.php index 845ff4de0..b5ac3549a 100644 --- a/extensions/tags/src/Api/Controller/UpdateTagController.php +++ b/extensions/tags/src/Api/Controller/UpdateTagController.php @@ -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( diff --git a/extensions/tags/src/Content/Tag.php b/extensions/tags/src/Content/Tag.php index 507c7bdc9..3a2d8dae0 100644 --- a/extensions/tags/src/Content/Tag.php +++ b/extensions/tags/src/Content/Tag.php @@ -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'); diff --git a/extensions/tags/src/LoadForumTagsRelationship.php b/extensions/tags/src/LoadForumTagsRelationship.php index e44ff8421..c7c34ca60 100755 --- a/extensions/tags/src/LoadForumTagsRelationship.php +++ b/extensions/tags/src/LoadForumTagsRelationship.php @@ -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