public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null)
 {
     if ($this->preAssert($acl, $role, $resource, $privilege)) {
         $event = new AssertionEvent(null, $this);
         $event->setAcl($acl)->setRole($role)->setResource($resource)->setPrivilege($privilege);
         $events = $this->getEventManager();
         $results = $events->triggerUntil($event, function ($r) {
             return false === $r;
         });
         return false === $results->last() ? false : true;
         // result must be BOOLEAN false (not "", null or 0)
     }
     return false;
 }
 public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null)
 {
     $preCheck = $this->preAssert($acl, $role, $resource, $privilege);
     if (is_bool($preCheck)) {
         return $preCheck;
     }
     $event = new AssertionEvent(null, $this);
     $event->setAcl($acl)->setRole($role)->setResource($resource)->setPrivilege($privilege);
     $events = $this->getEventManager();
     $results = $events->trigger($event, function ($r) {
         return false === $r;
     });
     return false === $results->last() ? false : true;
     // result must be BOOLEAN false (not "", null or 0 or any other value evaluated to FALSE)
 }
 /**
  * Checks if the user may create jobs according to the organization permissions.
  *
  * @param AssertionEvent $e
  *
  * @return bool
  */
 public function checkCreatePermission(AssertionEvent $e)
 {
     /* @var $role \Auth\Entity\User
      * @var $organization \Organizations\Entity\OrganizationReference
      */
     $role = $e->getRole();
     if (!$role instanceof UserInterface) {
         return false;
     }
     $organization = $role->getOrganization();
     if (!$organization->hasAssociation() || $organization->isOwner()) {
         return true;
     }
     $employees = $organization->getEmployees();
     foreach ($employees as $emp) {
         /* @var $emp \Organizations\Entity\EmployeeInterface */
         if ($emp->getUser()->getId() == $role->getId() && $emp->getPermissions()->isAllowed(EmployeePermissionsInterface::JOBS_CREATE)) {
             return true;
         }
     }
     return false;
 }
 /**
  * Gets an Assertion event seeded with Mock objects.
  *
  * @param bool $isOneEmployeeAllowed if true, one employee in the employees collection gets job create permissions.
  *
  * @return AssertionEvent
  */
 protected function getTestEvent($isOneEmployeeAllowed = true)
 {
     $employees = new ArrayCollection();
     for ($i = 0; $i < 3; $i++) {
         $empUser = new User();
         $empUser->setId('1234-' . $i);
         $perm = new EmployeePermissions(EmployeePermissionsInterface::JOBS_VIEW);
         if (2 == $i && $isOneEmployeeAllowed) {
             $perm->grant(EmployeePermissionsInterface::JOBS_CREATE);
         }
         $emp = new Employee($empUser, $perm);
         $employees->add($emp);
     }
     $org = $this->getMockBuilder('\\Organizations\\Entity\\OrganizationReference')->disableOriginalConstructor()->getMock();
     $org->expects($this->once())->method('hasAssociation')->willReturn(true);
     $org->expects($this->once())->method('isOwner')->willReturn(false);
     $org->expects($this->once())->method('getEmployees')->willReturn($employees);
     $role = new User();
     $role->setId('1234-2');
     $role->setOrganization($org);
     $e = new AssertionEvent();
     $e->setRole($role);
     return $e;
 }
 public function testDefaultEventName()
 {
     $target = new AssertionEvent();
     $this->assertEquals('assert', AssertionEvent::EVENT_ASSERT);
     $this->assertEquals(AssertionEvent::EVENT_ASSERT, $target->getName());
 }