public function testCachingNamedSecurableItemActualPermissions() { if (MEMCACHE_ON && Yii::app()->cache !== null) { Yii::app()->user->userModel = User::getByUsername('super'); $super = User::getByUsername('super'); $namedSecurableItem = 'AccountsModule'; $item = NamedSecurableItem::getByName('AccountsModule'); $actualPermissions = $item->getActualPermissions(); PermissionsCache::cacheNamedSecurableItemActualPermissions($namedSecurableItem, $super, $actualPermissions); $actualPermissionsFromCache = PermissionsCache::getNamedSecurableItemActualPermissions($namedSecurableItem, $super); $this->assertEquals($actualPermissions, $actualPermissionsFromCache); } }
public function testCachingNamedSecurableItemActualPermissions() { if (PermissionsCache::supportsAndAllowsMemcache() || PermissionsCache::supportsAndAllowsDatabaseCaching()) { Yii::app()->user->userModel = User::getByUsername('super'); $super = User::getByUsername('super'); $namedSecurableItem = 'AccountsModule'; $item = NamedSecurableItem::getByName('AccountsModule'); $actualPermissions = $item->getActualPermissions(); PermissionsCache::cacheNamedSecurableItemActualPermissions($namedSecurableItem, $super, $actualPermissions); $actualPermissionsFromCache = PermissionsCache::getNamedSecurableItemActualPermissions($namedSecurableItem, $super); $this->assertEquals($actualPermissions, $actualPermissionsFromCache); } }
/** * Override to add caching capabilities of this information. * @see SecurableItem::getActualPermissions() */ public function getActualPermissions($permitable = null) { assert('$permitable === null || $permitable instanceof Permitable'); if ($permitable === null) { $permitable = Yii::app()->user->userModel; if (!$permitable instanceof User) { throw new NoCurrentUserSecurityException(); } } if ($this->name != null) { try { return PermissionsCache::getNamedSecurableItemActualPermissions($this->name, $permitable); } catch (NotFoundException $e) { $actualPermissions = parent::getActualPermissions($permitable); } PermissionsCache::cacheNamedSecurableItemActualPermissions($this->name, $permitable, $actualPermissions); return $actualPermissions; } return parent::getActualPermissions($permitable); }