Пример #1
0
 public function testRuleCustom()
 {
     ItemCategoryQuery::create()->deleteAll();
     ItemQuery::create()->deleteAll();
     TestQuery::create()->deleteAll();
     $this->getACL()->setCaching(true);
     $this->getACL()->removeObjectRules('test/item');
     $user = new User();
     $user->setUsername('testuser');
     $user->save();
     $item1 = new Item();
     $item1->setTitle('Item 1');
     $item1->save();
     $item2 = new Item();
     $item2->setTitle('Item test');
     $item2->save();
     $rule = new Acl();
     $rule->setAccess(true);
     $rule->setObject('test/item');
     $rule->setTargetType(\Jarves\ACL::TARGET_TYPE_USER);
     $rule->setTargetId($user->getId());
     $rule->setMode(\Jarves\ACL::MODE_ALL);
     $rule->setConstraintType(\Jarves\ACL::CONSTRAINT_ALL);
     $rule->setPrio(2);
     $rule->save();
     $rule = new Acl();
     $rule->setAccess(false);
     $rule->setObject('test/item');
     $rule->setTargetType(\Jarves\ACL::TARGET_TYPE_USER);
     $rule->setTargetId($user->getId());
     $rule->setMode(\Jarves\ACL::MODE_ALL);
     $rule->setConstraintType(\Jarves\ACL::CONSTRAINT_CONDITION);
     $rule->setConstraintCode(json_encode([['title', 'LIKE', '%test']]));
     $rule->setPrio(3);
     $rule->save();
     $item1ListingRequest = ACLRequest::create('test/item', $item1->getId())->onlyListingMode()->targetUser($user->getId());
     $item2ListingRequest = ACLRequest::create('test/item', $item2->getId())->onlyListingMode()->targetUser($user->getId());
     $access1 = $this->getACL()->check($item1ListingRequest);
     $access2 = $this->getACL()->check($item2ListingRequest);
     $this->assertTrue($access1, 'item1 has access as the second rule doesnt grab and first rule says all access=true');
     $this->assertFalse($access2, 'no access to item2 as we have defined access=false in second rule.');
     $user->delete();
     $this->getACL()->setCaching(true);
     $this->getACL()->removeObjectRules('test/item');
 }