MDL-7513 Further tweak to the way defaultuser role works to unbreak one possible situation that my previous change just broke

This commit is contained in:
sam_marshall 2006-11-15 14:23:43 +00:00
parent 39dee8f200
commit 40d8670956

View File

@ -129,15 +129,26 @@ function load_defaultuser_role() {
if ($capabilities = get_records_select('role_capabilities',
"roleid = $CFG->defaultuserroleid AND contextid = $sitecontext->id AND permission <> 0")) {
// Find out if this default role is a guest role, for the hack below
$defaultisguestrole=false;
foreach ($capabilities as $capability) {
if($capability->capability=='moodle/legacy:guest') {
$defaultisguestrole=true;
}
}
foreach ($capabilities as $capability) {
// If the default role is a guest role, then don't copy legacy:guest,
// otherwise this user could get confused with a REAL guest. Also don't copy
// course:view, which is a hack that's necessary because guest roles are
// not really handled properly (see MDL-7513)
if($defaultisguestrole && $USER->username!='guest' &&
($capability->capability=='moodle/legacy:guest' ||
$capability->capability=='moodle/course:view')) {
continue;
}
// Don't overwrite capabilities from real role...
if (!isset($USER->capabilities[$sitecontext->id][$capability->capability])
// ...and if the default role is a guest role, then don't copy legacy:guest,
// otherwise this user could get confused with a REAL guest. Also don't copy
// course:view, which is a hack that's necessary because guest roles are
// not really handled properly (see MDL-7513)
&& (($capability->capability!='moodle/legacy:guest'
&& $capability->capability!='moodle/course:view') || $USER->username=='guest')) {
if (!isset($USER->capabilities[$sitecontext->id][$capability->capability])) {
$USER->capabilities[$sitecontext->id][$capability->capability] = $capability->permission;
}
}