mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
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:
parent
35d5053ba2
commit
57b81c93f5
45
blocks/navigation/tests/behat/participants_link.feature
Normal file
45
blocks/navigation/tests/behat/participants_link.feature
Normal file
@ -0,0 +1,45 @@
|
||||
@block @block_navigation
|
||||
Feature: Displaying the link to the Participants page
|
||||
In order to see the course / site participants
|
||||
As a student / admin respectively
|
||||
I need a link to the Participants page be displayed (but only if I can access that page)
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| student1 | Student | One | student1@example.com |
|
||||
| student2 | Student | Two | student2@example.com |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname |
|
||||
| Course1 | C1 |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| student1 | C1 | student |
|
||||
|
||||
@javascript
|
||||
Scenario: Course participants link is displayed to enrolled students after expanding the course node
|
||||
When I log in as "student1"
|
||||
And I expand "C1" node
|
||||
Then "Participants" "link" should exist in the "Navigation" "block"
|
||||
And I navigate to "Participants" node in "My courses > C1"
|
||||
And I should see "Participants"
|
||||
And "Student One" "link" should exist
|
||||
And "Student Two" "link" should not exist
|
||||
|
||||
Scenario: Site participants link is displayed to admins
|
||||
When I log in as "admin"
|
||||
Then "Participants" "link" should exist in the "Navigation" "block"
|
||||
And I navigate to "Participants" node in "Site pages"
|
||||
And I should see "Participants"
|
||||
And "Student One" "link" should exist
|
||||
And "Student Two" "link" should exist
|
||||
|
||||
@javascript
|
||||
Scenario: Site participants link is not displayed to students (MDL-55667)
|
||||
Given I log in as "admin"
|
||||
And I set the following administration settings values:
|
||||
| defaultfrontpageroleid | Student (student) |
|
||||
And I log out
|
||||
When I log in as "student2"
|
||||
And I expand "Site pages" node
|
||||
Then "Participants" "link" should not exist in the "Navigation" "block"
|
@ -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');
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user