示例#1
0
 /**
  * Check if the given User has permission to do action on this objects assigned model
  *
  * @param UserInterface $object
  * @param string $action
  * @return boolean
  */
 public function checkPermission(CanInterface $object, $action)
 {
     $has_permission = false;
     $container_name = $this->getEntity()->getTable();
     $row_id = $this->getEntity()->getKey();
     $permission_field = new PermissionField();
     $permission_field->setContainer($container_name);
     $permission_field->setAction($action);
     $permission_field->setRow($row_id);
     $roles = $this->repository->allByUserId($object->getAuthIdentifier());
     foreach ($roles as $role) {
         $result = $role->testPermission($permission_field);
         if ($result > 0) {
             $has_permission = true;
             if ($result >= 5) {
                 break;
             }
         }
         if ($result < 0) {
             $has_permission = false;
             if ($result <= -5) {
                 break;
             }
         }
     }
     return $has_permission;
 }