You are here

protected function CourseAccessControlHandler::checkAccess in Course 3.x

Same name and namespace in other branches
  1. 8.3 src/Access/CourseAccessControlHandler.php \Drupal\course\Access\CourseAccessControlHandler::checkAccess()
  2. 8.2 src/Access/CourseAccessControlHandler.php \Drupal\course\Access\CourseAccessControlHandler::checkAccess()

Grant access to reports.

File

src/Access/CourseAccessControlHandler.php, line 31

Class

CourseAccessControlHandler
Access controller for the Course entity.

Namespace

Drupal\course\Access

Code

protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
  if ($operation == 'report') {
    if ($account
      ->hasPermission('access all course reports')) {

      // If user has this permission then allow access without being able to
      // update.
      return AccessResultAllowed::allowed();
    }
    else {

      // Otherwise, check if the user can update this course.
      return parent::checkAccess($entity, 'update', $account);
    }
  }
  return parent::checkAccess($entity, $operation, $account);
}