Merge pull request #25917 from nextcloud/techdept/kill_deprecated/ocp_api
Remove deprecated \OCP\API
This commit is contained in:
commit
5325c3002c
|
@ -31,7 +31,6 @@ declare(strict_types=1);
|
||||||
namespace OCA\Provisioning_API\Controller;
|
namespace OCA\Provisioning_API\Controller;
|
||||||
|
|
||||||
use OC_App;
|
use OC_App;
|
||||||
use OCP\API;
|
|
||||||
use OCP\App\AppPathNotFoundException;
|
use OCP\App\AppPathNotFoundException;
|
||||||
use OCP\App\IAppManager;
|
use OCP\App\IAppManager;
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
|
@ -93,7 +92,7 @@ class AppsController extends OCSController {
|
||||||
return new DataResponse($info);
|
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 {
|
try {
|
||||||
$this->appManager->enableApp($app);
|
$this->appManager->enableApp($app);
|
||||||
} catch (AppPathNotFoundException $e) {
|
} 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();
|
return new DataResponse();
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ use OCP\AppFramework\Http\DataResponse;
|
||||||
use OCP\AppFramework\OCS\OCSException;
|
use OCP\AppFramework\OCS\OCSException;
|
||||||
use OCP\AppFramework\OCS\OCSForbiddenException;
|
use OCP\AppFramework\OCS\OCSForbiddenException;
|
||||||
use OCP\AppFramework\OCS\OCSNotFoundException;
|
use OCP\AppFramework\OCS\OCSNotFoundException;
|
||||||
|
use OCP\AppFramework\OCSController;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\IGroup;
|
use OCP\IGroup;
|
||||||
use OCP\IGroupManager;
|
use OCP\IGroupManager;
|
||||||
|
@ -195,7 +196,7 @@ class GroupsController extends AUserData {
|
||||||
if ($group !== null) {
|
if ($group !== null) {
|
||||||
$isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminOfGroup($currentUser, $group);
|
$isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminOfGroup($currentUser, $group);
|
||||||
} else {
|
} 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
|
// Check subadmin has access to this group
|
||||||
|
@ -224,7 +225,7 @@ class GroupsController extends AUserData {
|
||||||
return new DataResponse(['users' => $usersDetails]);
|
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);
|
throw new OCSException('Not supported by backend', 101);
|
||||||
} else {
|
} else {
|
||||||
throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
|
throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@ use OCP\AppFramework\Http;
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
use OCP\AppFramework\OCS\OCSException;
|
use OCP\AppFramework\OCS\OCSException;
|
||||||
use OCP\AppFramework\OCS\OCSForbiddenException;
|
use OCP\AppFramework\OCS\OCSForbiddenException;
|
||||||
|
use OCP\AppFramework\OCSController;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\IGroup;
|
use OCP\IGroup;
|
||||||
use OCP\IGroupManager;
|
use OCP\IGroupManager;
|
||||||
|
@ -469,7 +470,7 @@ class UsersController extends AUserData {
|
||||||
$data = $this->getUserData($userId);
|
$data = $this->getUserData($userId);
|
||||||
// getUserData returns empty array if not enough permissions
|
// getUserData returns empty array if not enough permissions
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
|
throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
|
||||||
}
|
}
|
||||||
return new DataResponse($data);
|
return new DataResponse($data);
|
||||||
}
|
}
|
||||||
|
@ -494,7 +495,7 @@ class UsersController extends AUserData {
|
||||||
return new DataResponse($data);
|
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);
|
$targetUser = $this->userManager->get($userId);
|
||||||
if ($targetUser === null) {
|
if ($targetUser === null) {
|
||||||
throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
|
throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
|
||||||
}
|
}
|
||||||
|
|
||||||
$permittedFields = [];
|
$permittedFields = [];
|
||||||
|
@ -597,12 +598,12 @@ class UsersController extends AUserData {
|
||||||
$permittedFields[] = 'quota';
|
$permittedFields[] = 'quota';
|
||||||
} else {
|
} else {
|
||||||
// No rights
|
// No rights
|
||||||
throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
|
throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check if permitted to edit this field
|
// Check if permitted to edit this field
|
||||||
if (!in_array($key, $permittedFields)) {
|
if (!in_array($key, $permittedFields)) {
|
||||||
throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
|
throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
|
||||||
}
|
}
|
||||||
// Process the edit
|
// Process the edit
|
||||||
switch ($key) {
|
switch ($key) {
|
||||||
|
@ -702,7 +703,7 @@ class UsersController extends AUserData {
|
||||||
// If not permitted
|
// If not permitted
|
||||||
$subAdminManager = $this->groupManager->getSubAdmin();
|
$subAdminManager = $this->groupManager->getSubAdmin();
|
||||||
if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
|
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);
|
$this->remoteWipe->markAllTokensForWipe($targetUser);
|
||||||
|
@ -730,7 +731,7 @@ class UsersController extends AUserData {
|
||||||
// If not permitted
|
// If not permitted
|
||||||
$subAdminManager = $this->groupManager->getSubAdmin();
|
$subAdminManager = $this->groupManager->getSubAdmin();
|
||||||
if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
|
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
|
// Go ahead with the delete
|
||||||
|
@ -784,7 +785,7 @@ class UsersController extends AUserData {
|
||||||
// If not permitted
|
// If not permitted
|
||||||
$subAdminManager = $this->groupManager->getSubAdmin();
|
$subAdminManager = $this->groupManager->getSubAdmin();
|
||||||
if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
|
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
|
// enable/disable the user now
|
||||||
|
@ -805,7 +806,7 @@ class UsersController extends AUserData {
|
||||||
|
|
||||||
$targetUser = $this->userManager->get($userId);
|
$targetUser = $this->userManager->get($userId);
|
||||||
if ($targetUser === null) {
|
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())) {
|
if ($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) {
|
||||||
|
@ -831,7 +832,7 @@ class UsersController extends AUserData {
|
||||||
return new DataResponse(['groups' => $groups]);
|
return new DataResponse(['groups' => $groups]);
|
||||||
} else {
|
} else {
|
||||||
// Not permitted
|
// 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);
|
$targetUser = $this->userManager->get($userId);
|
||||||
if ($targetUser === null) {
|
if ($targetUser === null) {
|
||||||
throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND);
|
throw new OCSException('', OCSController::RESPOND_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if admin / subadmin
|
// Check if admin / subadmin
|
||||||
|
@ -1039,7 +1040,7 @@ class UsersController extends AUserData {
|
||||||
if (!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)
|
if (!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)
|
||||||
&& !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
|
&& !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
|
||||||
// No rights
|
// No rights
|
||||||
throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
|
throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
|
||||||
}
|
}
|
||||||
|
|
||||||
$email = $targetUser->getEMailAddress();
|
$email = $targetUser->getEMailAddress();
|
||||||
|
|
|
@ -33,6 +33,7 @@ use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http\Response;
|
use OCP\AppFramework\Http\Response;
|
||||||
use OCP\AppFramework\Middleware;
|
use OCP\AppFramework\Middleware;
|
||||||
use OCP\AppFramework\OCS\OCSException;
|
use OCP\AppFramework\OCS\OCSException;
|
||||||
|
use OCP\AppFramework\OCSController;
|
||||||
use OCP\AppFramework\Utility\IControllerMethodReflector;
|
use OCP\AppFramework\Utility\IControllerMethodReflector;
|
||||||
|
|
||||||
class ProvisioningApiMiddleware extends Middleware {
|
class ProvisioningApiMiddleware extends Middleware {
|
||||||
|
@ -83,7 +84,7 @@ class ProvisioningApiMiddleware extends Middleware {
|
||||||
*/
|
*/
|
||||||
public function afterException($controller, $methodName, \Exception $exception) {
|
public function afterException($controller, $methodName, \Exception $exception) {
|
||||||
if ($exception instanceof NotSubAdminException) {
|
if ($exception instanceof NotSubAdminException) {
|
||||||
throw new OCSException($exception->getMessage(), \OCP\API::RESPOND_UNAUTHORISED);
|
throw new OCSException($exception->getMessage(), OCSController::RESPOND_UNAUTHORISED);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw $exception;
|
throw $exception;
|
||||||
|
|
|
@ -28,6 +28,7 @@ use OCA\Provisioning_API\Middleware\Exceptions\NotSubAdminException;
|
||||||
use OCA\Provisioning_API\Middleware\ProvisioningApiMiddleware;
|
use OCA\Provisioning_API\Middleware\ProvisioningApiMiddleware;
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\OCS\OCSException;
|
use OCP\AppFramework\OCS\OCSException;
|
||||||
|
use OCP\AppFramework\OCSController;
|
||||||
use OCP\AppFramework\Utility\IControllerMethodReflector;
|
use OCP\AppFramework\Utility\IControllerMethodReflector;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
|
@ -114,7 +115,7 @@ class ProvisioningApiMiddlewareTest extends TestCase {
|
||||||
} catch (OCSException $e) {
|
} catch (OCSException $e) {
|
||||||
$this->assertFalse($forwared);
|
$this->assertFalse($forwared);
|
||||||
$this->assertSame($exception->getMessage(), $e->getMessage());
|
$this->assertSame($exception->getMessage(), $e->getMessage());
|
||||||
$this->assertSame(\OCP\API::RESPOND_UNAUTHORISED, $e->getCode());
|
$this->assertSame(OCSController::RESPOND_UNAUTHORISED, $e->getCode());
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertTrue($forwared);
|
$this->assertTrue($forwared);
|
||||||
$this->assertSame($exception, $e);
|
$this->assertSame($exception, $e);
|
||||||
|
|
|
@ -7,7 +7,6 @@ $baseDir = dirname(dirname($vendorDir));
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
|
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
|
||||||
'OCP\\API' => $baseDir . '/lib/public/API.php',
|
|
||||||
'OCP\\Accounts\\IAccount' => $baseDir . '/lib/public/Accounts/IAccount.php',
|
'OCP\\Accounts\\IAccount' => $baseDir . '/lib/public/Accounts/IAccount.php',
|
||||||
'OCP\\Accounts\\IAccountManager' => $baseDir . '/lib/public/Accounts/IAccountManager.php',
|
'OCP\\Accounts\\IAccountManager' => $baseDir . '/lib/public/Accounts/IAccountManager.php',
|
||||||
'OCP\\Accounts\\IAccountProperty' => $baseDir . '/lib/public/Accounts/IAccountProperty.php',
|
'OCP\\Accounts\\IAccountProperty' => $baseDir . '/lib/public/Accounts/IAccountProperty.php',
|
||||||
|
|
|
@ -36,7 +36,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
|
||||||
|
|
||||||
public static $classMap = array (
|
public static $classMap = array (
|
||||||
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
|
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
|
||||||
'OCP\\API' => __DIR__ . '/../../..' . '/lib/public/API.php',
|
|
||||||
'OCP\\Accounts\\IAccount' => __DIR__ . '/../../..' . '/lib/public/Accounts/IAccount.php',
|
'OCP\\Accounts\\IAccount' => __DIR__ . '/../../..' . '/lib/public/Accounts/IAccount.php',
|
||||||
'OCP\\Accounts\\IAccountManager' => __DIR__ . '/../../..' . '/lib/public/Accounts/IAccountManager.php',
|
'OCP\\Accounts\\IAccountManager' => __DIR__ . '/../../..' . '/lib/public/Accounts/IAccountManager.php',
|
||||||
'OCP\\Accounts\\IAccountProperty' => __DIR__ . '/../../..' . '/lib/public/Accounts/IAccountProperty.php',
|
'OCP\\Accounts\\IAccountProperty' => __DIR__ . '/../../..' . '/lib/public/Accounts/IAccountProperty.php',
|
||||||
|
|
|
@ -29,7 +29,6 @@ use OC\AppFramework\Http;
|
||||||
use OC\AppFramework\OCS\BaseResponse;
|
use OC\AppFramework\OCS\BaseResponse;
|
||||||
use OC\AppFramework\OCS\V1Response;
|
use OC\AppFramework\OCS\V1Response;
|
||||||
use OC\AppFramework\OCS\V2Response;
|
use OC\AppFramework\OCS\V2Response;
|
||||||
use OCP\API;
|
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
use OCP\AppFramework\Http\JSONResponse;
|
use OCP\AppFramework\Http\JSONResponse;
|
||||||
|
@ -80,7 +79,7 @@ class OCSMiddleware extends Middleware {
|
||||||
if ($controller instanceof OCSController && $exception instanceof OCSException) {
|
if ($controller instanceof OCSController && $exception instanceof OCSException) {
|
||||||
$code = $exception->getCode();
|
$code = $exception->getCode();
|
||||||
if ($code === 0) {
|
if ($code === 0) {
|
||||||
$code = API::RESPOND_UNKNOWN_ERROR;
|
$code = \OCP\AppFramework\OCSController::RESPOND_UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->buildNewResponse($controller, $code, $exception->getMessage());
|
return $this->buildNewResponse($controller, $code, $exception->getMessage());
|
||||||
|
@ -109,7 +108,7 @@ class OCSMiddleware extends Middleware {
|
||||||
$message = $response->getData()['message'];
|
$message = $response->getData()['message'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->buildNewResponse($controller, API::RESPOND_UNAUTHORISED, $message);
|
return $this->buildNewResponse($controller, OCSController::RESPOND_UNAUTHORISED, $message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
|
|
||||||
namespace OC\AppFramework\OCS;
|
namespace OC\AppFramework\OCS;
|
||||||
|
|
||||||
use OCP\API;
|
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
|
use OCP\AppFramework\OCSController;
|
||||||
|
|
||||||
class V1Response extends BaseResponse {
|
class V1Response extends BaseResponse {
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ class V1Response extends BaseResponse {
|
||||||
*/
|
*/
|
||||||
public function getStatus() {
|
public function getStatus() {
|
||||||
$status = parent::getStatus();
|
$status = parent::getStatus();
|
||||||
if ($status === Http::STATUS_FORBIDDEN || $status === API::RESPOND_UNAUTHORISED) {
|
if ($status === Http::STATUS_FORBIDDEN || $status === OCSController::RESPOND_UNAUTHORISED) {
|
||||||
return Http::STATUS_UNAUTHORIZED;
|
return Http::STATUS_UNAUTHORIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
|
|
||||||
namespace OC\AppFramework\OCS;
|
namespace OC\AppFramework\OCS;
|
||||||
|
|
||||||
use OCP\API;
|
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
|
use OCP\AppFramework\OCSController;
|
||||||
|
|
||||||
class V2Response extends BaseResponse {
|
class V2Response extends BaseResponse {
|
||||||
|
|
||||||
|
@ -37,11 +37,11 @@ class V2Response extends BaseResponse {
|
||||||
*/
|
*/
|
||||||
public function getStatus() {
|
public function getStatus() {
|
||||||
$status = parent::getStatus();
|
$status = parent::getStatus();
|
||||||
if ($status === API::RESPOND_UNAUTHORISED) {
|
if ($status === OCSController::RESPOND_UNAUTHORISED) {
|
||||||
return Http::STATUS_UNAUTHORIZED;
|
return Http::STATUS_UNAUTHORIZED;
|
||||||
} elseif ($status === API::RESPOND_NOT_FOUND) {
|
} elseif ($status === OCSController::RESPOND_NOT_FOUND) {
|
||||||
return Http::STATUS_NOT_FOUND;
|
return Http::STATUS_NOT_FOUND;
|
||||||
} elseif ($status === API::RESPOND_SERVER_ERROR || $status === API::RESPOND_UNKNOWN_ERROR) {
|
} elseif ($status === OCSController::RESPOND_SERVER_ERROR || $status === OCSController::RESPOND_UNKNOWN_ERROR) {
|
||||||
return Http::STATUS_INTERNAL_SERVER_ERROR;
|
return Http::STATUS_INTERNAL_SERVER_ERROR;
|
||||||
} elseif ($status < 200 || $status > 600) {
|
} elseif ($status < 200 || $status > 600) {
|
||||||
return Http::STATUS_BAD_REQUEST;
|
return Http::STATUS_BAD_REQUEST;
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace OC\Remote\Api;
|
||||||
use GuzzleHttp\Exception\ClientException;
|
use GuzzleHttp\Exception\ClientException;
|
||||||
use OC\ForbiddenException;
|
use OC\ForbiddenException;
|
||||||
use OC\Remote\User;
|
use OC\Remote\User;
|
||||||
use OCP\API;
|
use OCP\AppFramework\OCSController;
|
||||||
use OCP\Remote\Api\ICapabilitiesApi;
|
use OCP\Remote\Api\ICapabilitiesApi;
|
||||||
use OCP\Remote\Api\IUserApi;
|
use OCP\Remote\Api\IUserApi;
|
||||||
|
|
||||||
|
@ -58,10 +58,10 @@ class OCS extends ApiBase implements ICapabilitiesApi, IUserApi {
|
||||||
if (!isset($response['ocs']) || !isset($response['ocs']['meta'])) {
|
if (!isset($response['ocs']) || !isset($response['ocs']['meta'])) {
|
||||||
throw new \Exception('Invalid ocs response');
|
throw new \Exception('Invalid ocs response');
|
||||||
}
|
}
|
||||||
if ($response['ocs']['meta']['statuscode'] === API::RESPOND_UNAUTHORISED) {
|
if ($response['ocs']['meta']['statuscode'] === OCSController::RESPOND_UNAUTHORISED) {
|
||||||
throw new ForbiddenException();
|
throw new ForbiddenException();
|
||||||
}
|
}
|
||||||
if ($response['ocs']['meta']['statuscode'] === API::RESPOND_NOT_FOUND) {
|
if ($response['ocs']['meta']['statuscode'] === OCSController::RESPOND_NOT_FOUND) {
|
||||||
throw new NotFoundException();
|
throw new NotFoundException();
|
||||||
}
|
}
|
||||||
if ($response['ocs']['meta']['status'] !== 'ok') {
|
if ($response['ocs']['meta']['status'] !== 'ok') {
|
||||||
|
|
|
@ -48,7 +48,7 @@ class OC_API {
|
||||||
$request = \OC::$server->getRequest();
|
$request = \OC::$server->getRequest();
|
||||||
|
|
||||||
// Send 401 headers if unauthorised
|
// Send 401 headers if unauthorised
|
||||||
if ($result->getStatusCode() === API::RESPOND_UNAUTHORISED) {
|
if ($result->getStatusCode() === \OCP\AppFramework\OCSController::RESPOND_UNAUTHORISED) {
|
||||||
// If request comes from JS return dummy auth request
|
// If request comes from JS return dummy auth request
|
||||||
if ($request->getHeader('X-Requested-With') === 'XMLHttpRequest') {
|
if ($request->getHeader('X-Requested-With') === 'XMLHttpRequest') {
|
||||||
header('WWW-Authenticate: DummyBasic realm="Authorisation Required"');
|
header('WWW-Authenticate: DummyBasic realm="Authorisation Required"');
|
||||||
|
@ -143,13 +143,13 @@ class OC_API {
|
||||||
*/
|
*/
|
||||||
public static function mapStatusCodes($sc) {
|
public static function mapStatusCodes($sc) {
|
||||||
switch ($sc) {
|
switch ($sc) {
|
||||||
case API::RESPOND_NOT_FOUND:
|
case \OCP\AppFramework\OCSController::RESPOND_NOT_FOUND:
|
||||||
return Http::STATUS_NOT_FOUND;
|
return Http::STATUS_NOT_FOUND;
|
||||||
case API::RESPOND_SERVER_ERROR:
|
case \OCP\AppFramework\OCSController::RESPOND_SERVER_ERROR:
|
||||||
return Http::STATUS_INTERNAL_SERVER_ERROR;
|
return Http::STATUS_INTERNAL_SERVER_ERROR;
|
||||||
case API::RESPOND_UNKNOWN_ERROR:
|
case \OCP\AppFramework\OCSController::RESPOND_UNKNOWN_ERROR:
|
||||||
return Http::STATUS_INTERNAL_SERVER_ERROR;
|
return Http::STATUS_INTERNAL_SERVER_ERROR;
|
||||||
case API::RESPOND_UNAUTHORISED:
|
case \OCP\AppFramework\OCSController::RESPOND_UNAUTHORISED:
|
||||||
// already handled for v1
|
// already handled for v1
|
||||||
return null;
|
return null;
|
||||||
case 100:
|
case 100:
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
||||||
*
|
|
||||||
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
|
||||||
* @author Joas Schilling <coding@schilljs.com>
|
|
||||||
* @author Morris Jobke <hey@morrisjobke.de>
|
|
||||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
|
||||||
* @author Tom Needham <tom@owncloud.com>
|
|
||||||
*
|
|
||||||
* @license AGPL-3.0
|
|
||||||
*
|
|
||||||
* This code is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License, version 3,
|
|
||||||
* as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Public interface of ownCloud for apps to use.
|
|
||||||
* API Class
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
// use OCP namespace for all classes that are considered public.
|
|
||||||
// This means that they should be used by apps instead of the internal ownCloud classes
|
|
||||||
|
|
||||||
namespace OCP;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class provides functions to manage apps in ownCloud
|
|
||||||
* @since 5.0.0
|
|
||||||
* @deprecated 9.1.0 Use the AppFramework
|
|
||||||
*/
|
|
||||||
class API {
|
|
||||||
/**
|
|
||||||
* API Response Codes
|
|
||||||
* @since 8.1.0
|
|
||||||
*/
|
|
||||||
public const RESPOND_UNAUTHORISED = 997;
|
|
||||||
public const RESPOND_SERVER_ERROR = 996;
|
|
||||||
public const RESPOND_NOT_FOUND = 998;
|
|
||||||
public const RESPOND_UNKNOWN_ERROR = 999;
|
|
||||||
}
|
|
|
@ -42,6 +42,10 @@ use OCP\IRequest;
|
||||||
* @since 8.1.0
|
* @since 8.1.0
|
||||||
*/
|
*/
|
||||||
abstract class OCSController extends ApiController {
|
abstract class OCSController extends ApiController {
|
||||||
|
public const RESPOND_UNAUTHORISED = 997;
|
||||||
|
public const RESPOND_SERVER_ERROR = 996;
|
||||||
|
public const RESPOND_NOT_FOUND = 998;
|
||||||
|
public const RESPOND_UNKNOWN_ERROR = 999;
|
||||||
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $ocsVersion;
|
private $ocsVersion;
|
||||||
|
|
|
@ -67,14 +67,14 @@ try {
|
||||||
$format = \OC::$server->getRequest()->getParam('format', 'xml');
|
$format = \OC::$server->getRequest()->getParam('format', 'xml');
|
||||||
$txt = 'Invalid query, please check the syntax. API specifications are here:'
|
$txt = 'Invalid query, please check the syntax. API specifications are here:'
|
||||||
.' http://www.freedesktop.org/wiki/Specifications/open-collaboration-services.'."\n";
|
.' http://www.freedesktop.org/wiki/Specifications/open-collaboration-services.'."\n";
|
||||||
OC_API::respond(new \OC\OCS\Result(null, \OCP\API::RESPOND_NOT_FOUND, $txt), $format);
|
OC_API::respond(new \OC\OCS\Result(null, \OCP\AppFramework\OCSController::RESPOND_NOT_FOUND, $txt), $format);
|
||||||
} catch (MethodNotAllowedException $e) {
|
} catch (MethodNotAllowedException $e) {
|
||||||
OC_API::setContentType();
|
OC_API::setContentType();
|
||||||
http_response_code(405);
|
http_response_code(405);
|
||||||
} catch (\OC\OCS\Exception $ex) {
|
} catch (\OC\OCS\Exception $ex) {
|
||||||
OC_API::respond($ex->getResult(), OC_API::requestedFormat());
|
OC_API::respond($ex->getResult(), OC_API::requestedFormat());
|
||||||
} catch (\OC\User\LoginException $e) {
|
} catch (\OC\User\LoginException $e) {
|
||||||
OC_API::respond(new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED, 'Unauthorised'));
|
OC_API::respond(new \OC\OCS\Result(null, \OCP\AppFramework\OCSController::RESPOND_UNAUTHORISED, 'Unauthorised'));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
\OC::$server->getLogger()->logException($e);
|
\OC::$server->getLogger()->logException($e);
|
||||||
OC_API::setContentType();
|
OC_API::setContentType();
|
||||||
|
@ -82,5 +82,5 @@ try {
|
||||||
$format = \OC::$server->getRequest()->getParam('format', 'xml');
|
$format = \OC::$server->getRequest()->getParam('format', 'xml');
|
||||||
$txt = 'Invalid query, please check the syntax. API specifications are here:'
|
$txt = 'Invalid query, please check the syntax. API specifications are here:'
|
||||||
.' http://www.freedesktop.org/wiki/Specifications/open-collaboration-services.'."\n";
|
.' http://www.freedesktop.org/wiki/Specifications/open-collaboration-services.'."\n";
|
||||||
OC_API::respond(new \OC\OCS\Result(null, \OCP\API::RESPOND_NOT_FOUND, $txt), $format);
|
OC_API::respond(new \OC\OCS\Result(null, \OCP\AppFramework\OCSController::RESPOND_NOT_FOUND, $txt), $format);
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ class OCSMiddlewareTest extends \Test\TestCase {
|
||||||
$this->assertSame($message, $this->invokePrivate($result, 'statusMessage'));
|
$this->assertSame($message, $this->invokePrivate($result, 'statusMessage'));
|
||||||
|
|
||||||
if ($exception->getCode() === 0) {
|
if ($exception->getCode() === 0) {
|
||||||
$this->assertSame(\OCP\API::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus());
|
$this->assertSame(\OCP\AppFramework\OCSController::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus());
|
||||||
} else {
|
} else {
|
||||||
$this->assertSame($code, $result->getOCSStatus());
|
$this->assertSame($code, $result->getOCSStatus());
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ class OCSMiddlewareTest extends \Test\TestCase {
|
||||||
|
|
||||||
$this->assertSame($message, $this->invokePrivate($result, 'statusMessage'));
|
$this->assertSame($message, $this->invokePrivate($result, 'statusMessage'));
|
||||||
if ($exception->getCode() === 0) {
|
if ($exception->getCode() === 0) {
|
||||||
$this->assertSame(\OCP\API::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus());
|
$this->assertSame(\OCP\AppFramework\OCSController::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus());
|
||||||
} else {
|
} else {
|
||||||
$this->assertSame($code, $result->getOCSStatus());
|
$this->assertSame($code, $result->getOCSStatus());
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ class OCSMiddlewareTest extends \Test\TestCase {
|
||||||
|
|
||||||
$this->assertSame($message, $this->invokePrivate($result, 'statusMessage'));
|
$this->assertSame($message, $this->invokePrivate($result, 'statusMessage'));
|
||||||
if ($exception->getCode() === 0) {
|
if ($exception->getCode() === 0) {
|
||||||
$this->assertSame(\OCP\API::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus());
|
$this->assertSame(\OCP\AppFramework\OCSController::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus());
|
||||||
} else {
|
} else {
|
||||||
$this->assertSame($code, $result->getOCSStatus());
|
$this->assertSame($code, $result->getOCSStatus());
|
||||||
}
|
}
|
||||||
|
@ -233,7 +233,7 @@ class OCSMiddlewareTest extends \Test\TestCase {
|
||||||
} else {
|
} else {
|
||||||
$this->assertInstanceOf(BaseResponse::class, $newResponse);
|
$this->assertInstanceOf(BaseResponse::class, $newResponse);
|
||||||
$this->assertSame($response->getData()['message'], $this->invokePrivate($newResponse, 'statusMessage'));
|
$this->assertSame($response->getData()['message'], $this->invokePrivate($newResponse, 'statusMessage'));
|
||||||
$this->assertSame(\OCP\API::RESPOND_UNAUTHORISED, $newResponse->getOCSStatus());
|
$this->assertSame(\OCP\AppFramework\OCSController::RESPOND_UNAUTHORISED, $newResponse->getOCSStatus());
|
||||||
$this->assertSame(Http::STATUS_UNAUTHORIZED, $newResponse->getStatus());
|
$this->assertSame(Http::STATUS_UNAUTHORIZED, $newResponse->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue