From e9a48f3f90f378c3f4ad9be3189d47ee354ca02e Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 2 Feb 2022 19:59:20 -0500 Subject: [PATCH] REF - Use function to get componenent name from permission --- CRM/Core/BAO/Dashboard.php | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/CRM/Core/BAO/Dashboard.php b/CRM/Core/BAO/Dashboard.php index d0866aceec..4e19a85546 100644 --- a/CRM/Core/BAO/Dashboard.php +++ b/CRM/Core/BAO/Dashboard.php @@ -134,13 +134,13 @@ class CRM_Core_BAO_Dashboard extends CRM_Core_DAO_Dashboard { /** * Check dashlet permission for current user. * - * @param array $permissions - * @param string $operator + * @param array|null $permissions + * @param string|null $operator * * @return bool * true if user has permission to view dashlet */ - public static function checkPermission($permissions, $operator) { + private static function checkPermission(?array $permissions, ?string $operator): bool { if ($permissions) { static $allComponents; if (!$allComponents) { @@ -151,22 +151,9 @@ class CRM_Core_BAO_Dashboard extends CRM_Core_DAO_Dashboard { foreach ($permissions as $key) { $showDashlet = TRUE; - $componentName = NULL; - if (strpos($key, 'access') === 0) { - $componentName = trim(substr($key, 6)); - if (!in_array($componentName, $allComponents)) { - $componentName = NULL; - } - } - - // hack to handle case permissions - if (!$componentName - && in_array($key, ['access my cases and activities', 'access all cases and activities']) - ) { - $componentName = 'CiviCase'; - } + $componentName = CRM_Core_Permission::getComponentName($key); - //hack to determine if it's a component related permission + // If the permission depends on a component, ensure it is enabled if ($componentName) { if (!CRM_Core_Component::isEnabled($componentName) || !CRM_Core_Permission::check($key)) { $showDashlet = FALSE; @@ -189,17 +176,10 @@ class CRM_Core_BAO_Dashboard extends CRM_Core_DAO_Dashboard { } } - if (!$showDashlet && !$hasPermission) { - return FALSE; - } - else { - return TRUE; - } - } - else { - // if permission is not set consider everyone has permission to access it. - return TRUE; + return $showDashlet || $hasPermission; } + // If permission is not set consider everyone has access. + return TRUE; } /** -- 2.25.1