Skip to content

Commit

Permalink
new: [API] Fast check object or attribute existence by HEAD method
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubOnderka committed Nov 2, 2020
1 parent 557c4f5 commit c800470
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/Controller/AttributesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,14 @@ public function editField($id)

public function view($id)
{
if ($this->request->is('head')) { // Just check if attribute exists
$attribute = $this->Attribute->fetchAttributesSimple($this->Auth->user(), [
'conditions' => $this->__idToConditions($id),
'fields' => ['Attribute.id'],
]);
return new CakeResponse(['status' => $attribute ? 200 : 404]);
}

$attribute = $this->__fetchAttribute($id);
if (empty($attribute)) {
throw new MethodNotAllowedException(__('Invalid attribute'));
Expand Down
8 changes: 8 additions & 0 deletions app/Controller/ObjectsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,14 @@ private function __delete($id, $hard)
public function view($id)
{
if ($this->_isRest()) {
if ($this->request->is('head')) { // Just check if object exists
$exists = $this->MispObject->fetchObjects($this->Auth->user(), [
'conditions' => $this->__objectIdToConditions($id),
'metadata' => true,
]);
return new CakeResponse(['status' => $exists ? 200 : 404]);
}

$objects = $this->MispObject->fetchObjects($this->Auth->user(), array(
'conditions' => $this->__objectIdToConditions($id),
));
Expand Down

0 comments on commit c800470

Please sign in to comment.