Authority is an authorization library for CodeIgniter 2+ and PHPActiveRecord This library is inspired by, and largely based off, Ryan Bates' CanCan gem for Ruby on Rails. It is not a 1:1 port, but the essentials are available. Please check out his work at http://github.com/ryanb/cancan/
Author: Matthew Machuga
Exemplo n.º 1
0
 /**
  * Determine if current rule is relevant based on an action and resource
  *
  * @param string|array  $action Action in question
  * @param string|mixed  $resource Name of resource or instance of object
  * @return boolean
  */
 public function isRelevant($action, $resource)
 {
     // Nested resources can be passed through a associative array, this way conditions which are
     // dependent upon the association will work when using a class.
     $resource = is_array($resource) ? head(array_keys($resource)) : $resource;
     return parent::isRelevant($action, $resource);
 }
Exemplo n.º 2
0
 public function testCanSetAndCheckRestrictionAgainstConditions()
 {
     $object1 = new stdClass();
     $object1->id = 1;
     $object2 = new stdClass();
     $object2->id = 2;
     $rule = new Rule(false, 'read', 'stdClass', function ($obj) {
         return $obj->id == 1;
     });
     $this->assertFalse($rule->isAllowed($object1));
     $this->assertTrue($rule->isAllowed($object2));
     $rule->when(function ($obj) {
         return 1 == 2;
     });
     $this->assertFalse($rule->isAllowed($object1));
     $this->assertTrue($rule->isAllowed($object2));
     $rule->when(function ($obj) {
         return 1 == 1;
     });
     $this->assertFalse($rule->isAllowed($object1));
     $this->assertFalse($rule->isAllowed($object2));
 }