diff options
Diffstat (limited to 'apps/provisioning_api')
5 files changed, 23 insertions, 20 deletions
diff --git a/apps/provisioning_api/lib/Controller/AppsController.php b/apps/provisioning_api/lib/Controller/AppsController.php index d0c91c3cee8..6a6db017f99 100644 --- a/apps/provisioning_api/lib/Controller/AppsController.php +++ b/apps/provisioning_api/lib/Controller/AppsController.php @@ -31,7 +31,6 @@ declare(strict_types=1); namespace OCA\Provisioning_API\Controller; use OC_App; -use OCP\API; use OCP\App\AppPathNotFoundException; use OCP\App\IAppManager; use OCP\AppFramework\Http\DataResponse; @@ -93,7 +92,7 @@ class AppsController extends OCSController { return new DataResponse($info); } - throw new OCSException('The request app was not found', API::RESPOND_NOT_FOUND); + throw new OCSException('The request app was not found', OCSController::RESPOND_NOT_FOUND); } /** @@ -106,7 +105,7 @@ class AppsController extends OCSController { try { $this->appManager->enableApp($app); } catch (AppPathNotFoundException $e) { - throw new OCSException('The request app was not found', API::RESPOND_NOT_FOUND); + throw new OCSException('The request app was not found', OCSController::RESPOND_NOT_FOUND); } return new DataResponse(); } diff --git a/apps/provisioning_api/lib/Controller/GroupsController.php b/apps/provisioning_api/lib/Controller/GroupsController.php index d91f5892f05..b031c405046 100644 --- a/apps/provisioning_api/lib/Controller/GroupsController.php +++ b/apps/provisioning_api/lib/Controller/GroupsController.php @@ -39,6 +39,7 @@ use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSException; use OCP\AppFramework\OCS\OCSForbiddenException; use OCP\AppFramework\OCS\OCSNotFoundException; +use OCP\AppFramework\OCSController; use OCP\IConfig; use OCP\IGroup; use OCP\IGroupManager; @@ -195,7 +196,7 @@ class GroupsController extends AUserData { if ($group !== null) { $isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminOfGroup($currentUser, $group); } else { - throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND); + throw new OCSException('The requested group could not be found', OCSController::RESPOND_NOT_FOUND); } // Check subadmin has access to this group @@ -224,7 +225,7 @@ class GroupsController extends AUserData { return new DataResponse(['users' => $usersDetails]); } - throw new OCSException('User does not have access to specified group', \OCP\API::RESPOND_UNAUTHORISED); + throw new OCSException('User does not have access to specified group', OCSController::RESPOND_UNAUTHORISED); } /** @@ -270,7 +271,7 @@ class GroupsController extends AUserData { throw new OCSException('Not supported by backend', 101); } else { - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); + throw new OCSException('', OCSController::RESPOND_UNAUTHORISED); } } diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index 9b249a9db5f..b4a0c557539 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -57,6 +57,7 @@ use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSException; use OCP\AppFramework\OCS\OCSForbiddenException; +use OCP\AppFramework\OCSController; use OCP\IConfig; use OCP\IGroup; use OCP\IGroupManager; @@ -469,7 +470,7 @@ class UsersController extends AUserData { $data = $this->getUserData($userId); // getUserData returns empty array if not enough permissions if (empty($data)) { - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); + throw new OCSException('', OCSController::RESPOND_UNAUTHORISED); } return new DataResponse($data); } @@ -494,7 +495,7 @@ class UsersController extends AUserData { return new DataResponse($data); } - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); + throw new OCSException('', OCSController::RESPOND_UNAUTHORISED); } /** @@ -541,7 +542,7 @@ class UsersController extends AUserData { $targetUser = $this->userManager->get($userId); if ($targetUser === null) { - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); + throw new OCSException('', OCSController::RESPOND_UNAUTHORISED); } $permittedFields = []; @@ -597,12 +598,12 @@ class UsersController extends AUserData { $permittedFields[] = 'quota'; } else { // No rights - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); + throw new OCSException('', OCSController::RESPOND_UNAUTHORISED); } } // Check if permitted to edit this field if (!in_array($key, $permittedFields)) { - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); + throw new OCSException('', OCSController::RESPOND_UNAUTHORISED); } // Process the edit switch ($key) { @@ -702,7 +703,7 @@ class UsersController extends AUserData { // If not permitted $subAdminManager = $this->groupManager->getSubAdmin(); if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); + throw new OCSException('', OCSController::RESPOND_UNAUTHORISED); } $this->remoteWipe->markAllTokensForWipe($targetUser); @@ -730,7 +731,7 @@ class UsersController extends AUserData { // If not permitted $subAdminManager = $this->groupManager->getSubAdmin(); if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); + throw new OCSException('', OCSController::RESPOND_UNAUTHORISED); } // Go ahead with the delete @@ -784,7 +785,7 @@ class UsersController extends AUserData { // If not permitted $subAdminManager = $this->groupManager->getSubAdmin(); if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); + throw new OCSException('', OCSController::RESPOND_UNAUTHORISED); } // enable/disable the user now @@ -805,7 +806,7 @@ class UsersController extends AUserData { $targetUser = $this->userManager->get($userId); if ($targetUser === null) { - throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); + throw new OCSException('', OCSController::RESPOND_NOT_FOUND); } if ($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { @@ -831,7 +832,7 @@ class UsersController extends AUserData { return new DataResponse(['groups' => $groups]); } else { // Not permitted - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); + throw new OCSException('', OCSController::RESPOND_UNAUTHORISED); } } } @@ -1031,7 +1032,7 @@ class UsersController extends AUserData { $targetUser = $this->userManager->get($userId); if ($targetUser === null) { - throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); + throw new OCSException('', OCSController::RESPOND_NOT_FOUND); } // Check if admin / subadmin @@ -1039,7 +1040,7 @@ class UsersController extends AUserData { if (!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) { // No rights - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); + throw new OCSException('', OCSController::RESPOND_UNAUTHORISED); } $email = $targetUser->getEMailAddress(); diff --git a/apps/provisioning_api/lib/Middleware/ProvisioningApiMiddleware.php b/apps/provisioning_api/lib/Middleware/ProvisioningApiMiddleware.php index e5a93fc402a..a8bb8140060 100644 --- a/apps/provisioning_api/lib/Middleware/ProvisioningApiMiddleware.php +++ b/apps/provisioning_api/lib/Middleware/ProvisioningApiMiddleware.php @@ -33,6 +33,7 @@ use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Middleware; use OCP\AppFramework\OCS\OCSException; +use OCP\AppFramework\OCSController; use OCP\AppFramework\Utility\IControllerMethodReflector; class ProvisioningApiMiddleware extends Middleware { @@ -83,7 +84,7 @@ class ProvisioningApiMiddleware extends Middleware { */ public function afterException($controller, $methodName, \Exception $exception) { if ($exception instanceof NotSubAdminException) { - throw new OCSException($exception->getMessage(), \OCP\API::RESPOND_UNAUTHORISED); + throw new OCSException($exception->getMessage(), OCSController::RESPOND_UNAUTHORISED); } throw $exception; diff --git a/apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php b/apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php index 1b4bb6e81a2..4565bde42a2 100644 --- a/apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php +++ b/apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php @@ -28,6 +28,7 @@ use OCA\Provisioning_API\Middleware\Exceptions\NotSubAdminException; use OCA\Provisioning_API\Middleware\ProvisioningApiMiddleware; use OCP\AppFramework\Controller; use OCP\AppFramework\OCS\OCSException; +use OCP\AppFramework\OCSController; use OCP\AppFramework\Utility\IControllerMethodReflector; use Test\TestCase; @@ -114,7 +115,7 @@ class ProvisioningApiMiddlewareTest extends TestCase { } catch (OCSException $e) { $this->assertFalse($forwared); $this->assertSame($exception->getMessage(), $e->getMessage()); - $this->assertSame(\OCP\API::RESPOND_UNAUTHORISED, $e->getCode()); + $this->assertSame(OCSController::RESPOND_UNAUTHORISED, $e->getCode()); } catch (\Exception $e) { $this->assertTrue($forwared); $this->assertSame($exception, $e); |