Deprecate the OC_API constants in favor of the OCP ones
This commit is contained in:
parent
4e58f4892a
commit
6ce1abfa5c
|
@ -34,17 +34,33 @@ class OC_API {
|
||||||
/**
|
/**
|
||||||
* API authentication levels
|
* API authentication levels
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/** @deprecated Use \OCP\API::GUEST_AUTH instead */
|
||||||
const GUEST_AUTH = 0;
|
const GUEST_AUTH = 0;
|
||||||
|
|
||||||
|
/** @deprecated Use \OCP\API::USER_AUTH instead */
|
||||||
const USER_AUTH = 1;
|
const USER_AUTH = 1;
|
||||||
|
|
||||||
|
/** @deprecated Use \OCP\API::SUBADMIN_AUTH instead */
|
||||||
const SUBADMIN_AUTH = 2;
|
const SUBADMIN_AUTH = 2;
|
||||||
|
|
||||||
|
/** @deprecated Use \OCP\API::ADMIN_AUTH instead */
|
||||||
const ADMIN_AUTH = 3;
|
const ADMIN_AUTH = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API Response Codes
|
* API Response Codes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/** @deprecated Use \OCP\API::RESPOND_UNAUTHORISED instead */
|
||||||
const RESPOND_UNAUTHORISED = 997;
|
const RESPOND_UNAUTHORISED = 997;
|
||||||
|
|
||||||
|
/** @deprecated Use \OCP\API::RESPOND_SERVER_ERROR instead */
|
||||||
const RESPOND_SERVER_ERROR = 996;
|
const RESPOND_SERVER_ERROR = 996;
|
||||||
|
|
||||||
|
/** @deprecated Use \OCP\API::RESPOND_NOT_FOUND instead */
|
||||||
const RESPOND_NOT_FOUND = 998;
|
const RESPOND_NOT_FOUND = 998;
|
||||||
|
|
||||||
|
/** @deprecated Use \OCP\API::RESPOND_UNKNOWN_ERROR instead */
|
||||||
const RESPOND_UNKNOWN_ERROR = 999;
|
const RESPOND_UNKNOWN_ERROR = 999;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,7 +81,7 @@ class OC_API {
|
||||||
* @param array $requirements
|
* @param array $requirements
|
||||||
*/
|
*/
|
||||||
public static function register($method, $url, $action, $app,
|
public static function register($method, $url, $action, $app,
|
||||||
$authLevel = OC_API::USER_AUTH,
|
$authLevel = \OCP\API::USER_AUTH,
|
||||||
$defaults = array(),
|
$defaults = array(),
|
||||||
$requirements = array()) {
|
$requirements = array()) {
|
||||||
$name = strtolower($method).$url;
|
$name = strtolower($method).$url;
|
||||||
|
@ -106,7 +122,7 @@ class OC_API {
|
||||||
if(!self::isAuthorised($action)) {
|
if(!self::isAuthorised($action)) {
|
||||||
$responses[] = array(
|
$responses[] = array(
|
||||||
'app' => $action['app'],
|
'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']),
|
'shipped' => OC_App::isShipped($action['app']),
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
|
@ -114,7 +130,7 @@ class OC_API {
|
||||||
if(!is_callable($action['action'])) {
|
if(!is_callable($action['action'])) {
|
||||||
$responses[] = array(
|
$responses[] = array(
|
||||||
'app' => $action['app'],
|
'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']),
|
'shipped' => OC_App::isShipped($action['app']),
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
|
@ -235,15 +251,15 @@ class OC_API {
|
||||||
private static function isAuthorised($action) {
|
private static function isAuthorised($action) {
|
||||||
$level = $action['authlevel'];
|
$level = $action['authlevel'];
|
||||||
switch($level) {
|
switch($level) {
|
||||||
case OC_API::GUEST_AUTH:
|
case \OCP\API::GUEST_AUTH:
|
||||||
// Anyone can access
|
// Anyone can access
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
case OC_API::USER_AUTH:
|
case \OCP\API::USER_AUTH:
|
||||||
// User required
|
// User required
|
||||||
return self::loginUser();
|
return self::loginUser();
|
||||||
break;
|
break;
|
||||||
case OC_API::SUBADMIN_AUTH:
|
case \OCP\API::SUBADMIN_AUTH:
|
||||||
// Check for subadmin
|
// Check for subadmin
|
||||||
$user = self::loginUser();
|
$user = self::loginUser();
|
||||||
if(!$user) {
|
if(!$user) {
|
||||||
|
@ -258,7 +274,7 @@ class OC_API {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case OC_API::ADMIN_AUTH:
|
case \OCP\API::ADMIN_AUTH:
|
||||||
// Check for admin
|
// Check for admin
|
||||||
$user = self::loginUser();
|
$user = self::loginUser();
|
||||||
if(!$user) {
|
if(!$user) {
|
||||||
|
@ -325,7 +341,7 @@ class OC_API {
|
||||||
*/
|
*/
|
||||||
public static function respond($result, $format='xml') {
|
public static function respond($result, $format='xml') {
|
||||||
// Send 401 headers if unauthorised
|
// 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('WWW-Authenticate: Basic realm="Authorisation Required"');
|
||||||
header('HTTP/1.0 401 Unauthorized');
|
header('HTTP/1.0 401 Unauthorized');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue