From d2b6eac83ecffbbaaa3cbb532035f28e8aca08ab Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 15 Mar 2021 10:20:36 +1300 Subject: [PATCH] [REF] Minor extraction to help cleanup permission code --- CRM/Core/Permission.php | 25 ++++++++++++++++++++----- CRM/Core/Permission/Drupal8.php | 1 + distmaker/utils/joomlaxml.php | 2 ++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CRM/Core/Permission.php b/CRM/Core/Permission.php index 2837ad3ac1e0..7191a8e60c6c 100644 --- a/CRM/Core/Permission.php +++ b/CRM/Core/Permission.php @@ -585,14 +585,13 @@ public static function basicPermissions($all = FALSE, $descriptions = FALSE) { * whether to return descriptions * * @return array + * @throws \CRM_Core_Exception */ - public static function assembleBasicPermissions($all = FALSE, $descriptions = FALSE) { - $config = CRM_Core_Config::singleton(); - $permissions = self::getCorePermissions(); - $permissions = array_merge($permissions, self::getComponentPermissions($all)); + public static function assembleBasicPermissions($all = FALSE, $descriptions = FALSE): array { + $permissions = self::getCoreAndComponentPermissions($all); // Add any permissions defined in hook_civicrm_permission implementations. - $module_permissions = $config->userPermissionClass->getAllModulePermissions(TRUE); + $module_permissions = CRM_Core_Config::singleton()->userPermissionClass->getAllModulePermissions(TRUE); $permissions = array_merge($permissions, $module_permissions); if (!$descriptions) { foreach ($permissions as $name => $attr) { @@ -1684,6 +1683,8 @@ public static function checkDownloadInvoice() { } /** + * Get permissions for components. + * * @param bool $includeDisabled * * @return array @@ -1716,4 +1717,18 @@ protected static function getComponentPermissions(bool $includeDisabled): array return $permissions; } + /** + * Get permissions for core functionality and for that of core components. + * + * @param bool $all + * + * @return array + * @throws \CRM_Core_Exception + */ + protected static function getCoreAndComponentPermissions(bool $all): array { + $permissions = self::getCorePermissions(); + $permissions = array_merge($permissions, self::getComponentPermissions($all)); + return $permissions; + } + } diff --git a/CRM/Core/Permission/Drupal8.php b/CRM/Core/Permission/Drupal8.php index 65112da46465..add83a00f337 100644 --- a/CRM/Core/Permission/Drupal8.php +++ b/CRM/Core/Permission/Drupal8.php @@ -109,6 +109,7 @@ function (\Drupal\user\RoleInterface $role) { * @inheritDoc */ public function upgradePermissions($permissions) { + // @todo - this should probably call getCoreAndComponentPermissions. $civicrm_perms = array_keys(CRM_Core_Permission::getCorePermissions()); if (empty($civicrm_perms)) { throw new CRM_Core_Exception("Cannot upgrade permissions: permission list missing"); diff --git a/distmaker/utils/joomlaxml.php b/distmaker/utils/joomlaxml.php index 5367d1cbc44b..5a77a2f1ba26 100644 --- a/distmaker/utils/joomlaxml.php +++ b/distmaker/utils/joomlaxml.php @@ -65,6 +65,8 @@ function generateJoomlaConfig($version) { $crmFolderDir = $sourceCheckoutDir . DIRECTORY_SEPARATOR . 'CRM'; + // @todo call getCoreAndComponentPermissions instead and let that + // do the work of these next 15-20 lines. require_once 'CRM/Core/Component.php'; $components = CRM_Core_Component::getComponentsFromFile($crmFolderDir); foreach ($components as $comp) {