/** @var \Civi\Api4\Generic\AbstractAction $apiRequest */
$apiRequest = $event->getApiRequest();
if ($apiRequest['version'] == 4) {
- if (!$apiRequest->getCheckPermissions() || $apiRequest->isAuthorized(\CRM_Core_Session::singleton()->getLoggedInContactID())) {
+ if (
+ !$apiRequest->getCheckPermissions() ||
+ // This action checks permissions internally
+ $apiRequest->getActionName() === 'getLinks' ||
+ $apiRequest->isAuthorized(\CRM_Core_Session::singleton()->getLoggedInContactID())
+ ) {
$event->authorize();
$event->stopPropagation();
}
use api\v4\Api4TestBase;
use Civi\API\Exception\UnauthorizedException;
+use Civi\Api4\Action\GetLinks;
use Civi\Api4\Activity;
use Civi\Api4\Address;
use Civi\Api4\Contact;
$this->assertCount(0, $result->toolbar);
// With 'add contacts' permission the button will be shown
\CRM_Core_Config::singleton()->userPermissionClass->permissions[] = 'add contacts';
+ // Clear getLinks cache after changing permissions
+ \Civi::$statics[GetLinks::class] = [];
+
$result = civicrm_api4('SearchDisplay', 'run', $params);
$this->assertCount(1, $result->toolbar);
$button = $result->toolbar[0];