return in_array(__CLASS__, ['CRM_Core_BAO_Phone', 'CRM_Core_BAO_Email', 'CRM_Core_BAO_Address']) &&
CRM_Core_Permission::check('edit all events', $userID);
}
- return CRM_Contact_BAO_Contact::checkAccess(CRM_Core_Permission::EDIT, ['id' => $cid], $userID);
+ return \Civi\Api4\Utils\CoreUtil::checkAccessDelegated('Contact', 'update', ['id' => $cid], $userID);
}
}
throw new CRM_Core_Exception('Missing required $groupName in CustomValue::checkAccess');
}
// Currently, multi-record custom data always extends Contacts
+ $extends = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $groupName, 'extends', 'name');
+ if (!in_array($extends, ['Contact', 'Individual', 'Organization', 'Household'])) {
+ throw new CRM_Core_Exception("Cannot assess delegated permissions for group {$groupName}.");
+ }
+
$cid = $record['entity_id'] ?? NULL;
if (!$cid) {
$tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $groupName, 'table_name', 'name');
$cid = CRM_Core_DAO::singleValueQuery("SELECT entity_id FROM `$tableName` WHERE id = " . (int) $record['id']);
}
- $granted = CRM_Contact_BAO_Contact::checkAccess(CRM_Core_Permission::EDIT, ['id' => $cid], $userID, $granted);
// Dispatch to hook
+ $granted = NULL;
CRM_Utils_Hook::checkAccess("Custom_$groupName", $action, $record, $userID, $granted);
+ if ($granted === NULL) {
+ $granted = \Civi\Api4\Utils\CoreUtil::checkAccessDelegated('Contact', 'update', ['id' => $cid], $userID);
+ }
return $granted;
}
$table = CRM_Core_DAO::getFieldValue(__CLASS__, $record['id'], 'entity_table');
}
if ($eid && $table) {
- $bao = CRM_Core_DAO_AllCoreTables::getBAOClassName(CRM_Core_DAO_AllCoreTables::getClassForTable($table));
- return $bao::checkAccess(CRM_Core_Permission::EDIT, ['id' => $eid], $userID);
+ $targetEntity = CRM_Core_DAO_AllCoreTables::getBriefName(CRM_Core_DAO_AllCoreTables::getClassForTable($table));
+ return \Civi\Api4\Utils\CoreUtil::checkAccessDelegated($targetEntity, 'update', ['id' => $eid], $userID);
}
return TRUE;
}
return $granted;
}
+ /**
+ * If the permissions of record $A are based on record $B, then use `checkAccessDelegated($B...)`
+ * to make see if access to $B is permitted.
+ *
+ * @param string $entityName
+ * @param string $actionName
+ * @param array $record
+ * @param int|null $userID
+ * Contact ID of the user we are testing, or NULL for the anonymous user.
+ *
+ * @return bool
+ * @throws \API_Exception
+ * @throws \CRM_Core_Exception
+ */
+ public static function checkAccessDelegated(string $entityName, string $actionName, array $record, $userID = NULL) {
+ // FIXME: Move isAuthorized check into here. It's redundant for normal checkAccess().
+ return static::checkAccess($entityName, $actionName, $record, $userID);
+ }
+
}
function civicrm_api3_contribution_delete($params) {
$contributionID = !empty($params['contribution_id']) ? $params['contribution_id'] : $params['id'];
- if (!empty($params['check_permissions']) && !CRM_Contribute_BAO_Contribution::checkAccess('delete', ['id' => $contributionID])) {
+ if (!empty($params['check_permissions']) && !\Civi\Api4\Utils\CoreUtil::checkAccessDelegated('Contribution', 'delete', ['id' => $contributionID], CRM_Core_Session::getLoggedInContactID())) {
throw new API_Exception('You do not have permission to delete this contribution');
}
if (CRM_Contribute_BAO_Contribution::deleteContribution($contributionID)) {