MDL-57512 categories: Use maxcategorydepth only when getting all cats

This commit is contained in:
Pau Ferrer Ocaña 2016-12-22 12:59:55 +01:00
parent c4cf1c60f5
commit 7180cdc7b5
2 changed files with 12 additions and 7 deletions

View File

@ -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 {

View File

@ -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),