returns true if user is authenticated and has all the passed rights on the base
todo : wtf $rights is an array since it's never called with more than 1 right in it ?

@param $baseId
@param array $rights
@return bool
@throws \Exception
184517
public function isGrantedOnCollection($baseId, Array $rights)
    {
        if (false === ($this->app->getAuthenticatedUser() instanceof User)) {

            return false;
        }

        $acl = $this->app->getAclForUser($this->app->getAuthenticatedUser());
        foreach ($rights as $right) {
            if (! $acl->has_right_on_base($baseId, $right)) {

                return false;
            }
        }

        return true;
    }
1283016
public function hasAllPermissions($permission)
    {
        foreach ($this->getArrayFrom($permission) as $permission) {
            if (!$this->checkPermission($permission)) {
                return false;
            }
        }

        return true;
    }
518582
public function isAuthorised()
    {

        if (is_array($this->user) === true
            && isset($this->user['error']) === false
        ) {

            return true;
        }

        return $this->getUser();
    }
1205383
public function hasPermission($permission, $force = false)
    {
        $permissions = $this->getAllPermissions($force)->pluck('name')->toArray();

        if (strpos($permission, '*')) {
            $permission = substr($permission, 0, -2);

            return (bool) preg_grep('~'.$permission.'~', $permissions);
        }

        return in_array($permission, $permissions);
    }
615219
public function checkAccess($user_id, $roles)
    {
        if ($this->isRoot($user_id)) {
            return true;
        }
        if (is_array($roles)) {
            return $this->hasRoles($user_id, $roles);
        } elseif (strpos($roles, '|') !== false) {
            return $this->hasAnyRole($user_id, explode('|', $roles));
        } else {
            return $this->hasRoles($user_id, explode('&', $roles));
        }
    }
909799
public function check($abilities, $arguments = [])
    {
        return collect($abilities)->every(function ($ability) use ($arguments) {
            try {
                return (bool) $this->raw($ability, $arguments);
            } catch (AuthorizationException $e) {
                return false;
            }
        });
    }
1236426
public function hasAnyOfThisRights($rights)
    {
        foreach ($rights as $right)
            if ($this->hasRight($right))
                return true;
        return false;
    }
579345
public function isGranted($permission, Array $params = null)
    {
        if ($this->checkPermissionCurrent($permission, $params)) {
            return true;
        }

        if ($this->checkPermissionRecursive($permission, $params)) {
            return true;
        }

        return false;
    }
309543
public static function hasAccessInCapabilities(string $capability, string $userId): bool
    {
        $userCaps = static::fetchUserCapabilities($userId);
        if (in_array($capability, $userCaps)) {
            return true;
        }

        return false;
    }
185104
public function check($ability, $arguments = array())
    {
        if (! is_array($arguments)) {
            $arguments = array_slice(func_get_args(), 1);
        }

        try {
            $result = $this->raw($ability, $arguments);
        }
        catch (AuthorizationException $e) {
            return false;
        }

        return (bool) $result;
    }
938036
public function has($id, $permission, $all = true)
    {
        if (! $user = $this->findUserById($id)) {
            return false;
        }

        return $user->has($permission, $all);
}
217498
public function checkUserExist($userId, $conversationId)
    {
        $thread = $this->find($conversationId);

        if ($thread) {
            if (($thread->first_user_id == $userId) || ($thread->second_user_id == $userId)) {
                return true;
            }
        }

        return false;
    }
139111
public function hasAny(array $permissions, bool $need_affiliation = true): bool
    {

        foreach ($permissions as $permission)
            if ($this->has($permission, $need_affiliation))
                return true;

        return false;
    }
1004316
private function isAuthorized() {

        /**
         * Use $permitted to insert name of pages that do not require authentication
         */
        $permitted = ['login', 'logout'];
        if (isset($this->request->pass[0]))
            if (in_array($this->request->pass[0], $permitted))
                return TRUE;

        /**
         * Check if the user is authenticated
         */
        if ($this->request->session()->check('User.id'))
            return TRUE;

        /**
         * Default rule
         */
        return TRUE;
    }
722511
protected function checkAllowBypass(array $permissions, $context, $allowBypass) {
    if(!$allowBypass) {
      return $allowBypass;
    }

    if(!array_key_exists('NO_BYPASS', $permissions)) {
      return $allowBypass;
    }

    if(is_bool($permissions['NO_BYPASS'])) {
      return !$permissions['NO_BYPASS'];
    }

    if(is_string($permissions['NO_BYPASS'])) {
      $noBypassUpper = strtoupper($permissions['NO_BYPASS']);
      if(!in_array($noBypassUpper, array('TRUE', 'FALSE'))) {
        throw new InvalidArgumentValueException('The NO_BYPASS value must be a boolean, a boolean string or an array. Current value: ' . print_r($permissions['NO_BYPASS'], TRUE));
      }

      if('TRUE' === $noBypassUpper) {
        return FALSE;
      }
      if('FALSE' === $noBypassUpper) {
        return TRUE;
      }
    }

    if(is_array($permissions['NO_BYPASS'])) {
      return !$this->processOR($permissions['NO_BYPASS'], NULL, $context);
    }

    throw new InvalidArgumentValueException('The NO_BYPASS value must be a boolean, a boolean string or an array. Current value: ' . print_r($permissions['NO_BYPASS'], TRUE));
  }
254351
public function doAuth (string $userId, string $passwd)
    {

        if(($user = $this->userProvider->validateUser($userId, $passwd, $this->roleMap)) !== null) {
            $this->authUser = $user;
            if ($this->authMech instanceof SessionBasedAuthMech)
                $this->authMech->setSessionUserId($userId);
            return true;
        }

        throw new InvalidUserException("Cannot login user '$userId'");
    }
245795
public function hasPermissions($permissions)
    {
        if ($this->user() === null) {
            return null;
        }

        if (!is_array($permissions)) {
            $permissions = func_get_args();
        }

        // Count permissions because user need user to have all permissions passed as parameter
        return count(array_intersect($permissions, $this->permissions)) === count($permissions);
    }