When a rule is added to an access filter that contains an IP range, the following error is thrown:
Error: Call to a member function isAllowed() on boolean in Drupal\access_filter\Entity\Filter->isAllowed() (line 213 of /docroot/modules/contrib/access_filter/src/Entity/Filter.php)

Example of a rule where this error is thrown:
Example of a rule with an IP range

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

edwardchiapet created an issue. See original summary.

edwardchiapet’s picture

It looks like the error is thrown because a boolean is returned in the condition that handles the IP ranges:

// Check as 2 IP address range format.
      $patterns = explode('-', $pattern);
      if (isset($patterns[1])) {
        return ($ip_long >= ip2long($patterns[0]) && $ip_long <= ip2long($patterns[1]));
      }

The `isAllowed()` method in `Filter.php` expects an `AccessResult` object in:

$result = $rule->check($request);
      if ($result->isAllowed()) {
        $is_allowed = TRUE;
      }

Attached is a patch that updates the return statement to return `AccessResult::allowed()` is the check passes and `AccessResult::forbidden()` if it fails.

edwardchiapet’s picture

Assigned: edwardchiapet » Unassigned
Status: Active » Needs review
wstocker’s picture

Status: Needs review » Reviewed & tested by the community

Reviewed and tested using Drupal core version 8.8.1. The error has been fixed, and IP ranges are working.

  • hayashi committed 48b9553 on 8.x-1.x authored by edwardchiapet
    Issue #3092308 by edwardchiapet, wstocker: An error is thrown when a...
hayashi’s picture

Thank you for reporting issue and fixing it.
8.x-1.2 has been released with this fix.

hayashi’s picture

Status: Reviewed & tested by the community » Fixed
hayashi’s picture

Status: Fixed » Closed (fixed)