From ce842c81649c5dc3a47d49532e041a22eabe3375 Mon Sep 17 00:00:00 2001 From: prasanna-lmsace <57126778+prasanna-lmsace@users.noreply.github.com> Date: Sat, 25 Jan 2025 16:52:45 +0530 Subject: [PATCH] Bugfix: Dynamic course items not updating properly based on course role assignments. resolves #749 --- CHANGES.md | 3 ++ classes/eventobservers.php | 6 ++++ ...usettings_menuitems_dynamiccourses.feature | 36 +++++++++++++++++++ version.php | 2 +- 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 741e5b36e01..19e5ef839ea 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,9 @@ moodle-theme_boost_union Changes ------- +### Unreleased + +* 2025-01-25 - Bugfix: Fix dynamic course items not updating properly based on course role assignments. resolves #749. ### v4.5-r5 diff --git a/classes/eventobservers.php b/classes/eventobservers.php index 711aefc2d86..13a0b6fe1b3 100644 --- a/classes/eventobservers.php +++ b/classes/eventobservers.php @@ -129,6 +129,8 @@ public static function role_assigned(\core\event\base $event) { // Purge the cached menus for the user with the assigned role. smartmenu_helper::purge_cache_session_roles($event->objectid, $event->relateduserid); + // Purge the related user cache. + smartmenu_helper::set_user_purgecache($event->relateduserid); } /** @@ -144,6 +146,8 @@ public static function role_unassigned(\core\event\base $event) { // Purge the cached menus for the user with the unassigned role. smartmenu_helper::purge_cache_session_roles($event->objectid, $event->relateduserid); + // Purge the related user cache. + smartmenu_helper::set_user_purgecache($event->relateduserid); } /** @@ -159,6 +163,8 @@ public static function role_deleted(\core\event\base $event) { // Purge the cached menus for all users with the deleted role. smartmenu_helper::purge_cache_deleted_roles($event->objectid); + // Purge all the dynamic course items cache. + smartmenu_helper::purge_cache_dynamic_courseitems(); } /** diff --git a/tests/behat/theme_boost_union_smartmenusettings_menuitems_dynamiccourses.feature b/tests/behat/theme_boost_union_smartmenusettings_menuitems_dynamiccourses.feature index 923ffc5f3a5..72ef7ff7768 100644 --- a/tests/behat/theme_boost_union_smartmenusettings_menuitems_dynamiccourses.feature +++ b/tests/behat/theme_boost_union_smartmenusettings_menuitems_dynamiccourses.feature @@ -316,3 +316,39 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, usi | teacher, editingteacher | teacher | should | Course 01 | Inline | smart menu item | | student | student1 | should | Course 01 | Inline | smart menu item | | student | teacher | should not | Course 01 | Inline | smart menu item | + + @javascript + Scenario: Smartmenus: Menu items: Dynamic courses - User role assignments in future courses + Given the following "theme_boost_union > smart menu" exists: + | title | Future Courses Menu | + | location | Main navigation, Menu bar, User menu, Bottom bar | + And the following "theme_boost_union > smart menu item" exists: + | menu | Future Courses Menu | + | title | Future Courses | + | itemtype | Dynamic courses | + | daterange | Future | + | enrolmentrole | student | + And I am logged in as "admin" + And I am on the "Future Courses Menu > Future Courses" "theme_boost_union > smart menu item" page + And the following "courses" exist: + | fullname | shortname | category | enablecompletion | startdate | enddate | + | Future 01 | F1 | CAT1 | 1 | ## +10 days ##| ## +20 days ## | + | Future 02 | F2 | CAT1 | 1 | ## +15 days ##| ## +25 days ## | + And the following "course enrolments" exist: + | user | course | role | + | student1 | F1 | student | + When I log in as "student1" + Then "Future 01" "theme_boost_union > Smart menu item" should exist in the "Future Courses Menu" "theme_boost_union > Main menu smart menu" + And "Future 02" "theme_boost_union > Smart menu item" should not exist in the "Future Courses Menu" "theme_boost_union > Main menu smart menu" + And the following "course enrolments" exist: + | user | course | role | + | student1 | F2 | student | + And I log in as "student1" + And "Future 02" "theme_boost_union > Smart menu item" should exist in the "Future Courses Menu" "theme_boost_union > Main menu smart menu" + Then I am on the "Future 02" "enrolled users" page logged in as "admin" + And I click on "Unenrol" "icon" in the "student1" "table_row" + And I click on "Unenrol" "button" in the "Unenrol" "dialogue" + And I log out + When I log in as "student1" + Then "Future 01" "theme_boost_union > Smart menu item" should exist in the "Future Courses Menu" "theme_boost_union > Main menu smart menu" + And "Future 02" "theme_boost_union > Smart menu item" should not exist in the "Future Courses Menu" "theme_boost_union > Main menu smart menu" diff --git a/version.php b/version.php index 905414bf11e..e7fcc35323d 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'theme_boost_union'; -$plugin->version = 2024100708; +$plugin->version = 2024100709; $plugin->release = 'v4.5-r5'; $plugin->requires = 2024100700; $plugin->supported = [405, 405];