MDL-65354 core: replace all usages of old cap

This commit is contained in:
Simey Lameze 2019-04-15 12:03:53 +08:00
parent d26749b74c
commit 3bc573501a
2 changed files with 8 additions and 8 deletions

View File

@ -304,7 +304,7 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr
}
if (count($children) > 1) {
// User has access to more than one category on the top level. Return the top as "user top category".
// In this case user actually may not have capability 'moodle/course:browse' on the top level.
// In this case user actually may not have capability 'moodle/category:viewcourselist' on the top level.
return self::top();
}
// User can not access any categories on the top level.
@ -653,13 +653,13 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr
*/
public static function can_view_category($category, $user = null) {
if (!$category->id) {
return has_capability('moodle/course:browse', context_system::instance(), $user);
return has_capability('moodle/category:viewcourselist', context_system::instance(), $user);
}
$context = context_coursecat::instance($category->id);
if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', $context, $user)) {
return false;
}
return has_capability('moodle/course:browse', $context, $user);
return has_capability('moodle/category:viewcourselist', $context, $user);
}
/**
@ -682,7 +682,7 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr
}
$categorycontext = isset($course->category) ? context_coursecat::instance($course->category) :
context_course::instance($course->id)->get_parent_context();
return has_capability('moodle/course:browse', $categorycontext, $user);
return has_capability('moodle/category:viewcourselist', $categorycontext, $user);
}
/**
@ -1088,7 +1088,7 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr
* @param array $params
* @param array $options may indicate that summary needs to be retrieved
* @param bool $checkvisibility if true, capability 'moodle/course:viewhiddencourses' will be checked
* on not visible courses and 'moodle/course:browse' on all courses
* on not visible courses and 'moodle/category:viewcourselist' on all courses
* @return array array of stdClass objects
*/
protected static function get_course_records($whereclause, $params, $options, $checkvisibility = false) {

View File

@ -28,13 +28,13 @@ Feature: Restricting access to course lists
Given I log in as "admin"
And I set the following system permissions of "Authenticated user" role:
| capability | permission |
| moodle/course:browse | Prevent |
| moodle/category:viewcourselist | Prevent |
And I set the following system permissions of "Guest" role:
| capability | permission |
| moodle/course:browse | Prevent |
| moodle/category:viewcourselist | Prevent |
And I set the following system permissions of "Category viewer" role:
| capability | permission |
| moodle/course:browse | Allow |
| moodle/category:viewcourselist | Allow |
And I am on site homepage
And I turn editing mode on
And I add the "Navigation" block if not present