1 views_handler_filter_user_permissions.inc views_handler_filter_user_permissions::query()

Add this filter to the query.

Due to the nature of fapi, the value and the operator have an unintended level of indirection. You will find them in $this->operator and $this->value respectively.

Overrides views_handler_filter_in_operator::query

File

core/modules/user/views/views_handler_filter_user_permissions.inc, line 14
Definition of views_handler_filter_user_permissions.

Class

views_handler_filter_user_permissions
Filter handler for user roles.

Code

function query() {
  // Convert the permission name to a list of roles that include the permission.
  $all_roles = user_roles(TRUE, NULL, TRUE);

  // If the authenticated user has this permission, no additional filtering.
  $needed_permissions = array_values(array_filter($this->value));
  $needed_count = count($needed_permissions);

  $roles_with_permissions = array();
  foreach ($all_roles as $role) {
    $matching_count = count(array_intersect($needed_permissions, $role->permissions));
    if (($this->operator !== 'and' && $matching_count) || ($this->operator === 'and' && $matching_count === $needed_count)) {
      $roles_with_permissions[] = $role->name;
    }
  }

  // The authenticated role is not in the users_roles table, so if it has the
  // permissions, special actions need to be taken.
  if (in_array(BACKDROP_AUTHENTICATED_ROLE, $roles_with_permissions)) {
    if ($this->operator === 'not') {
      // Block the display of any users at all.
      // @todo: Use a more graceful way to eliminate the query.
      $this->operator = 'and';
      $this->value = array('*NO_ROLES*');
    }
    else {
      // No action at all necessary to list all users.
      return;
    }
  }
  // Otherwise, join and search on roles as normal.
  else {
    $this->value = $roles_with_permissions;
  }

  parent::query();
}