/**
* 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) {
- $config = CRM_Core_Config::singleton();
-
static $allComponents;
if (!$allComponents) {
$allComponents = CRM_Core_Component::getNames();
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 (!in_array($componentName, $config->enableComponents) ||
- !CRM_Core_Permission::check($key)
- ) {
+ if (!CRM_Core_Component::isEnabled($componentName) || !CRM_Core_Permission::check($key)) {
$showDashlet = FALSE;
if ($operator == 'AND') {
return $showDashlet;
}
}
- 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;
}
/**