mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-17502 accesslib: added warning if incorrect parameters supplied to has_all_capabilities() and fixed parameters in course lib code
This commit is contained in:
parent
18af228bf2
commit
3ce50127b9
2 changed files with 12 additions and 4 deletions
|
@ -1789,11 +1789,15 @@ function make_categories_list(&$list, &$parents, $requiredcapability = '',
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add this category to $list, if the permissions check out.
|
// Add this category to $list, if the permissions check out.
|
||||||
if ($requiredcapability) {
|
if (empty($requiredcapability)) {
|
||||||
ensure_context_subobj_present($category, CONTEXT_COURSECAT);
|
|
||||||
}
|
|
||||||
if (!$requiredcapability || has_all_capabilities($requiredcapability, $category->context)) {
|
|
||||||
$list[$category->id] = $path;
|
$list[$category->id] = $path;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ensure_context_subobj_present($category, CONTEXT_COURSECAT);
|
||||||
|
$requiredcapability = (array)$requiredcapability;
|
||||||
|
if (has_all_capabilities($requiredcapability, $category->context)) {
|
||||||
|
$list[$category->id] = $path;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -512,6 +512,10 @@ function has_any_capability($capabilities, $context, $userid=NULL, $doanything=t
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function has_all_capabilities($capabilities, $context, $userid=NULL, $doanything=true) {
|
function has_all_capabilities($capabilities, $context, $userid=NULL, $doanything=true) {
|
||||||
|
if (!is_array($capabilities)) {
|
||||||
|
debugging('Incorrect $capabilities parameter in has_all_capabilities() call - must be an array');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
foreach ($capabilities as $capability) {
|
foreach ($capabilities as $capability) {
|
||||||
if (!has_capability($capability, $context, $userid, $doanything)) {
|
if (!has_capability($capability, $context, $userid, $doanything)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue