From 9a4d2c5083bc954ba42e09664386b4ced89ef950 Mon Sep 17 00:00:00 2001 From: Stefan Hanauska Date: Sun, 9 Mar 2025 09:47:51 +0100 Subject: [PATCH] MDL-84780 course: Disabled modules are not allowed --- public/course/lib.php | 4 ++++ public/course/tests/courselib_test.php | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/public/course/lib.php b/public/course/lib.php index e16c58a38d6..0cbb5d39bff 100644 --- a/public/course/lib.php +++ b/public/course/lib.php @@ -1483,6 +1483,10 @@ function course_allowed_module($course, $modname, ?\stdClass $user = null) { supports numeric module ids. Please update your code to pass the module name.'); } + if (!\core\plugininfo\mod::get_enabled_plugin($modname)) { + return false; + } + $capability = 'mod/' . $modname . ':addinstance'; if (!get_capability_info($capability)) { // Debug warning that the capability does not exist, but no more than once per page. diff --git a/public/course/tests/courselib_test.php b/public/course/tests/courselib_test.php index 3a33ed7a935..de3688626a1 100644 --- a/public/course/tests/courselib_test.php +++ b/public/course/tests/courselib_test.php @@ -7035,6 +7035,12 @@ final class courselib_test extends advanced_testcase { // Manager has permissions. $this->assertTrue(course_allowed_module($course, 'assign', $manager)); + + // Disable the assign module. + $DB->set_field('modules', 'visible', 0, ['name' => 'assign']); + + // Verify that disabled modules are not allowed. + $this->assertFalse(course_allowed_module($course, 'assign', $manager)); } /**