Skip to content
Snippets Groups Projects
Commit 257dfcc0 authored by jaapjansma's avatar jaapjansma
Browse files

Fixed issue with API permissions and performance improvement.

parent e11a83e6
No related branches found
No related tags found
No related merge requests found
# Version 1.107 (not yet released)
# Version 1.107
* Fixed issue with API permissions and performance improvement.
# Version 1.106
......
......@@ -175,13 +175,14 @@ class Api extends AbstractApi implements OutputInterface {
public static function buildConfigContainer(ContainerBuilder $containerBuilder) {
// Load the entities.
$dao = \CRM_Core_DAO::executeQuery("
SELECT DISTINCT o.api_entity, api_action, api_count_action
SELECT DISTINCT o.api_entity, api_action, api_count_action, o.permission
FROM civicrm_data_processor_output o
INNER JOIN civicrm_data_processor p ON o.data_processor_id = p.id
WHERE p.is_active = 1
");
$entities = array();
$actions = array();
$permissions = array();
while($dao->fetch()) {
if ($dao->api_entity ) {
......@@ -195,10 +196,14 @@ class Api extends AbstractApi implements OutputInterface {
}
$actions[$dao->api_entity][] = $dao->api_action;
$actions[$dao->api_entity][] = $dao->api_count_action;
foreach($actions[$dao->api_entity] as $action) {
$permissions[$dao->api_entity][$action] = [$dao->permission];
}
}
}
$containerBuilder->setParameter('entity_names', $entities);
$containerBuilder->setParameter('action_names', $actions);
$containerBuilder->setParameter('api3_permissions', $permissions);
}
/**
......
......@@ -67,34 +67,13 @@ function dataprocessor_civicrm_permission(&$permissions) {
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterAPIPermissions/
*/
function dataprocessor_civicrm_alterAPIPermissions($entity, $action, &$params, &$permissions) {
// We have to check the camelcase and the non camel case names
$entityNonCamelCase = _civicrm_api_get_entity_name_from_camel($entity);
$entityCamelCase = _civicrm_api_get_camel_name($entity);
$api_action = $action;
if ($action == 'getfields' && isset($params['api_action'])) {
$api_action = $params['api_action'];
}
$actionNonCamelCase = _civicrm_api_get_entity_name_from_camel($api_action);
$actionCamelCase = _civicrm_api_get_camel_name($api_action);
$dao = CRM_Core_DAO::executeQuery("
SELECT *
FROM civicrm_data_processor_output o
INNER JOIN civicrm_data_processor p ON o.data_processor_id = p.id
WHERE p.is_active = 1
AND (LOWER(api_entity) = LOWER(%1) OR LOWER(api_entity) = LOWER(%2))
AND (
LOWER(api_action) = LOWER(%3) OR LOWER(api_count_action) = LOWER(%3)
OR LOWER(api_action) = LOWER(%4) OR LOWER(api_count_action) = LOWER(%4)
)",
array(
1 => array($entityCamelCase, 'String'),
2 => array($entityNonCamelCase, 'String'),
3 => array($actionNonCamelCase, 'String'),
4 => array($actionCamelCase, 'String'))
);
while ($dao->fetch()) {
$permissions[$entity][$action] = array($dao->permission);
$config = \Civi\DataProcessor\Config\ConfigContainer::getInstance();
foreach($config->getParameter('api3_permissions') as $e => $actions) {
foreach($actions as $a => $p) {
$permissions[$e][$a] = $p;
}
}
if($entity=='data_processor_output' && $action=='get') {
$permissions['data_processor_output']['get'] = [
["access dataprocessor definitions", "administer CiviCRM"]
......
......@@ -15,7 +15,7 @@
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2024-05-30</releaseDate>
<version>1.107-dev</version>
<version>1.107</version>
<develStage>stable</develStage>
<compatibility>
<ver>5.37</ver>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment