Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APIv4 - Fix resolving pseudoconstants for less-permissioned users #24086

Merged
merged 1 commit into from
Aug 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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