/** * @param $version */ function generateJoomlaConfig($version) { global $targetDir, $sourceCheckoutDir, $pkgType; $smarty = new Smarty(); $smarty->template_dir = $sourceCheckoutDir . '/xml/templates'; $smarty->compile_dir = '/tmp/templates_c_u' . posix_geteuid(); createDir($smarty->compile_dir); $smarty->assign('CiviCRMVersion', $version); $smarty->assign('creationDate', date('F d Y')); $smarty->assign('pkgType', $pkgType); $xml = $smarty->fetch('joomla.tpl'); $output = $targetDir . '/civicrm.xml'; $fd = fopen($output, "w"); fwrite($fd, $xml); fclose($fd); require_once 'CRM/Core/Config.php'; $config = CRM_Core_Config::singleton(FALSE); require_once 'CRM/Core/Permission.php'; require_once 'CRM/Utils/String.php'; require_once 'CRM/Core/I18n.php'; $permissions = CRM_Core_Permission::getCorePermissions(TRUE); $crmFolderDir = $sourceCheckoutDir . DIRECTORY_SEPARATOR . 'CRM'; require_once 'CRM/Core/Component.php'; $components = CRM_Core_Component::getComponentsFromFile($crmFolderDir); foreach ($components as $comp) { $perm = $comp->getPermissions(FALSE, TRUE); if ($perm) { $info = $comp->getInfo(); foreach ($perm as $p => $attr) { $title = $info['translatedName'] . ': ' . array_shift($attr); array_unshift($attr, $title); $permissions[$p] = $attr; } } } $perms_array = array(); foreach ($permissions as $perm => $attr) { // give an empty string as default description $attr[] = ''; //order matters here, but we deal with that later $perms_array[CRM_Utils_String::munge(strtolower($perm))] = array('title' => array_shift($attr), 'description' => array_shift($attr)); } $smarty->assign('permissions', $perms_array); $output = $targetDir . '/admin/access.xml'; $xml = $smarty->fetch('access.tpl'); $fd = fopen($output, "w"); fwrite($fd, $xml); fclose($fd); }
/** * Should we be adding ACLs in this instance. If we don't add them the user * will not be able to see anything. We check if the install has the permissions * hook implemented correctly & if so only allow view & edit based on those. * * Otherwise all users get these permissions added (4.2 vs 4.3 / other CMS issues) * * @param integer $type type of operation * * @return bool */ function _multisite_add_permissions($type) { $hookclass = 'CRM_Utils_Hook'; if (!method_exists($hookclass, 'permissions')) { // ie. unpatched 4.2 so we can't check for extra declared permissions // & default to applying this to all return TRUE; } // extra check to make sure that hook is properly implemented // if not we won't check for it. NB view all contacts in domain is enough checking $declaredPermissions = CRM_Core_Permission::getCorePermissions(); if (!array_key_exists('view all contacts in domain', $declaredPermissions)) { drupal_set_message('here'); return TRUE; } if (CRM_ACL_BAO_ACL::matchType($type, 'View') && CRM_Core_Permission::check('view all contacts in domain')) { return TRUE; } if (CRM_ACL_BAO_ACL::matchType($type, 'Edit') && CRM_Core_Permission::check('edit all contacts in domain')) { return TRUE; } return FALSE; }
/** * @inheritDoc */ public function upgradePermissions($permissions) { $civicrm_perms = array_keys(CRM_Core_Permission::getCorePermissions()); if (empty($civicrm_perms)) { throw new CRM_Core_Exception("Cannot upgrade permissions: permission list missing"); } $roles = user_roles(TRUE); foreach ($roles as $role) { foreach ($civicrm_perms as $permission) { $role->revokePermission($permission); } } }
/** * Check method testPermissionedFinancialTypes() */ public function testPermissionedFinancialTypes() { // First get all core permissions $permissions = $checkPerms = CRM_Core_Permission::getCorePermissions(); $this->setACL(); CRM_Financial_BAO_FinancialType::permissionedFinancialTypes($permissions, TRUE); $financialTypes = CRM_Contribute_PseudoConstant::financialType(); $prefix = ts('CiviCRM') . ': '; $actions = array('add', 'view', 'edit', 'delete'); foreach ($financialTypes as $id => $type) { foreach ($actions as $action) { $checkPerms[$action . ' contributions of type ' . $type] = array($prefix . ts($action . ' contributions of type ') . $type, ts(ucfirst($action) . ' contributions of type ') . $type); } } $checkPerms['administer CiviCRM Financial Types'] = array($prefix . ts('administer CiviCRM Financial Types'), ts('Administer access to Financial Types')); $this->assertEquals($permissions, $checkPerms, 'Verify that permissions for each financial type have been added'); }