mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
accesslib: has_capability() now loads sub-course accessdata for $ACCESS
When querying capabilities of non-logged-in users, has_capability() will now load accessdata for the subcontexts as needed. Without this patch, below-the-course RAs and rdefs were ignored when checking caps for a user different from $USER. I don't think it is ever done in current moodle code, so the problem wasn't visible. In any case - it's fixed ;-)
This commit is contained in:
parent
21e2dcd946
commit
420bfab156
1 changed files with 14 additions and 1 deletions
|
@ -363,7 +363,7 @@ function has_capability($capability, $context=NULL, $userid=NULL, $doanything=tr
|
|||
return has_cap_fad($capability, $context,
|
||||
$USER->access, $doanything);
|
||||
}
|
||||
// Load it as needed
|
||||
// Load accessdata for below-the-course contexts
|
||||
if (!path_inaccessdata($context->path,$USER->access)) {
|
||||
error_log("loading access for context {$context->path} for $capability at {$context->contextlevel} {$context->id}");
|
||||
// $bt = debug_backtrace();
|
||||
|
@ -382,6 +382,19 @@ function has_capability($capability, $context=NULL, $userid=NULL, $doanything=tr
|
|||
if (!isset($ACCESS[$userid])) {
|
||||
load_user_accessdata($userid);
|
||||
}
|
||||
if ($context->contextlevel <= CONTEXT_COURSE) {
|
||||
// Course and above are always preloaded
|
||||
return has_cap_fad($capability, $context,
|
||||
$ACCESS[$userid], $doanything);
|
||||
}
|
||||
// Load accessdata for below-the-course contexts as needed
|
||||
if (!path_inaccessdata($context->path,$ACCESS[$userid])) {
|
||||
error_log("loading access for context {$context->path} for $capability at {$context->contextlevel} {$context->id}");
|
||||
// $bt = debug_backtrace();
|
||||
// error_log("bt {$bt[0]['file']} {$bt[0]['line']}");
|
||||
$ACCESS[$userid] = get_user_access_bycontext($userid, $context,
|
||||
$ACCESS[$userid]);
|
||||
}
|
||||
return has_cap_fad($capability, $context,
|
||||
$ACCESS[$userid], $doanything);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue