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(); } else { PermissionsCache::forgetSecurableItem($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(); } else { PermissionsCache::forgetSecurableItem($this); } }
public function testForgetSecurableItem() { if (MEMCACHE_ON && Yii::app()->cache !== null) { $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); try { PermissionsCache::getCombinedPermissions($account, $super); $this->fail('NotFoundException exception is not thrown.'); } catch (NotFoundException $e) { $this->assertTrue(true); } } }