Skip to content

Commit

Permalink
Correct issue #403:
Browse files Browse the repository at this point in the history
* [Issue] POST /catalogs should returns HTTP 409 if catalog already exists
* [Issue] DELETE /collections/items/{itemId} should returns 404 if itemId does not exist
* [Request] Item properties does not contain the "owner" property
  • Loading branch information
jjrom committed May 13, 2024
1 parent eff1d52 commit 8773bfc
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/resto/core/RestoCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@
* @OA\Property(
* property="owner",
* type="string",
* description="Collection owner (i.e. user identifier)"
* description="Collection owner (i.e. resto user identifier as bigint)"
* )
* )
* ),
Expand Down
2 changes: 1 addition & 1 deletion app/resto/core/RestoFeature.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
* @OA\Property(
* property="owner",
* type="string",
* description="Owner of the feature i.e. user that created it"
* description="Owner of the feature (i.e. resto user identifier as bigint)"
* ),
* @OA\Property(
* property="status",
Expand Down
2 changes: 1 addition & 1 deletion app/resto/core/RestoModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ public function remap($featureArray, $collection)
$discardedProperties = array(
'id',
'visibility',
'owner',
//'owner',
'sort_idx',
'_keywords',
'resto:internal'
Expand Down
2 changes: 1 addition & 1 deletion app/resto/core/addons/STAC.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ public function getQueryables($params)
* name="owner",
* in="query",
* style="form",
* description="Limit search to owner's features",
* description="Limit search to owner's features (i.e. resto user identifier as bigint)",
* required=false,
* @OA\Schema(
* type="integer"
Expand Down
31 changes: 30 additions & 1 deletion app/resto/core/addons/STACCatalog.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,26 @@ public function removeCatalog($params)

}

/**
* Check if catalog exists
*
* @param string $catalogId
* @return boolean
* @throws Exception
*/
private function catalogExists($catalogId, $parentId, $collectionId)
{

// Facet primary key is (is, pid, collection)
$results = $this->dbDriver->fetch($this->dbDriver->pQuery('SELECT id FROM ' . $this->dbDriver->targetSchema . '.facet WHERE id=$1 AND pid=$2 AND collection=$3', array(
$catalogId,
$parentId,
$collectionId
)));

return !empty($results);
}

/**
*
* Store catalog as facet
Expand Down Expand Up @@ -348,12 +368,21 @@ private function storeCatalogAsFacet($catalog, $parentId)
$catalog['id'] = substr($catalog['id'], strlen($this->prefix));
}

$parentId = isset($parentId) ? (str_starts_with($parentId, $this->prefix) ? $parentId : $this->prefix . $parentId) : null;

/*
* Catalog already exist
*/
if ( $this->catalogExists($this->prefix . $catalog['id'], $parentId, '*') ) {
RestoLogUtil::httpError(409, 'Catalog ' . $catalog['id'] . ' already exist');
}

try {
(new FacetsFunctions($this->context->dbDriver))->storeFacets(array(
array(
'id' => $this->prefix . $catalog['id'],
// Prefix parentId with $prefix if needed
'parentId' => isset($parentId) ? (str_starts_with($parentId, $this->prefix) ? $parentId : $this->prefix . $parentId) : null,
'parentId' => $parentId,
'value' => $catalog['title'] ?? $catalog['id'],
'type' => substr($this->prefix, 0, -1),
'description' => $catalog['description'],
Expand Down
2 changes: 1 addition & 1 deletion app/resto/core/api/FeaturesAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public function getFeature($params)
* name="owner",
* in="query",
* style="form",
* description="Limit search to owner's features",
* description="Limit search to owner's features (i.e. resto user identifier as bigint)",
* required=false,
* @OA\Schema(
* type="integer"
Expand Down
4 changes: 2 additions & 2 deletions app/resto/core/api/GroupAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class GroupAPI
* ),
* @OA\Property(
* property="owner",
* type="string",
* description="Owner of the group (i.e. user unique identifier)"
* type="integer",
* description="Owner of the group (i.e. resto user identifier as bigint)"
* ),
* example={
* "id": 100,
Expand Down
8 changes: 6 additions & 2 deletions app/resto/core/dbfunctions/FeaturesFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,13 @@ public function removeFeature($feature)
* Remove feature
*/
try {
$this->dbDriver->pQuery('DELETE FROM ' . $this->dbDriver->targetSchema . '.' . $model->dbParams['tablePrefix'] . 'feature WHERE id=$1', array($feature->id));
$result = pg_fetch_assoc($this->dbDriver->pQuery('DELETE FROM ' . $this->dbDriver->targetSchema . '.' . $model->dbParams['tablePrefix'] . 'feature WHERE id=$1 RETURNING id', array($feature->id)));
if (empty($result)) {
return RestoLogUtil::httpError(404);
}

} catch (Exception $e) {
RestoLogUtil::httpError(500, 'Cannot delete feature ' . $feature->id);
return RestoLogUtil::httpError(500, 'Cannot delete feature ' . $feature->id);
}

/*
Expand Down

0 comments on commit 8773bfc

Please sign in to comment.