From ed08a4ee5226fa45f38b30aa5b0bf75c34731dde Mon Sep 17 00:00:00 2001 From: Laurent David Date: Tue, 28 Feb 2023 13:46:22 +0100 Subject: [PATCH] MDL-76940 core_courseformat: Index refreshing when role switch * Hidden sections and content should not visible to students when switching role --- course/format/tests/behat/course_courseindex.feature | 11 +++++++++++ lib/accesslib.php | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/course/format/tests/behat/course_courseindex.feature b/course/format/tests/behat/course_courseindex.feature index acbf7591d2d..a8d988e57ea 100644 --- a/course/format/tests/behat/course_courseindex.feature +++ b/course/format/tests/behat/course_courseindex.feature @@ -297,3 +297,14 @@ Feature: Course index depending on role | large | be | Close | not be | Open | be | | tablet | not be | Open | not be | Open | not be | | mobile | not be | Open | not be | Open | not be | + + @javascript + Scenario: Course index is refreshed when we change role. + When I am on the "C1" "Course" page logged in as "teacher1" + And I turn editing mode on + And I hide section "1" + And I turn editing mode off + And I should see "Topic 1" in the "courseindex-content" "region" + And I follow "Switch role to..." in the user menu + And I press "Student" + Then I should not see "Topic 1" in the "courseindex-content" "region" diff --git a/lib/accesslib.php b/lib/accesslib.php index ff6b39ee747..cacfc2f16bc 100644 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -4344,6 +4344,11 @@ function role_switch($roleid, context $context) { load_all_capabilities(); } + // Make sure that course index is refreshed. + if ($coursecontext = $context->get_course_context()) { + core_courseformat\base::session_cache_reset(get_course($coursecontext->instanceid)); + } + // Add the switch RA if ($roleid == 0) { unset($USER->access['rsw'][$context->path]);