Skip to content

Commit

Permalink
Test if this gets hit
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Jan 8, 2024
1 parent fd2c727 commit f527a97
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CRM/Core/BAO/EntityTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
16 changes: 8 additions & 8 deletions CRM/Core/DynamicFKAccessTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand All @@ -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;
}

}

0 comments on commit f527a97

Please sign in to comment.