public function testCacheAndGetHasReadPermissionOnSecurableItem() { if (AllPermissionsOptimizationCache::supportsAndAllowsMemcache()) { $account = new Account(); $account->name = 'Yooples'; $this->assertTrue($account->save()); $super = User::getByUsername('super'); AllPermissionsOptimizationCache::cacheHasReadPermissionOnSecurableItem($account, $super, true); $hasReadPermission = AllPermissionsOptimizationCache::getHasReadPermissionOnSecurableItem($account, $super); $this->assertTrue($hasReadPermission); AllPermissionsOptimizationCache::forgetSecurableItemForRead($account); try { AllPermissionsOptimizationCache::getHasReadPermissionOnSecurableItem($account, $super); $this->fail('NotFoundException exception is not thrown.'); } catch (NotFoundException $e) { $this->assertTrue(true); } } }
/** * @param SecurableItem $securableItem * @param Group $group */ public static function securableItemLostReadPermissionsForGroup(SecurableItem $securableItem, Group $group) { ReadPermissionsOptimizationUtil::securableItemLostPermissionsForGroup($securableItem, $group); AllPermissionsOptimizationCache::forgetSecurableItemForRead($securableItem); }
/** * @param Permitable $permitable * @param int $permissions * @param array $type */ public function removePermissions(Permitable $permitable, $permissions = Permission::ALL, $type = Permission::ALLOW_DENY) { assert('is_int($permissions)'); assert("({$permissions} & ~Permission::ALL) == 0"); assert('$permissions != Permission::NONE'); assert('in_array($type, array(Permission::ALLOW, Permission::DENY, Permission::ALLOW_DENY))'); $this->checkPermissionsHasAnyOf(Permission::CHANGE_PERMISSIONS); if ($this instanceof NamedSecurableItem) { PermissionsCache::forgetAll(); AllPermissionsOptimizationCache::forgetAll(); } else { PermissionsCache::forgetSecurableItem($this); AllPermissionsOptimizationCache::forgetSecurableItemForRead($this); } foreach ($this->permissions as $permission) { if ($permission->permitable->isSame($permitable) && ($permission->type == $type || $type == Permission::ALLOW_DENY)) { $permission->permissions &= ~$permissions; if ($permission->permissions == Permission::NONE) { $this->permissions->remove($permission); } } } if ($this instanceof NamedSecurableItem) { PermissionsCache::forgetAll(); AllPermissionsOptimizationCache::forgetAll(); } else { PermissionsCache::forgetSecurableItem($this); AllPermissionsOptimizationCache::forgetSecurableItemForRead($this); } $this->permissionsChanged = true; }
public function testForgetSecurableItem() { if (PermissionsCache::supportsAndAllowsMemcache()) { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $account = new Account(); $account->name = 'Ocean Inc.'; $this->assertTrue($account->save()); $combinedPermissions = 5; PermissionsCache::cacheCombinedPermissions($account, $super, $combinedPermissions); $combinedPermissionsFromCache = PermissionsCache::getCombinedPermissions($account, $super); $this->assertEquals($combinedPermissions, $combinedPermissionsFromCache); PermissionsCache::forgetSecurableItem($account); AllPermissionsOptimizationCache::forgetSecurableItemForRead($account); try { PermissionsCache::getCombinedPermissions($account, $super); $this->fail('NotFoundException exception is not thrown.'); } catch (NotFoundException $e) { $this->assertTrue(true); } } }