From: skodak Date: Mon, 12 May 2008 14:05:46 +0000 (+0000) Subject: MDL-14183 guest type role not allowed in defaultuserroleid anymore, because it was... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=ab37dc6031d13770e614e7d86d50446a11d7dde1;p=moodle.git MDL-14183 guest type role not allowed in defaultuserroleid anymore, because it was causing trouble in many places; admins must choose another role if guest role detected in this setting; merged from MOODLE_19_STABLE --- diff --git a/admin/settings/users.php b/admin/settings/users.php index 9922d0b5cf..c15caf6f0b 100644 --- a/admin/settings/users.php +++ b/admin/settings/users.php @@ -108,13 +108,21 @@ if ($hassiteconfig set_config('creatornewroleid', 0); } } + if (!$guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) { + $guestroles = array(); + } // we must not use assignable roles here: // 1/ unsetting roles as assignable for admin might bork the settings! // 2/ default user role should not be assignable anyway $allroles = array(); + $nonguestroles = array(); if ($roles = get_all_roles()) { foreach ($roles as $role) { - $allroles[$role->id] = strip_tags(format_string($role->name, true)); + $rolename = strip_tags(format_string($role->name, true)); + $allroles[$role->id] = $rolename; + if (!isset($guestroles[$role->id])) { + $nonguestroles[$role->id] = $rolename; + } } } @@ -123,7 +131,7 @@ if ($hassiteconfig $temp->add(new admin_setting_configselect('guestroleid', get_string('guestroleid', 'admin'), get_string('configguestroleid', 'admin'), $guestrole->id, $allroles)); $temp->add(new admin_setting_configselect('defaultuserroleid', get_string('defaultuserroleid', 'admin'), - get_string('configdefaultuserroleid', 'admin'), $userrole->id, $allroles)); + get_string('configdefaultuserroleid', 'admin'), $userrole->id, $nonguestroles)); // guest role here breaks a lot of stuff } $temp->add(new admin_setting_configcheckbox('nodefaultuserrolelists', get_string('nodefaultuserrolelists', 'admin'), get_string('confignodefaultuserrolelists', 'admin'), 0)); diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 985975d52e..1531197e2c 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -68,6 +68,22 @@ function xmldb_main_upgrade($oldversion=0) { upgrade_main_savepoint($result, 2008050700); } + if ($result && $oldversion < 2008051200) { + // if guest role used as default user role unset it and force admin to choose new setting + if (!empty($CFG->defaultuserroleid)) { + if ($role = get_record('role', 'id', $CFG->defaultuserroleid)) { + if ($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) { + if (isset($guestroles[$role->id])) { + set_config('defaultuserroleid', null); + notify('Guest role removed from "Default role for all users" setting, please select another role.', 'notifysuccess'); + } + } + } else { + set_config('defaultuserroleid', null); + } + } + } + return $result; } diff --git a/version.php b/version.php index 1906cbb92c..c8f7335c2c 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2008050700; // YYYYMMDD = date of the last version bump + $version = 2008051200; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20080512)'; // Human-friendly version name