You are here

function opigno_statistics_user_access in Opigno statistics 8

Same name and namespace in other branches
  1. 3.x opigno_statistics.module \opigno_statistics_user_access()

Implements hook_ENTITY_TYPE_access().

File

./opigno_statistics.module, line 123
Contains opigno_statistics.module.

Code

function opigno_statistics_user_access(UserInterface $user, $operation, AccountInterface $account) {
  if ($operation === 'view statistics') {

    // Allow users to view their own profile.
    if ($account
      ->id() === $user
      ->id()) {
      return AccessResult::allowed();
    }
    if ($account
      ->hasPermission('view global statistics') || $account
      ->hasPermission('view any user statistics')) {
      return AccessResult::allowed();
    }
    else {
      return AccessResult::forbidden();
    }
  }
  return AccessResult::neutral();
}