X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FTask.php;h=3ef3690a722ecb3d58016d31f9806d060328a562;hb=96d9c94a6d9c49a84cd38ab3b3d68167b3274d47;hp=a947f4729c001b9fd6fb7cfdbd10d770ed01a87e;hpb=b489bc7b963b2d9e59baf330f155302d24de7786;p=civicrm-core.git diff --git a/CRM/Core/Task.php b/CRM/Core/Task.php index a947f4729c..3ef3690a72 100644 --- a/CRM/Core/Task.php +++ b/CRM/Core/Task.php @@ -47,7 +47,7 @@ abstract class CRM_Core_Task { * * @var array */ - public static $_tasks = NULL; + public static $_tasks = []; /** * @var string @@ -165,6 +165,51 @@ abstract class CRM_Core_Task { ]; } + /** + * Filter tasks based on the permission key, if available. + * + * @param array $tasks + * @param bool $hasEditContactPermission + * Does the user have permission to edit the given contact. Required where + * permission to edit the user is required in conjunction with permission + * to do the task. + * + * @return array + */ + protected static function getTasksFilteredByPermission(array $tasks, bool $hasEditContactPermission): array { + foreach ($tasks as $index => $task) { + // requires_edit_contact_permission is a (hopefully transient way) of denoting which + // tasks need 'edit this contact' on top of the membership permission. + if (!empty($task['requires_edit_contact_permission']) && !$hasEditContactPermission) { + unset($tasks[$index]); + } + elseif (!empty($task['permissions']) && !CRM_Core_Permission::check($task['permissions'])) { + unset($tasks[$index]); + } + } + return $tasks; + } + + /** + * Get task tiles filtered by any declared permissions. + * + * @param array $tasks + * @param bool $hasEditContactPermission + * Does the user have permission to edit the given contact. Required where + * permission to edit the user is required in conjunction with permission + * to do the task. + * + * @return array + */ + protected static function getTitlesFilteredByPermission(array $tasks, bool $hasEditContactPermission): array { + $availableTasks = self::getTasksFilteredByPermission($tasks, $hasEditContactPermission); + $return = []; + foreach ($availableTasks as $key => $details) { + $return[$key] = $details['title']; + } + return $return; + } + /** * Function to return the task information on basis of provided task's form name *