Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] Minor extraction to help cleanup permission code #19803

Merged
merged 1 commit into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions CRM/Core/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -1684,6 +1683,8 @@ public static function checkDownloadInvoice() {
}

/**
* Get permissions for components.
*
* @param bool $includeDisabled
*
* @return array
Expand Down Expand Up @@ -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;
}

}
1 change: 1 addition & 0 deletions CRM/Core/Permission/Drupal8.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions distmaker/utils/joomlaxml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down