diff --git a/CRM/Core/BAO/EntityTag.php b/CRM/Core/BAO/EntityTag.php index 97c94866d95d..dbe88447ee8a 100644 --- a/CRM/Core/BAO/EntityTag.php +++ b/CRM/Core/BAO/EntityTag.php @@ -15,7 +15,7 @@ * @package CRM * @copyright CiviCRM LLC https://civicrm.org/licensing */ -class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag { +class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag implements \Civi\Core\HookInterface { use CRM_Core_DynamicFKAccessTrait; /** diff --git a/CRM/Core/DynamicFKAccessTrait.php b/CRM/Core/DynamicFKAccessTrait.php index d2dbd72c659b..b064704adf1e 100644 --- a/CRM/Core/DynamicFKAccessTrait.php +++ b/CRM/Core/DynamicFKAccessTrait.php @@ -15,20 +15,21 @@ * @copyright CiviCRM LLC https://civicrm.org/licensing */ +use Civi\Api4\Event\AuthorizeRecordEvent; +use Civi\Api4\Utils\CoreUtil; + /** * Trait for with entities with an entity_table + entity_id dynamic FK. */ trait CRM_Core_DynamicFKAccessTrait { /** - * @param string $entityName - * @param string $action - * @param array $record - * @param int $userID - * @return bool * @see \Civi\Api4\Utils\CoreUtil::checkAccessRecord */ - public static function _checkAccess(string $entityName, string $action, array $record, int $userID): bool { + public static function self_civi_api4_authorizeRecord(AuthorizeRecordEvent $e): void { + $record = $e->getRecord(); + $userID = $e->getUserID();return; + $delegateAction = $e->getActionName() === 'get' ? 'get' : 'update'; $eid = $record['entity_id'] ?? NULL; $table = $record['entity_table'] ?? NULL; if (!$eid && !empty($record['id'])) { @@ -43,9 +44,8 @@ public static function _checkAccess(string $entityName, string $action, array $r throw new \CRM_Core_Exception(sprintf('Cannot resolve permissions for dynamic foreign key in "%s". Invalid table reference "%s".', static::getTableName(), $table)); } - return \Civi\Api4\Utils\CoreUtil::checkAccessDelegated($targetEntity, 'update', ['id' => $eid], $userID); + $e->setAuthorized(CoreUtil::checkAccessDelegated($targetEntity, $delegateAction, ['id' => $eid], $userID)); } - return TRUE; } }