Skip to content

Commit

Permalink
Fix error for value pointing to private items
Browse files Browse the repository at this point in the history
The code preventing this kind of error was keyed specifically to the
name "resource" for the data type of the value, but we've since
introduced other more specific resource types for values that can point
only to items, sets, etc.

Rather than base this check on the name of the type, this instead
checks if the type class extends from the abstract class for resource
data types. This introduces a new method isHidden to the value
representation to simplify this check.

(fix #1507)

(cherry picked from commit 61abd65)
  • Loading branch information
zerocrates committed Mar 25, 2020
1 parent f6749af commit 0d29416
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public function values()
$values = [];
foreach ($this->resource->getValues() as $valueEntity) {
$value = new ValueRepresentation($valueEntity, $this->getServiceLocator());
if ('resource' === $value->type() && null === $value->valueResource()) {
if ($value->isHidden()) {
// Skip this resource value if the resource is not available
// (most likely because it is private).
continue;
Expand Down
18 changes: 17 additions & 1 deletion application/src/Api/Representation/ValueRepresentation.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Omeka\Api\Representation;

use Omeka\DataType\Resource\AbstractResource;
use Omeka\Entity\Value;
use Zend\ServiceManager\ServiceLocatorInterface;

Expand All @@ -12,7 +13,7 @@ class ValueRepresentation extends AbstractRepresentation
protected $value;

/**
* @var \Omeka\DataType\Manager
* @var \Omeka\DataType\DataTypeInterface
*/
protected $dataType;

Expand Down Expand Up @@ -168,4 +169,19 @@ public function isPublic()
{
return $this->value->isPublic();
}

/**
* Return whether this value should be hidden when listing values for its
* parent resource.
*
* Currently the only "hidden" values are resource-type values that point
* to unretrievable resources (i.e., private resources the current user
* cannot see).
*
* @return bool
*/
public function isHidden()
{
return $this->dataType instanceof AbstractResource && null === $this->value->getValueResource();
}
}

0 comments on commit 0d29416

Please sign in to comment.