You are here

public function WorkbenchAccessManager::userInAll in Workbench Access 8

Determines if a user is assigned to all sections.

This method checks the permissions and assignments for a user. Someone set as an admin or with access to the top-level sections is assumed to be able to access all sections. We use this logic in query filtering.

Parameters

\Drupal\workbench_access\Entity\AccessSchemeInterface $scheme: Access scheme.

\Drupal\Core\Session\AccountInterface $account: Account being checked.

Return value

bool TRUE if user is in all schemes.

Overrides WorkbenchAccessManagerInterface::userInAll

File

src/WorkbenchAccessManager.php, line 142

Class

WorkbenchAccessManager
Defines a class for interacting with content and fields.

Namespace

Drupal\workbench_access

Code

public function userInAll(AccessSchemeInterface $scheme, AccountInterface $account = NULL) {

  // Get the information from the account.
  if (!$account) {
    $account = $this->currentUser;
  }
  if ($account
    ->hasPermission('bypass workbench access')) {
    return TRUE;
  }
  else {

    // If the user is assigned to all the top-level sections, treat as admin.
    $user_sections = $this->userSectionStorage
      ->getUserSections($scheme, $account);
    foreach (array_keys($scheme
      ->getAccessScheme()
      ->getTree()) as $root) {
      if (!in_array($root, $user_sections)) {
        return FALSE;
      }
    }
  }
  return TRUE;
}