Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 4326f12

Browse files
committed
ENH: refs #236. Add folder.children and new client auth methods to web api
1 parent 50329c4 commit 4326f12

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

modules/api/controllers/IndexController.php

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,16 @@ private function _setApiCallbacks($apiMethodPrefix)
271271
$this->helpContent[$apiMethodPrefix.'folder.get'] = $help;
272272
$this->apicallbacks[$apiMethodPrefix.'folder.get'] = array(&$this, 'folderGet');
273273

274+
$help = array();
275+
$help['params'] = array();
276+
$help['params']['token'] = '(Optional) Authentification token';
277+
$help['params']['id'] = 'Id of the folder';
278+
$help['example'] = array();
279+
$help['return'] = 'List of children';
280+
$help['description'] = 'Get all of the immediate children of a folder';
281+
$this->helpContent[$apiMethodPrefix.'folder.children'] = $help;
282+
$this->apicallbacks[$apiMethodPrefix.'folder.children'] = array(&$this, 'folderChildren');
283+
274284
$help = array();
275285
$help['params'] = array();
276286
$help['params']['token'] = '(Optional) Authentification token';
@@ -301,6 +311,7 @@ private function _setApiCallbacks($apiMethodPrefix)
301311
$this->helpContent[$apiMethodPrefix.'folder.tree'] = $help;
302312
$this->apicallbacks[$apiMethodPrefix.'folder.tree'] = array(&$this, 'folderTree');
303313

314+
/** ----- User -------------*/
304315
$help = array();
305316
$help['params'] = array();
306317
$help['params']['token'] = '(Optional) Authentification token';
@@ -310,6 +321,16 @@ private function _setApiCallbacks($apiMethodPrefix)
310321
$this->helpContent[$apiMethodPrefix.'user.folders'] = $help;
311322
$this->apicallbacks[$apiMethodPrefix.'user.folders'] = array(&$this, 'userFolders');
312323

324+
$help = array();
325+
$help['params'] = array();
326+
$help['params']['email'] = 'The user\'s email';
327+
$help['params']['password'] = 'The user\'s password';
328+
$help['example'] = array();
329+
$help['return'] = 'The user\'s default API key';
330+
$help['description'] = 'Gets the user\'s default API key. Only call this the first time a new password is used';
331+
$this->helpContent[$apiMethodPrefix.'user.apikey.default'] = $help;
332+
$this->apicallbacks[$apiMethodPrefix.'user.apikey.default'] = array(&$this, 'userApikeyDefault');
333+
313334
/** ------ ITEM --- */
314335
$help = array();
315336
$help['params'] = array();
@@ -845,6 +866,24 @@ function folderGet($args)
845866
return $folder->toArray();
846867
}
847868

869+
/** Get the immediate children of a folder */
870+
function folderChildren($args)
871+
{
872+
if(!array_key_exists('id', $args))
873+
{
874+
throw new Exception('Parameter id is not defined', MIDAS_INVALID_PARAMETER);
875+
}
876+
877+
$id = $args['id'];
878+
$folder = $this->Folder->load($id);
879+
880+
$userDao = $this->_getUser($args);
881+
$folders = $this->Folder->getChildrenFoldersFiltered($folder, $userDao);
882+
$items = $this->Folder->getItemsFiltered($folder, $userDao);
883+
884+
return array('folders' => $folders, 'items' => $items);
885+
}
886+
848887
/** Create a folder */
849888
function folderCreate($args)
850889
{
@@ -1168,13 +1207,13 @@ function resourceGet($args)
11681207
}
11691208

11701209
/** Returns a path of uuids from the root community to the given node */
1171-
function pathFromRoot ($args)
1210+
function pathFromRoot($args)
11721211
{
11731212
return array_reverse($this->pathToRoot($args));
11741213
}
11751214

11761215
/** Returns a path of uuids from the given node to the root community */
1177-
function pathToRoot ($args)
1216+
function pathToRoot($args)
11781217
{
11791218
if(!array_key_exists('uuid', $args))
11801219
{
@@ -1334,5 +1373,28 @@ function userFolders($args)
13341373
$userRootFolder = $userDao->getFolder();
13351374
return $this->Folder->getChildrenFoldersFiltered($userRootFolder, $userDao, MIDAS_POLICY_READ);
13361375
}
1376+
1377+
/**
1378+
* Returns the user's default API key given their username and password
1379+
*/
1380+
function userApikeyDefault($args)
1381+
{
1382+
if(!$this->_request->isPost())
1383+
{
1384+
throw new Exception('POST method required', MIDAS_HTTP_ERROR);
1385+
}
1386+
if(!array_key_exists('email', $args))
1387+
{
1388+
throw new Exception('Parameter email is not defined', MIDAS_INVALID_PARAMETER);
1389+
}
1390+
if(!array_key_exists('password', $args))
1391+
{
1392+
throw new Exception('Parameter password is not defined', MIDAS_INVALID_PARAMETER);
1393+
}
1394+
1395+
$salt = Zend_Registry::get('configGlobal')->password->prefix;
1396+
$defaultApiKey = $key = md5($args['email'].md5($salt.$args['password']).'Default');
1397+
return array('apikey' => $defaultApiKey);
1398+
}
13371399
} // end class
13381400
?>

0 commit comments

Comments
 (0)