You are here

protected function ApiDocAccessControlHandler::checkAccess in Apigee API Catalog 8

Same name and namespace in other branches
  1. 8.2 src/Entity/Access/ApiDocAccessControlHandler.php \Drupal\apigee_api_catalog\Entity\Access\ApiDocAccessControlHandler::checkAccess()

Performs access checks.

This method is supposed to be overwritten by extending classes that do their own custom access checking.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for which to check access.

string $operation: The entity operation. Usually one of 'view', 'view label', 'update' or 'delete'.

\Drupal\Core\Session\AccountInterface $account: The user for which to check access.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

Overrides EntityAccessControlHandler::checkAccess

File

src/Entity/Access/ApiDocAccessControlHandler.php, line 73

Class

ApiDocAccessControlHandler
Access controller for the API Doc entity.

Namespace

Drupal\apigee_api_catalog\Entity\Access

Code

protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {

  /** @var \Drupal\apigee_api_catalog\Entity\ApiDocInterface $entity */
  $access = parent::checkAccess($entity, $operation, $account);

  // Access control for revisions.
  if (!$entity
    ->isDefaultRevision()) {
    return $this
      ->checkAccessRevisions($entity, $operation, $account);
  }
  switch ($operation) {
    case 'view':
      return $access
        ->orIf($entity
        ->isPublished() ? AccessResult::allowedIfHasPermission($account, 'view published apidoc entities') : AccessResult::allowedIfHasPermission($account, 'view unpublished apidoc entities'));
    case 'reimport':
      return AccessResult::allowedIf($entity->spec_file_source->value === ApiDocInterface::SPEC_AS_URL)
        ->andIf($entity
        ->access('update', $account, TRUE));
    case 'update':
      return $access
        ->orIf(AccessResult::allowedIfHasPermission($account, 'edit apidoc entities'));
    case 'delete':
      return $access
        ->orIf(AccessResult::allowedIfHasPermission($account, 'delete apidoc entities'));
  }

  // Unknown operation, no opinion.
  return $access;
}