Skip to content

Commit bd7dd63

Browse files
committed
endpoints to fetch item's children
For /users/i:objectUserID/items/:objectKey/children and /groups/i:objectGroupID/items/:objectKey/children. Only allows get requests. Fixes: #113
1 parent 2cf66c3 commit bd7dd63

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

controllers/ApiController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class ApiController extends Controller {
5555
protected $objectKey;
5656
protected $objectName;
5757
protected $subset;
58+
protected $getOnly;
5859
protected $singleObject;
5960
protected $publications = false;
6061
protected $legacyPublications = false;
@@ -446,6 +447,7 @@ public function init($extra) {
446447

447448
$this->scopeObject = !empty($extra['scopeObject']) ? $extra['scopeObject'] : $this->scopeObject;
448449
$this->subset = !empty($extra['subset']) ? $extra['subset'] : $this->subset;
450+
$this->getOnly = !empty($extra['getOnly']) ? $extra['getOnly'] : $this->getOnly;
449451

450452
$this->fileMode = !empty($extra['file'])
451453
? (!empty($_GET['info']) ? 'info' : 'download')

controllers/ItemsController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,9 @@ public function items() {
425425
);
426426
}
427427
else if ($this->subset == 'children') {
428+
if ($this->getOnly) {
429+
$this->allowMethods(array('GET'));
430+
}
428431
$item = Zotero_Items::getByLibraryAndKey($this->objectLibraryID, $this->objectKey);
429432
if (!$item) {
430433
$this->e404("Item not found");

include/config/routes.inc.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
$router->map('/groups/i:objectGroupID/items/:objectKey/file', array('controller' => 'Items', 'extra' => array('allowHTTP' => true, 'file' => true)));
3535
$router->map('/groups/i:objectGroupID/items/:objectKey/file/view', array('controller' => 'Items', 'extra' => array('allowHTTP' => true, 'file' => true, 'view' => true)));
3636
$router->map('/groups/i:objectGroupID/items/:objectKey/file/view/url', ['controller' => 'Items', 'extra' => ['file' => true, 'viewurl' => true]]);
37+
$router->map('/users/i:objectUserID/items/:objectKey/children', ['controller' => 'Items', 'extra' => ['subset' => 'children', 'getOnly' => true]]);
38+
$router->map('/groups/i:objectGroupID/items/:objectKey/children', ['controller' => 'Items', 'extra' => ['subset' => 'children', 'getOnly' => true]]);
3739

3840
// Full-text content
3941
$router->map('/users/i:objectUserID/items/:objectKey/fulltext', array('controller' => 'FullText', 'action' => 'itemContent'));

0 commit comments

Comments
 (0)