Skip to content

Commit

Permalink
Merge pull request #24203 from colemanw/fixTagFilter553
Browse files Browse the repository at this point in the history
APIv4 - Fix resolving pseudoconstants for less-permissioned users
  • Loading branch information
eileenmcnaughton authored Aug 10, 2022
2 parents fbe1bd6 + 05d4c0d commit 7bdbd08
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Civi/Api4/Utils/FormattingUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public static function getPseudoconstantList(array $field, string $fieldAlias, $
}
// Fallback for option lists that exist in the api but not the BAO
if (!isset($options) || $options === FALSE) {
$options = civicrm_api4($field['entity'], 'getFields', ['action' => $action, 'loadOptions' => ['id', $valueType], 'where' => [['name', '=', $field['name']]]])[0]['options'] ?? NULL;
$options = civicrm_api4($field['entity'], 'getFields', ['checkPermissions' => FALSE, 'action' => $action, 'loadOptions' => ['id', $valueType], 'where' => [['name', '=', $field['name']]]])[0]['options'] ?? NULL;
$options = $options ? array_column($options, $valueType, 'id') : $options;
}
if (is_array($options)) {
Expand Down
4 changes: 4 additions & 0 deletions tests/phpunit/api/v4/Entity/TagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
class TagTest extends Api4TestBase implements TransactionalInterface {

public function testTagFilter() {
// Ensure bypassing permissions works correctly by giving none to the logged-in user
$this->createLoggedInUser();
\CRM_Core_Config::singleton()->userPermissionClass->permissions = [];

$conTag = Tag::create(FALSE)
->addValue('name', uniqid('con'))
->addValue('used_for', 'civicrm_contact')
Expand Down

0 comments on commit 7bdbd08

Please sign in to comment.