Merge pull request #15717 from owncloud/issue/15716-fixing-ocp-api-namespace-usage

Fixing OCS API namespace usage
remotes/origin/poc-doctrine-migrations
Morris Jobke 10 years ago
commit 9cb260d310
  1. 2
      apps/files/appinfo/routes.php
  2. 2
      apps/files_external/appinfo/routes.php
  3. 15
      apps/files_sharing/appinfo/routes.php
  4. 2
      apps/files_trashbin/appinfo/routes.php
  5. 2
      apps/files_versions/appinfo/routes.php
  6. 42
      apps/provisioning_api/appinfo/routes.php
  7. 2
      apps/provisioning_api/lib/apps.php
  8. 4
      apps/provisioning_api/lib/groups.php
  9. 6
      apps/provisioning_api/lib/users.php
  10. 2
      apps/provisioning_api/tests/appstest.php
  11. 4
      apps/provisioning_api/tests/groupstest.php
  12. 2
      apps/provisioning_api/tests/userstest.php
  13. 36
      lib/private/api.php
  14. 22
      lib/public/api.php
  15. 58
      ocs/routes.php

@ -85,4 +85,4 @@ $this->create('download', 'download{file}')
->actionInclude('files/download.php');
// Register with the capabilities API
\OC_API::register('get', '/cloud/capabilities', array('OCA\Files\Capabilities', 'getCapabilities'), 'files', \OC_API::USER_AUTH);
\OCP\API::register('get', '/cloud/capabilities', array('OCA\Files\Capabilities', 'getCapabilities'), 'files', \OCP\API::USER_AUTH);

@ -61,7 +61,7 @@ $this->create('files_external_google', 'ajax/google.php')
$this->create('files_external_list_applicable', '/applicable')
->actionInclude('files_external/ajax/applicable.php');
\OC_API::register('get',
\OCP\API::register('get',
'/apps/files_external/api/v1/mounts',
array('\OCA\Files\External\Api', 'getUserMounts'),
'files_external');

@ -26,6 +26,7 @@
namespace OCA\Files_Sharing\AppInfo;
use OCA\Files_Sharing\Application;
use OCP\API;
$application = new Application();
$application->registerRoutes($this, [
@ -55,33 +56,33 @@ $this->create('sharing_external_test_remote', '/testremote')
//TODO: SET: mail notification, waiting for PR #4689 to be accepted
\OC_API::register('get',
API::register('get',
'/apps/files_sharing/api/v1/shares',
array('\OCA\Files_Sharing\API\Local', 'getAllShares'),
'files_sharing');
\OC_API::register('post',
API::register('post',
'/apps/files_sharing/api/v1/shares',
array('\OCA\Files_Sharing\API\Local', 'createShare'),
'files_sharing');
\OC_API::register('get',
API::register('get',
'/apps/files_sharing/api/v1/shares/{id}',
array('\OCA\Files_Sharing\API\Local', 'getShare'),
'files_sharing');
\OC_API::register('put',
API::register('put',
'/apps/files_sharing/api/v1/shares/{id}',
array('\OCA\Files_Sharing\API\Local', 'updateShare'),
'files_sharing');
\OC_API::register('delete',
API::register('delete',
'/apps/files_sharing/api/v1/shares/{id}',
array('\OCA\Files_Sharing\API\Local', 'deleteShare'),
'files_sharing');
// Register with the capabilities API
\OC_API::register('get',
API::register('get',
'/cloud/capabilities',
array('OCA\Files_Sharing\Capabilities', 'getCapabilities'),
'files_sharing', \OC_API::USER_AUTH);
'files_sharing', API::USER_AUTH);

@ -34,4 +34,4 @@ $this->create('files_trashbin_ajax_undelete', 'ajax/undelete.php')
// Register with the capabilities API
\OC_API::register('get', '/cloud/capabilities', array('OCA\Files_Trashbin\Capabilities', 'getCapabilities'), 'files_trashbin', \OC_API::USER_AUTH);
\OCP\API::register('get', '/cloud/capabilities', array('OCA\Files_Trashbin\Capabilities', 'getCapabilities'), 'files_trashbin', \OCP\API::USER_AUTH);

@ -38,4 +38,4 @@ $this->create('files_versions_ajax_rollbackVersion', 'ajax/rollbackVersion.php')
->actionInclude('files_versions/ajax/rollbackVersion.php');
// Register with the capabilities API
OC_API::register('get', '/cloud/capabilities', array('OCA\Files_Versions\Capabilities', 'getCapabilities'), 'files_versions', OC_API::USER_AUTH);
\OCP\API::register('get', '/cloud/capabilities', array('OCA\Files_Versions\Capabilities', 'getCapabilities'), 'files_versions', \OCP\API::USER_AUTH);

@ -21,27 +21,29 @@
*/
// Users
OCP\API::register('get', '/cloud/users', array('OCA\Provisioning_API\Users', 'getUsers'), 'provisioning_api', OC_API::ADMIN_AUTH);
OCP\API::register('post', '/cloud/users', array('OCA\Provisioning_API\Users', 'addUser'), 'provisioning_api', OC_API::ADMIN_AUTH);
OCP\API::register('get', '/cloud/users/{userid}', array('OCA\Provisioning_API\Users', 'getUser'), 'provisioning_api', OC_API::USER_AUTH);
OCP\API::register('put', '/cloud/users/{userid}', array('OCA\Provisioning_API\Users', 'editUser'), 'provisioning_api', OC_API::USER_AUTH);
OCP\API::register('delete', '/cloud/users/{userid}', array('OCA\Provisioning_API\Users', 'deleteUser'), 'provisioning_api', OC_API::SUBADMIN_AUTH);
OCP\API::register('get', '/cloud/users/{userid}/groups', array('OCA\Provisioning_API\Users', 'getUsersGroups'), 'provisioning_api', OC_API::USER_AUTH);
OCP\API::register('post', '/cloud/users/{userid}/groups', array('OCA\Provisioning_API\Users', 'addToGroup'), 'provisioning_api', OC_API::SUBADMIN_AUTH);
OCP\API::register('delete', '/cloud/users/{userid}/groups', array('OCA\Provisioning_API\Users', 'removeFromGroup'), 'provisioning_api', OC_API::SUBADMIN_AUTH);
OCP\API::register('post', '/cloud/users/{userid}/subadmins', array('OCA\Provisioning_API\Users', 'addSubAdmin'), 'provisioning_api', OC_API::ADMIN_AUTH);
OCP\API::register('delete', '/cloud/users/{userid}/subadmins', array('OCA\Provisioning_API\Users', 'removeSubAdmin'), 'provisioning_api', OC_API::ADMIN_AUTH);
OCP\API::register('get', '/cloud/users/{userid}/subadmins', array('OCA\Provisioning_API\Users', 'getUserSubAdminGroups'), 'provisioning_api', OC_API::ADMIN_AUTH);
use OCP\API;
API::register('get', '/cloud/users', array('OCA\Provisioning_API\Users', 'getUsers'), 'provisioning_api', API::ADMIN_AUTH);
API::register('post', '/cloud/users', array('OCA\Provisioning_API\Users', 'addUser'), 'provisioning_api', API::ADMIN_AUTH);
API::register('get', '/cloud/users/{userid}', array('OCA\Provisioning_API\Users', 'getUser'), 'provisioning_api', API::USER_AUTH);
API::register('put', '/cloud/users/{userid}', array('OCA\Provisioning_API\Users', 'editUser'), 'provisioning_api', API::USER_AUTH);
API::register('delete', '/cloud/users/{userid}', array('OCA\Provisioning_API\Users', 'deleteUser'), 'provisioning_api', API::SUBADMIN_AUTH);
API::register('get', '/cloud/users/{userid}/groups', array('OCA\Provisioning_API\Users', 'getUsersGroups'), 'provisioning_api', API::USER_AUTH);
API::register('post', '/cloud/users/{userid}/groups', array('OCA\Provisioning_API\Users', 'addToGroup'), 'provisioning_api', API::SUBADMIN_AUTH);
API::register('delete', '/cloud/users/{userid}/groups', array('OCA\Provisioning_API\Users', 'removeFromGroup'), 'provisioning_api', API::SUBADMIN_AUTH);
API::register('post', '/cloud/users/{userid}/subadmins', array('OCA\Provisioning_API\Users', 'addSubAdmin'), 'provisioning_api', API::ADMIN_AUTH);
API::register('delete', '/cloud/users/{userid}/subadmins', array('OCA\Provisioning_API\Users', 'removeSubAdmin'), 'provisioning_api', API::ADMIN_AUTH);
API::register('get', '/cloud/users/{userid}/subadmins', array('OCA\Provisioning_API\Users', 'getUserSubAdminGroups'), 'provisioning_api', API::ADMIN_AUTH);
// Groups
OCP\API::register('get', '/cloud/groups', array('OCA\Provisioning_API\Groups', 'getGroups'), 'provisioning_api', OC_API::SUBADMIN_AUTH);
OCP\API::register('post', '/cloud/groups', array('OCA\Provisioning_API\Groups', 'addGroup'), 'provisioning_api', OC_API::SUBADMIN_AUTH);
OCP\API::register('get', '/cloud/groups/{groupid}', array('OCA\Provisioning_API\Groups', 'getGroup'), 'provisioning_api', OC_API::SUBADMIN_AUTH);
OCP\API::register('delete', '/cloud/groups/{groupid}', array('OCA\Provisioning_API\Groups', 'deleteGroup'), 'provisioning_api', OC_API::ADMIN_AUTH);
OCP\API::register('get', '/cloud/groups/{groupid}/subadmins', array('OCA\Provisioning_API\Groups', 'getSubAdminsOfGroup'), 'provisioning_api', OC_API::ADMIN_AUTH);
API::register('get', '/cloud/groups', array('OCA\Provisioning_API\Groups', 'getGroups'), 'provisioning_api', API::SUBADMIN_AUTH);
API::register('post', '/cloud/groups', array('OCA\Provisioning_API\Groups', 'addGroup'), 'provisioning_api', API::SUBADMIN_AUTH);
API::register('get', '/cloud/groups/{groupid}', array('OCA\Provisioning_API\Groups', 'getGroup'), 'provisioning_api', API::SUBADMIN_AUTH);
API::register('delete', '/cloud/groups/{groupid}', array('OCA\Provisioning_API\Groups', 'deleteGroup'), 'provisioning_api', API::ADMIN_AUTH);
API::register('get', '/cloud/groups/{groupid}/subadmins', array('OCA\Provisioning_API\Groups', 'getSubAdminsOfGroup'), 'provisioning_api', API::ADMIN_AUTH);
// Apps
OCP\API::register('get', '/cloud/apps', array('OCA\Provisioning_API\Apps', 'getApps'), 'provisioning_api', OC_API::ADMIN_AUTH);
OCP\API::register('get', '/cloud/apps/{appid}', array('OCA\Provisioning_API\Apps', 'getAppInfo'), 'provisioning_api', OC_API::ADMIN_AUTH);
OCP\API::register('post', '/cloud/apps/{appid}', array('OCA\Provisioning_API\Apps', 'enable'), 'provisioning_api', OC_API::ADMIN_AUTH);
OCP\API::register('delete', '/cloud/apps/{appid}', array('OCA\Provisioning_API\Apps', 'disable'), 'provisioning_api', OC_API::ADMIN_AUTH);
API::register('get', '/cloud/apps', array('OCA\Provisioning_API\Apps', 'getApps'), 'provisioning_api', API::ADMIN_AUTH);
API::register('get', '/cloud/apps/{appid}', array('OCA\Provisioning_API\Apps', 'getAppInfo'), 'provisioning_api', API::ADMIN_AUTH);
API::register('post', '/cloud/apps/{appid}', array('OCA\Provisioning_API\Apps', 'enable'), 'provisioning_api', API::ADMIN_AUTH);
API::register('delete', '/cloud/apps/{appid}', array('OCA\Provisioning_API\Apps', 'disable'), 'provisioning_api', API::ADMIN_AUTH);

@ -60,7 +60,7 @@ class Apps {
if(!is_null($info)) {
return new OC_OCS_Result(OC_App::getAppInfo($app));
} else {
return new OC_OCS_Result(null, \OC_API::RESPOND_NOT_FOUND, 'The request app was not found');
return new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The request app was not found');
}
}

@ -44,14 +44,14 @@ class Groups{
public static function getGroup($parameters){
// Check the group exists
if(!OC_Group::groupExists($parameters['groupid'])){
return new OC_OCS_Result(null, \OC_API::RESPOND_NOT_FOUND, 'The requested group could not be found');
return new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The requested group could not be found');
}
// Check subadmin has access to this group
if(\OC_User::isAdminUser(\OC_User::getUser())
|| in_array($parameters['groupid'], \OC_SubAdmin::getSubAdminsGroups(\OC_User::getUser()))){
return new OC_OCS_Result(array('users' => OC_Group::usersInGroup($parameters['groupid'])));
} else {
return new OC_OCS_Result(null, \OC_API::RESPOND_UNAUTHORISED, 'User does not have access to specified group');
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED, 'User does not have access to specified group');
}
}

@ -67,7 +67,7 @@ class Users {
if(OC_User::isAdminUser(OC_User::getUser()) || OC_SubAdmin::isUserAccessible(OC_User::getUser(), $userId)) {
// Check they exist
if(!OC_User::userExists($userId)) {
return new OC_OCS_Result(null, \OC_API::RESPOND_NOT_FOUND, 'The requested user could not be found');
return new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The requested user could not be found');
}
// Show all
$return = array(
@ -80,7 +80,7 @@ class Users {
} else {
// Check they are looking up themselves
if(OC_User::getUser() != $userId) {
return new OC_OCS_Result(null, \OC_API::RESPOND_UNAUTHORISED);
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
}
// Return some additional information compared to the core route
$return = array(
@ -226,7 +226,7 @@ class Users {
// Check they're an admin
if(!OC_Group::inGroup(OC_User::getUser(), 'admin')){
// This user doesn't have rights to add a user to this group
return new OC_OCS_Result(null, \OC_API::RESPOND_UNAUTHORISED);
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
}
// Check if the group exists
if(!OC_Group::groupExists($group)){

@ -36,7 +36,7 @@ class AppsTest extends TestCase {
$result = \OCA\provisioning_API\Apps::getAppInfo(array('appid' => 'not_provisioning_api'));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
$this->assertEquals(\OC_API::RESPOND_NOT_FOUND, $result->getStatusCode());
$this->assertEquals(\OCP\API::RESPOND_NOT_FOUND, $result->getStatusCode());
}

@ -39,7 +39,7 @@ class GroupsTest extends TestCase {
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
$this->assertEquals(\OC_API::RESPOND_UNAUTHORISED, $result->getStatusCode());
$this->assertEquals(\OCP\API::RESPOND_UNAUTHORISED, $result->getStatusCode());
}
@ -92,7 +92,7 @@ class GroupsTest extends TestCase {
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
$this->assertEquals(\OC_API::RESPOND_UNAUTHORISED, $result->getStatusCode());
$this->assertEquals(\OCP\API::RESPOND_UNAUTHORISED, $result->getStatusCode());
}

@ -101,7 +101,7 @@ class UsersTest extends TestCase {
$result = \OCA\provisioning_API\Users::getUser($params);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
$this->assertEquals(\OC_API::RESPOND_NOT_FOUND, $result->getStatusCode());
$this->assertEquals(\OCP\API::RESPOND_NOT_FOUND, $result->getStatusCode());
}

@ -34,17 +34,33 @@ class OC_API {
/**
* API authentication levels
*/
/** @deprecated Use \OCP\API::GUEST_AUTH instead */
const GUEST_AUTH = 0;
/** @deprecated Use \OCP\API::USER_AUTH instead */
const USER_AUTH = 1;
/** @deprecated Use \OCP\API::SUBADMIN_AUTH instead */
const SUBADMIN_AUTH = 2;
/** @deprecated Use \OCP\API::ADMIN_AUTH instead */
const ADMIN_AUTH = 3;
/**
* API Response Codes
*/
/** @deprecated Use \OCP\API::RESPOND_UNAUTHORISED instead */
const RESPOND_UNAUTHORISED = 997;
/** @deprecated Use \OCP\API::RESPOND_SERVER_ERROR instead */
const RESPOND_SERVER_ERROR = 996;
/** @deprecated Use \OCP\API::RESPOND_NOT_FOUND instead */
const RESPOND_NOT_FOUND = 998;
/** @deprecated Use \OCP\API::RESPOND_UNKNOWN_ERROR instead */
const RESPOND_UNKNOWN_ERROR = 999;
/**
@ -65,7 +81,7 @@ class OC_API {
* @param array $requirements
*/
public static function register($method, $url, $action, $app,
$authLevel = OC_API::USER_AUTH,
$authLevel = \OCP\API::USER_AUTH,
$defaults = array(),
$requirements = array()) {
$name = strtolower($method).$url;
@ -106,7 +122,7 @@ class OC_API {
if(!self::isAuthorised($action)) {
$responses[] = array(
'app' => $action['app'],
'response' => new OC_OCS_Result(null, OC_API::RESPOND_UNAUTHORISED, 'Unauthorised'),
'response' => new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED, 'Unauthorised'),
'shipped' => OC_App::isShipped($action['app']),
);
continue;
@ -114,7 +130,7 @@ class OC_API {
if(!is_callable($action['action'])) {
$responses[] = array(
'app' => $action['app'],
'response' => new OC_OCS_Result(null, OC_API::RESPOND_NOT_FOUND, 'Api method not found'),
'response' => new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, 'Api method not found'),
'shipped' => OC_App::isShipped($action['app']),
);
continue;
@ -172,7 +188,7 @@ class OC_API {
// Which shipped response do we use if they all failed?
// They may have failed for different reasons (different status codes)
// Which response code should we return?
// Maybe any that are not OC_API::RESPOND_SERVER_ERROR
// Maybe any that are not \OCP\API::RESPOND_SERVER_ERROR
// Merge failed responses if more than one
$data = array();
foreach($shipped['failed'] as $failure) {
@ -235,15 +251,15 @@ class OC_API {
private static function isAuthorised($action) {
$level = $action['authlevel'];
switch($level) {
case OC_API::GUEST_AUTH:
case \OCP\API::GUEST_AUTH:
// Anyone can access
return true;
break;
case OC_API::USER_AUTH:
case \OCP\API::USER_AUTH:
// User required
return self::loginUser();
break;
case OC_API::SUBADMIN_AUTH:
case \OCP\API::SUBADMIN_AUTH:
// Check for subadmin
$user = self::loginUser();
if(!$user) {
@ -258,7 +274,7 @@ class OC_API {
}
}
break;
case OC_API::ADMIN_AUTH:
case \OCP\API::ADMIN_AUTH:
// Check for admin
$user = self::loginUser();
if(!$user) {
@ -325,7 +341,7 @@ class OC_API {
*/
public static function respond($result, $format='xml') {
// Send 401 headers if unauthorised
if($result->getStatusCode() === self::RESPOND_UNAUTHORISED) {
if($result->getStatusCode() === \OCP\API::RESPOND_UNAUTHORISED) {
header('WWW-Authenticate: Basic realm="Authorisation Required"');
header('HTTP/1.0 401 Unauthorized');
}
@ -384,7 +400,7 @@ class OC_API {
* Based on the requested format the response content type is set
*/
public static function setContentType() {
$format = \OC_API::requestedFormat();
$format = self::requestedFormat();
if ($format === 'xml') {
header('Content-type: text/xml; charset=UTF-8');
return;

@ -37,18 +37,36 @@ namespace OCP;
*/
class API {
/**
* API authentication levels
* @since 8.1.0
*/
const GUEST_AUTH = 0;
const USER_AUTH = 1;
const SUBADMIN_AUTH = 2;
const ADMIN_AUTH = 3;
/**
* API Response Codes
* @since 8.1.0
*/
const RESPOND_UNAUTHORISED = 997;
const RESPOND_SERVER_ERROR = 996;
const RESPOND_NOT_FOUND = 998;
const RESPOND_UNKNOWN_ERROR = 999;
/**
* registers an api call
* @param string $method the http method
* @param string $url the url to match
* @param callable $action the function to run
* @param string $app the id of the app registering the call
* @param int $authLevel the level of authentication required for the call (See OC_API constants)
* @param int $authLevel the level of authentication required for the call (See `self::*_AUTH` constants)
* @param array $defaults
* @param array $requirements
* @since 5.0.0
*/
public static function register($method, $url, $action, $app, $authLevel = OC_API::USER_AUTH,
public static function register($method, $url, $action, $app, $authLevel = self::USER_AUTH,
$defaults = array(), $requirements = array()){
\OC_API::register($method, $url, $action, $app, $authLevel, $defaults, $requirements);
}

@ -23,109 +23,111 @@
*
*/
use OCP\API;
// Config
OC_API::register(
API::register(
'get',
'/config',
array('OC_OCS_Config', 'apiConfig'),
'core',
OC_API::GUEST_AUTH
API::GUEST_AUTH
);
// Person
OC_API::register(
API::register(
'post',
'/person/check',
array('OC_OCS_Person', 'check'),
'core',
OC_API::GUEST_AUTH
API::GUEST_AUTH
);
// Privatedata
OC_API::register(
API::register(
'get',
'/privatedata/getattribute',
array('OC_OCS_Privatedata', 'get'),
'core',
OC_API::USER_AUTH,
API::USER_AUTH,
array('app' => '', 'key' => '')
);
OC_API::register(
API::register(
'get',
'/privatedata/getattribute/{app}',
array('OC_OCS_Privatedata', 'get'),
'core',
OC_API::USER_AUTH,
API::USER_AUTH,
array('key' => '')
);
OC_API::register(
API::register(
'get',
'/privatedata/getattribute/{app}/{key}',
array('OC_OCS_Privatedata', 'get'),
'core',
OC_API::USER_AUTH
API::USER_AUTH
);
OC_API::register(
API::register(
'post',
'/privatedata/setattribute/{app}/{key}',
array('OC_OCS_Privatedata', 'set'),
'core',
OC_API::USER_AUTH
API::USER_AUTH
);
OC_API::register(
API::register(
'post',
'/privatedata/deleteattribute/{app}/{key}',
array('OC_OCS_Privatedata', 'delete'),
'core',
OC_API::USER_AUTH
API::USER_AUTH
);
// cloud
OC_API::register(
API::register(
'get',
'/cloud/capabilities',
array('OC_OCS_Cloud', 'getCapabilities'),
'core',
OC_API::USER_AUTH
API::USER_AUTH
);
OC_API::register(
API::register(
'get',
'/cloud/users/{userid}',
array('OC_OCS_Cloud', 'getUser'),
'core',
OC_API::USER_AUTH
API::USER_AUTH
);
OC_API::register(
API::register(
'get',
'/cloud/user',
array('OC_OCS_Cloud', 'getCurrentUser'),
'core',
OC_API::USER_AUTH
API::USER_AUTH
);
// Server-to-Server Sharing
$s2s = new \OCA\Files_Sharing\API\Server2Server();
OC_API::register('post',
API::register('post',
'/cloud/shares',
array($s2s, 'createShare'),
'files_sharing',
OC_API::GUEST_AUTH
API::GUEST_AUTH
);
OC_API::register('post',
API::register('post',
'/cloud/shares/{id}/accept',
array($s2s, 'acceptShare'),
'files_sharing',
OC_API::GUEST_AUTH
API::GUEST_AUTH
);
OC_API::register('post',
API::register('post',
'/cloud/shares/{id}/decline',
array($s2s, 'declineShare'),
'files_sharing',
OC_API::GUEST_AUTH
API::GUEST_AUTH
);
OC_API::register('post',
API::register('post',
'/cloud/shares/{id}/unshare',
array($s2s, 'unshare'),
'files_sharing',
OC_API::GUEST_AUTH
API::GUEST_AUTH
);

Loading…
Cancel
Save