From 053785ff5fea13daf2feb8ca64d2df8cac079eb8 Mon Sep 17 00:00:00 2001 From: Ilya Tregubov Date: Tue, 15 Mar 2022 16:08:51 +0600 Subject: [PATCH] MDL-74205 navigation: Don't show participants link to user if he has no permission. --- .../tests/behat/participants_link.feature | 29 +++++++++++++++++++ lib/navigationlib.php | 4 +-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/blocks/navigation/tests/behat/participants_link.feature b/blocks/navigation/tests/behat/participants_link.feature index f08ce38d867..a66edbcdd0c 100644 --- a/blocks/navigation/tests/behat/participants_link.feature +++ b/blocks/navigation/tests/behat/participants_link.feature @@ -37,6 +37,35 @@ Feature: Displaying the link to the Participants page And "Student One" "link" should exist And "Student Two" "link" should not exist + @javascript + Scenario: Course participants link is displayed to users depending on role permissions settings + And I log in as "admin" + And I am on "Course1" course homepage with editing mode on + And I add a "Forum" to section "1" and I fill the form with: + | Forum name | Test forum name | + | Description | Test forum description | + And I am on the "Course1" "enrolment methods" page + And I click on "Edit" "link" in the "Guest access" "table_row" + And I set the following fields to these values: + | Allow guest access | Yes | + And I press "Save changes" + And I log out + When I log in as "guest" + And I am on "Course1" course homepage + Then I should not see "Participants" in the "Navigation" "block" + And I am on the "Test forum name" "forum activity" page + And I should not see "Participants" in the "Navigation" "block" + And I log out + And I log in as "admin" + And I set the following system permissions of "Guest" role: + | capability | permission | + | moodle/course:viewparticipants | Allow | + And I log in as "guest" + And I am on "Course1" course homepage + And I should see "Participants" in the "Navigation" "block" + And I am on the "Test forum name" "forum activity" page + And I should see "Participants" in the "Navigation" "block" + Scenario: Site participants link is displayed to admins When I log in as "admin" Then "Participants" "link" should exist in the "Navigation" "block" diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 6140cf90d65..b27722301e3 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -2939,8 +2939,8 @@ class global_navigation extends navigation_node { if ($navoptions->notes) { $participants->add(get_string('notes', 'notes'), new moodle_url('/notes/index.php', array('filtertype' => 'course', 'filterselect' => $course->id)), self::TYPE_SETTING, null, 'currentcoursenotes'); } - } else if (count($this->extendforuser) > 0 || $this->page->course->id == $course->id) { - $participants = $coursenode->add(get_string('participants'), null, self::TYPE_CONTAINER, get_string('participants'), 'participants'); + } else if (count($this->extendforuser) > 0) { + $coursenode->add(get_string('participants'), null, self::TYPE_CONTAINER, get_string('participants'), 'participants'); } // Badges.