APIv4 - Fix resolving pseudoconstants for less-permissioned users
authorColeman Watts <coleman@civicrm.org>
Fri, 29 Jul 2022 01:24:57 +0000 (21:24 -0400)
committerColeman Watts <coleman@civicrm.org>
Tue, 9 Aug 2022 21:35:17 +0000 (17:35 -0400)
Fixes dev/core#3750

Civi/Api4/Utils/FormattingUtil.php
tests/phpunit/api/v4/Entity/TagTest.php

index da1129ad4fa606350e9c0c14d836729cc9f607ec..efacccb3de3ee905d0d262f04dced2e3d89a188c 100644 (file)
@@ -265,7 +265,7 @@ class FormattingUtil {
     }
     // 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)) {
index 7aed01ce713ab1c1d1d75ca241d86c94db10efe3..60640106d0d5ffc15d1c0314fe858e8a841bf6f3 100644 (file)
@@ -30,6 +30,10 @@ use Civi\Test\TransactionalInterface;
 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')