Skip to content

Commit

Permalink
WIP: workflow read field blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
wellingguzman committed Mar 12, 2018
1 parent 8a69242 commit f9cf7b2
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/core/Directus/Database/TableGateway/RelationalTableGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -802,10 +802,19 @@ public function loadItems(array $params = [], \Closure $queryCallback = null)
// TODO: Create a new TableGateway Query Builder based on Query\Builder
$builder = new Builder($this->getAdapter());
$builder->from($this->getTable());
$builder->columns(
array_merge([$collectionObject->getPrimaryKeyName()], $this->getSelectedNonAliasFields($fields))

$selectedFields = array_merge(
[$collectionObject->getPrimaryKeyName()],
$this->getSelectedNonAliasFields($fields)
);

$statusField = $collectionObject->getStatusField();
if ($statusField && $this->acl->getCollectionStatuses($this->table)) {
$selectedFields = array_merge($selectedFields, [$statusField->getName()]);
}

$builder->columns($selectedFields);

$builder = $this->applyParamsToTableEntriesSelect(
$params,
$builder
Expand Down Expand Up @@ -870,6 +879,19 @@ public function loadItems(array $params = [], \Closure $queryCallback = null)
}, $results);
}

if ($statusField && $this->acl->getCollectionStatuses($this->table)) {
foreach ($results as $index => &$item) {
$statusId = ArrayUtils::get($item, $statusField->getName());
$blacklist = $this->acl->getReadFieldBlacklist($this->table, $statusId);
$item = ArrayUtils::omit($item, $blacklist);
if (empty($item)) {
unset($results[$index]);
}
}

$results = array_values($results);
}

if (ArrayUtils::has($params, 'single')) {
$results = reset($results);
}
Expand Down

0 comments on commit f9cf7b2

Please sign in to comment.