]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14183 guest type role not allowed in defaultuserroleid anymore, because it was...
authorskodak <skodak>
Mon, 12 May 2008 14:05:46 +0000 (14:05 +0000)
committerskodak <skodak>
Mon, 12 May 2008 14:05:46 +0000 (14:05 +0000)
admin/settings/users.php
lib/db/upgrade.php
version.php

index 9922d0b5cf0160a946766aa294d072023cadf0b5..c15caf6f0baa94a95384b2ba96906cd6163824f3 100644 (file)
@@ -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));
index 985975d52ec1788ca031ec400489850bece2cb45..1531197e2c1ed0fb6e26b1c9751a020c418c4f2b 100644 (file)
@@ -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;
 }
 
index 1906cbb92c8a0c5586e56714e115e830dd81f82f..c8f7335c2c0ab8f16a294ba9b02dcfcb48e7e018 100644 (file)
@@ -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