Skip to content

Commit

Permalink
Ensure queries returns an array, not an object
Browse files Browse the repository at this point in the history
  • Loading branch information
driusan committed Aug 16, 2023
1 parent 95b1423 commit eb85340
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
1 change: 1 addition & 0 deletions modules/dataquery/php/queries.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Queries extends \NDB_Page
[
'queries' => iterator_to_array(
$this->getUserAccessibleQueries($user),
false, // do not preserve keys, stay an array
),
]
);
Expand Down
39 changes: 26 additions & 13 deletions modules/dataquery/php/query.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,27 @@ class Query implements \LORIS\StudyEntities\AccessibleResource,
}

// Check accessibility for fields
$fields = $this->getFields();
foreach ($fields as $field) {
if ($field->isAccessibleBy($user) === false) {
return false;
try {
$fields = $this->getFields();
foreach ($fields as $field) {
if ($field->isAccessibleBy($user) === false) {
return false;
}
}
}

// Check accessibility for dictionary items in the criteria
$critfields = $this->_getAllCriteriaDictionaries($criteria);
foreach ($critfields as $field) {
if ($field->isAccessibleBy($user) === false) {
return false;
}
// Check accessibility for dictionary items in the criteria
$critfields = $this->_getAllCriteriaDictionaries($criteria);
foreach ($critfields as $field) {
if ($field->isAccessibleBy($user) === false) {
return false;
}

}
} catch (\OutOfBoundsException $e) {
// The query references a field that no longer exists.
// The module can not provide the data, so the query is
// not accessible by anyone.
return false;
}
return true;
}
Expand Down Expand Up @@ -175,7 +182,10 @@ class Query implements \LORIS\StudyEntities\AccessibleResource,
$cname = $item['category'];
$fname = $item['fieldname'];
$this->_populateModuleDictCache($mname);
assert(isset($this->moduleDictCache[$mname][$cname][$fname]));
if (!isset($this->moduleDictCache[$mname][$cname][$fname])) {
// This query references a field that no longer exist.
throw new \OutOfBoundsException();
}
$usedDicts[] = $this->moduleDictCache[$mname][$cname][$fname];
}
}
Expand Down Expand Up @@ -373,7 +383,10 @@ class Query implements \LORIS\StudyEntities\AccessibleResource,
$fname = $field['field'];

$this->_populateModuleDictCache($mname);

if (!isset($this->moduleDictCache[$mname][$cname][$fname])) {
// This query references a field that no longer exist.
throw new \OutOfBoundsException();
}
assert(isset($this->moduleDictCache[$mname][$cname][$fname]));
$fields[] = $this->moduleDictCache[$mname][$cname][$fname];
}
Expand Down

0 comments on commit eb85340

Please # to comment.