MDL-55667 navigation: Do not display site participants link to students

The problem here was that user/index.php checks the system level
capability moodle/site:viewparticipants when the user is on the front
page, and the moodle/course:viewparticipants on non-front pages.

But the navigation displayed the link by mistake even in situations,
when the user has the capability moodle/course:viewparticipants on the
front page (typically when the default role for the front page is set to
student).

Added behat tests for reproducing the bug and also for checking the
basic functionality of the feature.
This commit is contained in:
David Mudrák
2016-08-29 12:11:59 +02:00
parent 95839d65c7
commit afb949e087
2 changed files with 48 additions and 2 deletions
+3 -2
View File
@@ -2600,6 +2600,7 @@ class global_navigation extends navigation_node {
}
$sitecontext = context_system::instance();
$isfrontpage = ($course->id == SITEID);
// Hidden node that we use to determine if the front page navigation is loaded.
// This required as there are not other guaranteed nodes that may be loaded.
@@ -2608,8 +2609,8 @@ class global_navigation extends navigation_node {
// Participants.
// If this is the site course, they need to have moodle/site:viewparticipants at the site level.
// If no, then they need to have moodle/course:viewparticipants at the course level.
if ((($course->id == SITEID) && has_capability('moodle/site:viewparticipants', $sitecontext)) ||
has_capability('moodle/course:viewparticipants', context_course::instance($course->id))) {
if (($isfrontpage && has_capability('moodle/site:viewparticipants', $sitecontext)) ||
(!$isfrontpage && has_capability('moodle/course:viewparticipants', context_course::instance($course->id)))) {
$coursenode->add(get_string('participants'), new moodle_url('/user/index.php?id='.$course->id), self::TYPE_CUSTOM, get_string('participants'), 'participants');
}