Skip to content

Commit

Permalink
Merge pull request #451 from jjrom/develop
Browse files Browse the repository at this point in the history
Correct issue #429
  • Loading branch information
jjrom authored Oct 14, 2024
2 parents f0b5333 + aa82819 commit b6335f8
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/resto/core/RestoConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RestoConstants
// [IMPORTANT] Starting resto 7.x, default routes are defined in RestoRouter class

// resto version
const VERSION = '9.0.0-RC15';
const VERSION = '9.0.0-RC16';

/* ============================================================
* NEVER EVER TOUCH THESE VALUES
Expand Down
3 changes: 0 additions & 3 deletions app/resto/core/api/STACAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -1495,9 +1495,6 @@ private function getParentAndChilds($catalogId, $params)
if ( isset($parentAndChilds['parent']['title']) ) {
$element['title'] = $parentAndChilds['parent']['title'];
}
if ( isset($catalogs[$i]['rtype']) ) {
$element['resto:type'] = $catalogs[$i]['rtype'];
}
$parentAndChilds['childs'][] = $element;
}

Expand Down
33 changes: 24 additions & 9 deletions app/resto/core/dbfunctions/CatalogsFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ private function insertIntoCatalogFeature($featureId, $path, $catalogId, $collec
* @return array
*/
private function getCleanLinks($catalog, $userid, $baseUrl) {

$output = array(
'links' => array(),
'updateCatalogs' => array(),
Expand All @@ -715,9 +715,9 @@ private function getCleanLinks($catalog, $userid, $baseUrl) {
if ( in_array($link['rel'], array('child', 'item', 'items')) ) {

if ( !isset($link['href']) ) {
return RestoLogUtil::httpError(400, 'One link child has an empty href');
return RestoLogUtil::httpError(400, 'One link has an empty href');
}

/*
* [IMPORTANT] Only put EXTERNAL item/items to links array. Local one are processed later on
*/
Expand Down Expand Up @@ -748,12 +748,27 @@ private function getCleanLinks($catalog, $userid, $baseUrl) {

}

/*
* Store local collection within links
*/
if ( $link['rel'] === 'child' && str_starts_with($link['href'], $baseUrl . RestoRouter::ROUTE_TO_COLLECTIONS )) {
$output['links'][] = $link;
continue;

if ( $link['rel'] === 'child') {

/*
* Avoid cycling (i.e. catalog self referencing one of its parent)
*/
if (str_starts_with($link['href'], $baseUrl . RestoRouter::ROUTE_TO_CATALOGS )) {
$exploded = explode('/', substr($link['href'], strlen($baseUrl . RestoRouter::ROUTE_TO_CATALOGS) + 1));
if ( count($exploded) <= count(explode('/', $catalog['id'])) ) {
return RestoLogUtil::httpError(400, 'Child ' . $link['href'] . ' is invalid because it references a parent resource');
}
}

/*
* Store local collection within links
*/
if (str_starts_with($link['href'], $baseUrl . RestoRouter::ROUTE_TO_COLLECTIONS )) {
$output['links'][] = $link;
continue;
}

}

$exploded = explode($baseUrl . RestoRouter::ROUTE_TO_CATALOGS . '/', $link['href']);
Expand Down
6 changes: 6 additions & 0 deletions docs/COLLECTIONS_AND_CATALOGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ Then get the feature :
# The catalog dummyCatalogChild1 is posted under /catalogs/dummyCatalog
curl -X POST -d@examples/catalogs/dummyCatalogChild1.json "http://admin:admin@localhost:5252/catalogs/dummyCatalog"

## Create a catalog under an existing catalog that cycle on itself

# The catalog dummyCatalogCycling is posted under /catalogs/dummyCatalogChild1 but reference one of this
# parent as a child which is forbiden
curl -X POST -d@examples/catalogs/dummyCatalogCycling.json "http://admin:admin@localhost:5252/catalogs/dummyCatalog/dummyCatalogChild1"

### Create a catalog with item

# The catalog dummyCatalogWithItem is posted under /catalogs/dummyCatalog/dummyCatalogChild1
Expand Down
13 changes: 13 additions & 0 deletions examples/catalogs/dummyCatalogCycling.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"id": "dummyCatalogCycling",
"title": "Dummy Catalog cycling",
"type": "Catalog",
"description":"There is nothing to say on this catalog",
"stac_version":"1.0.0",
"links":[
{
"rel":"child",
"href":"http://127.0.0.1:5252/catalogs/dummyCatalog/dummyCatalogChild1"
}
]
}

0 comments on commit b6335f8

Please sign in to comment.