You are here

public function ContentHubUiAccess::access in Acquia Content Hub 8.2

Provides access to Content Hub UI.

Only grants access to logged in users with 'Administer Acquia Content Hub' permission and a valid client. While this looks similar to ContentHubAccess it uses opposite logic.

Parameters

\Drupal\Core\Session\AccountInterface $account: Run access checks for this account.

Return value

\Drupal\Core\Access\AccessResultAllowed|\Drupal\Core\Access\AccessResultForbidden TRUE if granted access; FALSE otherwise.

Throws

\Drupal\acquia_contenthub\Exception\ContentHubException

File

src/Access/ContentHubUiAccess.php, line 58

Class

ContentHubUiAccess
Implements permission to prevent unauthorized access to webhooks.

Namespace

Drupal\acquia_contenthub\Access

Code

public function access(AccountInterface $account) {

  // Check permissions and combine that with any custom access checking
  // needed. Pass forward parameters from the route and/or request as needed.
  $access_result = AccessResult::forbidden();
  if ($account
    ->hasPermission('administer acquia content hub')) {

    // If this is a logged in user with 'Administer Acquia Content Hub'
    // permission then grant access.
    if (!$this->clientFactory
      ->getClient()) {
      $this->loggerFactory
        ->get('acquia_contenthub')
        ->debug('Access denied: Acquia Content Hub Client not connected.');
      $access_result
        ->setReason('Acquia Content Hub Client not connected.');
    }
    else {
      $access_result = AccessResult::allowed();
    }
  }
  $access_result
    ->addCacheTags([
    'acquia_contenthub_settings',
  ]);
  return $access_result;
}