From 420bfab1564672cbe0158472a58b995b49d087ba Mon Sep 17 00:00:00 2001 From: martinlanghoff Date: Wed, 19 Sep 2007 07:26:02 +0000 Subject: [PATCH] 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 ;-) --- lib/accesslib.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/accesslib.php b/lib/accesslib.php index f38e580027..789c51b7eb 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -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); } -- 2.39.5