From 8b4568500b305f7ddedbca355b73ce34ea4afbc0 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Tue, 5 May 2015 11:52:14 +0800 Subject: [PATCH] MDL-49788 navigation: Ensure we only check active enrolments --- lib/navigationlib.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 564418674a6..2800def4b35 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -1173,7 +1173,7 @@ class global_navigation extends navigation_node { // course node and not populate it. // Not enrolled, can't view, and hasn't switched roles - if (!can_access_course($course)) { + if (!can_access_course($course, null, '', true)) { if ($coursenode->isexpandable === true) { // Obviously the situation has changed, update the cache and adjust the node. // This occurs if the user access to a course has been revoked (one way or another) after @@ -1189,9 +1189,7 @@ class global_navigation extends navigation_node { $canviewcourseprofile = false; break; } - } - - if ($coursenode->isexpandable === false) { + } else if ($coursenode->isexpandable === false) { // Obviously the situation has changed, update the cache and adjust the node. // This occurs if the user has been granted access to a course (one way or another) after initially // logging in for this session. @@ -1236,7 +1234,7 @@ class global_navigation extends navigation_node { // If the user is not enrolled then we only want to show the // course node and not populate it. - if (!can_access_course($course)) { + if (!can_access_course($course, null, '', true)) { $coursenode->make_active(); $canviewcourseprofile = false; break; @@ -1275,7 +1273,7 @@ class global_navigation extends navigation_node { // If the user is not enrolled then we only want to show the // course node and not populate it. - if (!can_access_course($course)) { + if (!can_access_course($course, null, '', true)) { $coursenode->make_active(); $canviewcourseprofile = false; break; @@ -2328,7 +2326,7 @@ class global_navigation extends navigation_node { $usercoursenode->add(get_string('notes', 'notes'), $url, self::TYPE_SETTING); } - if (can_access_course($usercourse, $user->id)) { + if (can_access_course($usercourse, $user->id, '', true)) { $usercoursenode->add(get_string('entercourse'), new moodle_url('/course/view.php', array('id' => $usercourse->id)), self::TYPE_SETTING, null, null, new pix_icon('i/course', '')); } @@ -2430,6 +2428,7 @@ class global_navigation extends navigation_node { } else if ($coursetype == self::COURSE_CURRENT) { $parent = $this->rootnodes['currentcourse']; $url = new moodle_url('/course/view.php', array('id'=>$course->id)); + $canexpandcourse = $this->can_expand_course($course); } else if ($coursetype == self::COURSE_MY && !$forcegeneric) { if (!empty($CFG->navshowmycoursecategories) && ($parent = $this->rootnodes['mycourses']->find($course->category, self::TYPE_MY_CATEGORY))) { // Nothing to do here the above statement set $parent to the category within mycourses. @@ -2509,7 +2508,7 @@ class global_navigation extends navigation_node { $cache = $this->get_expand_course_cache(); $canexpand = $cache->get($course->id); if ($canexpand === false) { - $canexpand = isloggedin() && can_access_course($course); + $canexpand = isloggedin() && can_access_course($course, null, '', true); $canexpand = (int)$canexpand; $cache->set($course->id, $canexpand); } @@ -2865,7 +2864,7 @@ class global_navigation_for_ajax extends global_navigation { break; case self::TYPE_COURSE : $course = $DB->get_record('course', array('id' => $this->instanceid), '*', MUST_EXIST); - if (!can_access_course($course)) { + if (!can_access_course($course, null, '', true)) { // Thats OK all courses are expandable by default. We don't need to actually expand it we can just // add the course node and break. This leads to an empty node. $this->add_course($course); @@ -3270,7 +3269,7 @@ class navbar extends navigation_node { } // Don't show the 'course' node if enrolled in this course. - if (!is_enrolled(context_course::instance($this->page->course->id))) { + if (!is_enrolled(context_course::instance($this->page->course->id, null, '', true))) { $courses = $this->page->navigation->get('courses'); if (!$courses) { // Courses node may not be present. @@ -4166,7 +4165,7 @@ class settings_navigation extends navigation_node { } } else { $canviewusercourse = has_capability('moodle/user:viewdetails', $coursecontext); - $userisenrolled = is_enrolled($coursecontext, $user->id); + $userisenrolled = is_enrolled($coursecontext, $user->id, '', true); if ((!$canviewusercourse && !$canviewuser) || !$userisenrolled) { return false; }