From e85293f3388b54541afd56ce0ea4954ff8c944f9 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Tue, 7 Oct 2014 20:58:31 +0200 Subject: [PATCH] Improved error message when search requires auth --- .../Parsers/PostSearchParser.php | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/SearchServices/Parsers/PostSearchParser.php b/src/SearchServices/Parsers/PostSearchParser.php index ef05c931..7468ec7f 100644 --- a/src/SearchServices/Parsers/PostSearchParser.php +++ b/src/SearchServices/Parsers/PostSearchParser.php @@ -4,10 +4,14 @@ namespace Szurubooru\SearchServices\Parsers; class PostSearchParser extends AbstractSearchParser { private $authService; + private $privilegeService; - public function __construct(\Szurubooru\Services\AuthService $authService) + public function __construct( + \Szurubooru\Services\AuthService $authService, + \Szurubooru\Services\PrivilegeService $privilegeService) { $this->authService = $authService; + $this->privilegeService = $privilegeService; } protected function createFilter() @@ -62,14 +66,21 @@ class PostSearchParser extends AbstractSearchParser elseif ($token->getKey() === 'comment') $this->addCommentRequirement($filter, $token); - elseif ($token->getKey() === 'special' and $token->getValue() === 'liked' and $this->authService->isLoggedIn()) - $this->addUserScoreRequirement($filter, $this->authService->getLoggedInUser()->getName(), 1, $token->isNegated()); - - elseif ($token->getKey() === 'special' and $token->getValue() === 'disliked' and $this->authService->isLoggedIn()) - $this->addUserScoreRequirement($filter, $this->authService->getLoggedInUser()->getName(), -1, $token->isNegated()); - - elseif ($token->getKey() === 'special' and $token->getValue() === 'fav' and $this->authService->isLoggedIn()) + elseif ($token->getKey() === 'special' and $token->getValue() === 'liked') { + $this->privilegeService->assertLoggedIn(); + $this->addUserScoreRequirement($filter, $this->authService->getLoggedInUser()->getName(), 1, $token->isNegated()); + } + + elseif ($token->getKey() === 'special' and $token->getValue() === 'disliked') + { + $this->privilegeService->assertLoggedIn(); + $this->addUserScoreRequirement($filter, $this->authService->getLoggedInUser()->getName(), -1, $token->isNegated()); + } + + elseif ($token->getKey() === 'special' and $token->getValue() === 'fav') + { + $this->privilegeService->assertLoggedIn(); $token = new \Szurubooru\SearchServices\Tokens\NamedSearchToken(); $token->setKey('fav'); $token->setValue($this->authService->getLoggedInUser()->getName());