API: remove OAuth auth check, respond in ocs formatted xml/json

This commit is contained in:
Tom Needham 2012-09-04 13:50:56 +00:00
parent 37bb16becb
commit 4224eb8831
1 changed files with 25 additions and 11 deletions

View File

@ -74,15 +74,15 @@ class OC_API {
foreach(self::$actions[$name] as $action){ foreach(self::$actions[$name] as $action){
$app = $action['app']; $app = $action['app'];
// Check the consumer has permission to call this method. // Check the consumer has permission to call this method.
if(OC_OAuth_Server::isAuthorised('app_'.$app)){ //if(OC_OAuth_Server::isAuthorised('app_'.$app)){
if(is_callable($action['action'])){ if(is_callable($action['action'])){
$responses[] = array('app' => $app, 'response' => call_user_func($action['action'], $parameters)); $responses[] = array('app' => $app, 'response' => call_user_func($action['action'], $parameters));
} else { } else {
$responses[] = array('app' => $app, 'response' => 501); $responses[] = array('app' => $app, 'response' => 501);
} }
} else { //} else {
$responses[] = array('app' => $app, 'response' => 401); // $responses[] = array('app' => $app, 'response' => 401);
} //}
} }
// Merge the responses // Merge the responses
@ -103,25 +103,39 @@ class OC_API {
* @return array the final merged response * @return array the final merged response
*/ */
private static function mergeResponses($responses){ private static function mergeResponses($responses){
$finalresponse = array(); $finalresponse = array(
'meta' => array(
'statuscode' => '',
),
'data' => array(),
);
$numresponses = count($responses); $numresponses = count($responses);
foreach($responses as $response){ foreach($responses as $response){
if(is_int($response['response']) && empty($finalresponse)){ if(is_int($response['response']) && empty($finalresponse['meta']['statuscode'])){
$finalresponse = $response['response']; $finalresponse['meta']['statuscode'] = $response['response'];
continue; continue;
} }
if(is_array($response['response'])){ if(is_array($response['response'])){
// Shipped apps win // Shipped apps win
if(OC_App::isShipped($response['app'])){ if(OC_App::isShipped($response['app'])){
$finalresponse = array_merge_recursive($finalresponse, $response['response']); $finalresponse['data'] = array_merge_recursive($finalresponse['data'], $response['response']);
} else { } else {
$finalresponse = array_merge_recursive($response['response'], $finalresponse); $finalresponse['data'] = array_merge_recursive($response['response'], $finalresponse['data']);
} }
$finalresponse['meta']['statuscode'] = 100;
} }
} }
//Some tidying up
return $finalresponse; if($finalresponse['meta']['statuscode']=='100'){
$finalresponse['meta']['status'] = 'ok';
} else {
$finalresponse['meta']['status'] = 'failure';
}
if(empty($finalresponse['data'])){
unset($finalresponse['data']);
}
return array('ocs' => $finalresponse);
} }
/** /**