public static function authorizeCourseAccess(GcrMdlCourse $course)
 {
     global $CFG;
     $eschool = $course->getApp();
     $open_access = $eschool->getConfigVar('forcelogin') == 0;
     $visible = $course->isVisible();
     $authorized = false;
     if ($CFG->current_app->hasPrivilege('Student')) {
         $current_user = $CFG->current_app->getCurrentUser();
         if ($current_user->hasAccess($eschool)) {
             $authorized = $CFG->current_app->hasPrivilege('GCStaff');
             if (!$authorized && $CFG->current_app->hasPrivilege('EschoolStaff')) {
                 $authorized = $eschool->getInstitution()->getId() == $CFG->current_app->getInstitution()->getId();
             }
             if (!$authorized) {
                 $authorized = $visible;
                 if (!$authorized) {
                     $mdl_user = $current_user->getUserOnEschool($eschool);
                     $authorized = $mdl_user && $course->isInstructor($mdl_user);
                 }
             }
         }
     } else {
         $authorized = $visible && $open_access;
     }
     return $authorized;
 }