From fedf821cafdc17785ecc845d04ca97b62e21caef Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 27 Mar 2014 23:20:35 -0700 Subject: [PATCH] CRM-14370 - API Kernel - Add UnauthorizedException, NotImplementedException Conflicts: tests/phpunit/Civi/API/Provider/DoctrineCrudProviderTest.php --- Civi/API/Exception/NotImplementedException.php | 9 +++++++++ Civi/API/Exception/UnauthorizedException.php | 9 +++++++++ Civi/API/Kernel.php | 4 ++-- Civi/API/Subscriber/PermissionCheck.php | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 Civi/API/Exception/NotImplementedException.php create mode 100644 Civi/API/Exception/UnauthorizedException.php diff --git a/Civi/API/Exception/NotImplementedException.php b/Civi/API/Exception/NotImplementedException.php new file mode 100644 index 0000000000..69db92e02f --- /dev/null +++ b/Civi/API/Exception/NotImplementedException.php @@ -0,0 +1,9 @@ +dispatcher->dispatch(Events::RESOLVE, new ResolveEvent($apiRequest)); $apiRequest = $resolveEvent->getApiRequest(); if (!$resolveEvent->getApiProvider()) { - throw new \API_Exception("API (" . $apiRequest['entity'] . ", " . $apiRequest['action'] . ") does not exist (join the API team and implement it!)", \API_Exception::NOT_IMPLEMENTED); + throw new \Civi\API\Exception\NotImplementedException("API (" . $apiRequest['entity'] . ", " . $apiRequest['action'] . ") does not exist (join the API team and implement it!)"); } return array($resolveEvent->getApiProvider(), $apiRequest); } @@ -249,7 +249,7 @@ class Kernel { public function authorize($apiProvider, $apiRequest) { $event = $this->dispatcher->dispatch(Events::AUTHORIZE, new AuthorizeEvent($apiProvider, $apiRequest)); if (!$event->isAuthorized()) { - throw new \API_Exception("Authorization failed", \API_Exception::UNAUTHORIZED); + throw new \Civi\API\Exception\UnauthorizedException("Authorization failed"); } } diff --git a/Civi/API/Subscriber/PermissionCheck.php b/Civi/API/Subscriber/PermissionCheck.php index f108d7b152..00bc3fef88 100644 --- a/Civi/API/Subscriber/PermissionCheck.php +++ b/Civi/API/Subscriber/PermissionCheck.php @@ -67,7 +67,7 @@ class PermissionCheck implements EventSubscriberInterface { $permissions = implode(' and ', $permissions); } // FIXME: Generating the exception ourselves allows for detailed error but doesn't play well with multiple authz subscribers. - throw new \API_Exception("API permission check failed for {$apiRequest['entity']}/{$apiRequest['action']} call; insufficient permission: require $permissions", \API_Exception::UNAUTHORIZED); + throw new \Civi\API\Exception\UnauthorizedException("API permission check failed for {$apiRequest['entity']}/{$apiRequest['action']} call; insufficient permission: require $permissions"); } $event->authorize(); -- 2.25.1