Skip to content

Commit

Permalink
CRM-21229 improve static var management in group permission clause
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Nov 21, 2017
1 parent a6bd202 commit bc95ea0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
1 change: 1 addition & 0 deletions CRM/ACL/BAO/ACL.php
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ public static function group(
$cache = CRM_Utils_Cache::singleton();
$ids = $cache->get($cacheKey);
if (!$ids) {
$ids = array();
$query = "
SELECT a.operation, a.object_id
FROM civicrm_acl_cache c, civicrm_acl a
Expand Down
14 changes: 5 additions & 9 deletions CRM/Contact/BAO/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,16 +602,11 @@ public static function groupTypeCondition($groupType = NULL, $excludeHidden = TR

/**
* Get permission relevant clauses.
* CRM-12209
*
* @param bool $force
*
* @return array
*/
public static function getPermissionClause($force = FALSE) {
static $clause = 1;
static $retrieved = FALSE;
if (!$retrieved || $force) {
public static function getPermissionClause() {
if (!isset(Civi::$statics[__CLASS__]['permission_clause'])) {
if (CRM_Core_Permission::check('view all contacts') || CRM_Core_Permission::check('edit all contacts')) {
$clause = 1;
}
Expand All @@ -626,9 +621,9 @@ public static function getPermissionClause($force = FALSE) {
$clause = '1 = 0';
}
}
Civi::$statics[__CLASS__]['permission_clause'] = $clause;
}
$retrieved = TRUE;
return $clause;
return Civi::$statics[__CLASS__]['permission_clause'];
}

/**
Expand All @@ -642,6 +637,7 @@ protected static function flushCaches() {
'CRM_Core_PseudoConstant' => 'groups',
'CRM_ACL_API' => 'group_permission',
'CRM_ACL_BAO_ACL' => 'permissioned_groups',
'CRM_Contact_BAO_Group' => 'permission_clause',
);
foreach ($staticCaches as $class => $key) {
if (isset(Civi::$statics[$class][$key])) {
Expand Down
7 changes: 1 addition & 6 deletions tests/phpunit/CRM/Group/Page/AjaxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase {

public function setUp() {
parent::setUp();
// CRM_Contact_BAO_Group::getPermissionClause sets a static variable.
// Ensure it is reset before each run.
$force = TRUE;
CRM_Contact_BAO_Group::getPermissionClause($force);
$this->_params = array(
'page' => 1,
'rp' => 50,
Expand Down Expand Up @@ -79,7 +75,6 @@ public function setPermissionAndRequest($permission) {
public function setHookAndRequest($permission, $hook) {
CRM_Core_Config::singleton()->userPermissionClass->permissions = (array) $permission;
$this->hookClass->setHook('civicrm_aclGroup', array($this, $hook));
CRM_Contact_BAO_Group::getPermissionClause(TRUE);
global $_REQUEST;
$_REQUEST = $this->_params;
}
Expand Down Expand Up @@ -253,7 +248,7 @@ public function testGroupListViewAllContactsAll() {
*/
public function testGroupListAccessCiviCRM() {
$this->setPermissionAndRequest('access CiviCRM');
$permissionClause = CRM_Contact_BAO_Group::getPermissionClause(TRUE);
$permissionClause = CRM_Contact_BAO_Group::getPermissionClause();
$this->assertEquals('1 = 0', $permissionClause);
$params = $this->_params;
$groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
Expand Down
2 changes: 0 additions & 2 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3092,7 +3092,6 @@ public function setupACL($isProfile = FALSE) {
if (!$isProfile) {
//flush cache
CRM_ACL_BAO_Cache::resetCache();
CRM_Contact_BAO_Group::getPermissionClause(TRUE);
CRM_ACL_API::groupPermission('whatever', 9999, NULL, 'civicrm_saved_search', NULL, NULL, TRUE);
}
}
Expand Down Expand Up @@ -3572,7 +3571,6 @@ protected function flushFinancialTypeStatics() {
protected function setPermissions($permissions) {
CRM_Core_Config::singleton()->userPermissionClass->permissions = $permissions;
$this->flushFinancialTypeStatics();
CRM_Contact_BAO_Group::getPermissionClause(TRUE);
}

/**
Expand Down

0 comments on commit bc95ea0

Please sign in to comment.