diff --git a/course/externallib.php b/course/externallib.php index 32214693cbe..d19a5dfc765 100644 --- a/course/externallib.php +++ b/course/externallib.php @@ -1644,12 +1644,6 @@ class core_course_external extends external_api { } } - // Check category depth is <= maxdepth (do not check for user who can manage categories). - if ((!empty($CFG->maxcategorydepth) && count($parents) > $CFG->maxcategorydepth) - and !has_capability('moodle/category:manage', $context)) { - $excludedcats[$category->id] = 'depth'; - } - // Check the user can use the category context. $context = context_coursecat::instance($category->id); try { diff --git a/course/tests/externallib_test.php b/course/tests/externallib_test.php index 083e558e795..aebdf878657 100644 --- a/course/tests/externallib_test.php +++ b/course/tests/externallib_test.php @@ -278,8 +278,19 @@ class core_course_externallib_testcase extends externallib_advanced_testcase { $this->assertEquals($DB->count_records('course_categories'), count($categories)); - // Call without required capability (it will fail cause of the search on idnumber). $this->unassignUserCapability('moodle/category:manage', $context->id, $roleid); + + // Ensure maxdepthcategory is 2 and retrieve all categories without category:manage capability. It should retrieve all + // visible categories as well. + set_config('maxcategorydepth', 2); + $categories = core_course_external::get_categories(); + + // We need to execute the return values cleaning process to simulate the web service server. + $categories = external_api::clean_returnvalue(core_course_external::get_categories_returns(), $categories); + + $this->assertEquals($DB->count_records('course_categories', array('visible' => 1)), count($categories)); + + // Call without required capability (it will fail cause of the search on idnumber). $this->expectException('moodle_exception'); $categories = core_course_external::get_categories(array( array('key' => 'id', 'value' => $category1->id),