You are here

function opigno_module_entity_access in Opigno module 3.x

Same name and namespace in other branches
  1. 8 opigno_module.module \opigno_module_entity_access()

Implements hook_entity_access().

File

./opigno_module.module, line 1142
Contains opigno_module.module.

Code

function opigno_module_entity_access(EntityInterface $entity, $operation, AccountInterface $account) {
  if ($entity
    ->getEntityTypeId() == 'file' && $operation == 'download') {
    $user_is_manager = LearningPathAccess::memberHasRole('user_manager', $account);
    if ($user_is_manager || $account
      ->id() == $entity
      ->get('uid')
      ->getString()) {
      return AccessResult::allowed();
    }
  }
  if ($entity
    ->getEntityTypeId() == 'user_module_status') {
    if ($entity
      ->getOwnerId() == $account
      ->id()) {
      return AccessResultAllowed::allowedIf((int) $account
        ->id() === 0)
        ->mergeCacheMaxAge(0);
    }
  }
}