From: moodler Date: Sun, 3 Sep 2006 08:45:41 +0000 (+0000) Subject: Fices bug when loading another user's capabilities (it would trash your own) X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=dc411d1be004b1e0d1e802aaaaccb945639e5a04;p=moodle.git Fices bug when loading another user's capabilities (it would trash your own) --- diff --git a/lib/accesslib.php b/lib/accesslib.php index 34af2d717e..6810de83b5 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -177,7 +177,7 @@ function has_capability($capability, $context=NULL, $userid=NULL, $doanything='t global $USER, $CONTEXT, $CFG; - if (!isloggedin() && !isset($USER->capabilities)) { + if (empty($userid) && !isloggedin() && !isset($USER->capabilities)) { load_notloggedin_role(); } @@ -383,7 +383,7 @@ function capability_search($capability, $context, $capabilities) { error ('This is an unknown context!'); return false; } - if ($CFG->debug > 15) { + if ($CFG->debug > 7) { notify("Found $capability recursively from context $context->id at level $context->aggregatelevel: $permission", 'notifytiny'); } @@ -410,13 +410,16 @@ function load_user_capability($capability='', $context ='', $userid='') { global $USER, $CFG; - // make sure it's cleaned when loaded (again) - if (!empty($USER->capabilities)) { - unset($USER->capabilities); - } if (empty($userid)) { + if (empty($USER->id)) { // We have no user to get capabilities for + return false; + } + if (!empty($USER->capabilities)) { // make sure it's cleaned when loaded (again) + unset($USER->capabilities); + } $userid = $USER->id; + $otheruserid = false; } else { $otheruserid = $userid; } @@ -1158,6 +1161,11 @@ function role_assign($roleid, $userid, $groupid, $contextid, $timestart=0, $time return false; } + if ($groupid && !record_exists('groups', 'id', $groupid)) { + notify('Group does not exist!'); + return false; + } + if (!$context = get_context_instance_by_id($contextid)) { notify('A valid context must be provided'); return false;