]> git.mjollnir.org Git - moodle.git/commitdiff
(MDL-8367) Add configuration option to select role for guest - guestroleid
authorskodak <skodak>
Thu, 1 Feb 2007 10:24:26 +0000 (10:24 +0000)
committerskodak <skodak>
Thu, 1 Feb 2007 10:24:26 +0000 (10:24 +0000)
admin/settings/users.php
lang/en_utf8/admin.php
lib/accesslib.php

index ae4185cb22326df6fec3a4b05fb249d9b7d787fd..5d3fcfbbba0cba8d0d315157814cf0bbd5b64a7e 100644 (file)
@@ -29,7 +29,7 @@ $ADMIN->add('roles', new admin_externalpage('assignroles', get_string('assignrol
 // "userpolicies" settingpage
 $temp = new admin_settingpage('userpolicies', get_string('userpolicies', 'admin'));
 
-$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
+$context = get_context_instance(CONTEXT_SYSTEM);
 if (!$guestrole = get_guest_role()) {
     $guestrole->id = 0;
 }
@@ -43,7 +43,9 @@ if ($userroles = get_roles_with_capability('moodle/legacy:user', CAP_ALLOW)) {
 } else {
     $userrole->id = 0;
 }
-$assignableroles  = get_assignable_roles($context);
+// 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();
 if ($roles = get_all_roles()) {
     foreach ($roles as $role) {
@@ -52,16 +54,18 @@ if ($roles = get_all_roles()) {
 }
 
 $temp->add(new admin_setting_configselect('notloggedinroleid', get_string('notloggedinroleid', 'admin'),
-              get_string('confignotloggedinroleid', 'admin'), $guestrole->id, $assignableroles ));
+              get_string('confignotloggedinroleid', 'admin'), $guestrole->id, $allroles ));
+$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));
 $temp->add(new admin_setting_configselect('defaultcourseroleid', get_string('defaultcourseroleid', 'admin'),
-              get_string('configdefaultcourseroleid', 'admin'), $studentrole->id, $assignableroles));
+              get_string('configdefaultcourseroleid', 'admin'), $studentrole->id, $allroles));
 
 $temp->add(new admin_setting_configcheckbox('autologinguests', get_string('autologinguests', 'admin'), get_string('configautologinguests', 'admin'), 0));
 
 $temp->add(new admin_setting_configmultiselect('nonmetacoursesyncroleids', get_string('nonmetacoursesyncroleids', 'admin'),
-              get_string('confignonmetacoursesyncroleids', 'admin'), array(), $assignableroles));
+              get_string('confignonmetacoursesyncroleids', 'admin'), array(), $allroles));
 
 //$temp->add(new admin_setting_configcheckbox('allusersaresitestudents', get_string('allusersaresitestudents', 'admin'), get_string('configallusersaresitestudents','admin'), 1));
 $temp->add(new admin_setting_configmultiselect('hiddenuserfields', get_string('hiddenuserfields', 'admin'),
index e44e0b8601068a4604555b9c0f3daa6652ec5971..ee184f640dd51319ff23b4b4ef10e4927d867c35 100644 (file)
@@ -103,6 +103,7 @@ $string['configfrontpageloggedin'] = 'The items selected above will be displayed
 $string['configfullnamedisplay'] = 'This defines how names are shown when they are displayed in full. For most mono-lingual sites the most efficient setting is the default \"Given names + Surname\", but you may choose to hide surnames altogether, or to leave it up to the current language pack to decide (some languages have different conventions).';
 $string['configgdversion'] = 'Indicate the version of GD that is installed.  The version shown by default is the one that has been auto-detected.  Don\'t change this unless you really know what you\'re doing.';
 $string['configgradebookroles'] = 'This setting allows you to control who appears on the gradebook.  Users need to have at least one of these roles in a course to be shown in the gradebook for that course.';
+$string['configguestroleid'] = 'This role is automatically assigned to the guest user. It is also temporarily assigned to not enrolled users when they enter course that allows guests without password. Please verify that the role has moodle/legacy:guest and moodle/course:view capability.';
 $string['confighiddenuserfields'] = 'Select which user infomation fields you wish to hide from other users other than course teachers/admins. This will increase student privacy. Hold CTRL key to select multiple fields.';
 $string['confightmleditor'] = 'Choose whether or not to allow use of the embedded HTML text editor. Even if you choose allow, this editor will only appear when the user is using a compatible web browser.  Users can also choose not to use it.';
 $string['configidnumber'] = 'This option specifies whether (a) Users are not be asked for an ID number at all, (b) Users are asked for an ID number but can leave it blank or (c) Users are asked for an ID Number and cannot leave it blank. If given the User\'s ID number is displayed in their Profile.';
@@ -290,6 +291,7 @@ $string['globalsquoteswarning'] = '<p><strong>Security Warning</strong>: to oper
 $string['gotofirst'] = 'Go to first missing string';
 $string['gradebook'] = 'Gradebook';
 $string['gradebookroles'] = 'Graded roles';
+$string['guestroleid'] = 'Role for guest';
 $string['helpadminseesall'] = 'Do admins see all calendar events or just those that apply to themselves?';
 $string['helpcalendarsettings'] = 'Configure various calendar and date/time-related aspects of Moodle';
 $string['helpforcetimezone'] = 'You can allow users to individually select their timezone, or force a timezone for everyone.';
index 308c350dae56c4f4f1d55bd14d2d1bab2cf0607a..ca712b75ca4ae1e7430ba12058a41fba906554c9 100755 (executable)
@@ -187,10 +187,25 @@ function load_defaultuser_role($return=false) {
  * @return object role
  */
 function get_guest_role() {
-    if ($roles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) {
-        return array_shift($roles);   // Pick the first one
+    global $CFG;
+
+    if (empty($CFG->guestroleid)) {
+        if ($roles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) {
+            $guestrole = array_shift($roles);   // Pick the first one
+            set_config('guestroleid', $guestrole->id);
+            return $guestrole;
+        } else {
+            debugging('Can not find any guest role!');
+            return false;
+        }
     } else {
-        return false;
+        if ($guestrole = get_record('role','id', $CFG->guestroleid)) {
+            return $guestrole;
+        } else {
+            //somebody is messing with guest roles, remove incorrect setting and try to find a new one
+            set_config('guestroleid', '');
+            return get_guest_role();
+        }
     }
 }