From: moodler Date: Thu, 14 Sep 2006 09:39:23 +0000 (+0000) Subject: Added a new setting called $CFG->defaultuserroleid which defines X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=8f8ed475f71c592acaff9834c23d3f45b5974f45;p=moodle.git Added a new setting called $CFG->defaultuserroleid which defines the role that ALL users get by default when they log in. --- diff --git a/admin/roles/assign.php b/admin/roles/assign.php index 0b5098475a..afed977df9 100755 --- a/admin/roles/assign.php +++ b/admin/roles/assign.php @@ -35,6 +35,7 @@ require_capability('moodle/role:assign', $context); + $assignableroles = get_assignable_roles($context); $strassignusers = get_string('assignusers', 'role'); $strpotentialusers = get_string('potentialusers', 'role'); @@ -45,8 +46,6 @@ $strsearch = get_string('search'); $strshowall = get_string('showall'); - $context = get_record('context', 'id', $contextid); - $assignableroles = get_assignable_roles($context); /// Make sure this user can assign that role diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index a321b11cb7..cc300bc3a1 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -4,7 +4,7 @@ $ADMIN->add('appearance', new admin_category('themes', get_string('themes'))); // "themesettings" settingpage -$temp = new admin_settingpage('themesettings', get_string('settings')); +$temp = new admin_settingpage('themesettings', get_string('themesettings', 'admin')); $temp->add(new admin_setting_configtext('themelist', get_string('themelist', 'admin'), get_string('configthemelist','admin'), '', PARAM_NOTAGS)); $temp->add(new admin_setting_configcheckbox('allowuserthemes', get_string('allowuserthemes', 'admin'), get_string('configallowuserthemes', 'admin'), 0)); $temp->add(new admin_setting_configcheckbox('allowcoursethemes', get_string('allowcoursethemes', 'admin'), get_string('configallowcoursethemes', 'admin'), 0)); diff --git a/admin/settings/language.php b/admin/settings/language.php index f4872ede17..5dd9e15417 100644 --- a/admin/settings/language.php +++ b/admin/settings/language.php @@ -3,7 +3,7 @@ // This file defines settingpages and externalpages under the "appearance" category // "languageandlocation" settingpage -$temp = new admin_settingpage('langsettings', get_string('settings')); +$temp = new admin_settingpage('langsettings', get_string('languagesettings', 'admin')); $temp->add(new admin_setting_configselect('lang', get_string('lang', 'admin'), get_string('configlang', 'admin'), $CFG->lang, get_list_of_languages())); // $CFG->lang might be set in installer already, default en or en_utf8 is in setup.php $temp->add(new admin_setting_configcheckbox('langmenu', get_string('langmenu', 'admin'), get_string('configlangmenu', 'admin'), 1)); $temp->add(new admin_setting_configtext('langlist', get_string('langlist', 'admin'), get_string('configlanglist', 'admin'), '', PARAM_NOTAGS)); diff --git a/admin/settings/location.php b/admin/settings/location.php index a7748e6cd4..cde4443bf3 100644 --- a/admin/settings/location.php +++ b/admin/settings/location.php @@ -1,7 +1,7 @@ add(new admin_setting_configselect('timezone', get_string('timezone','admin'), get_string('configtimezone', 'admin'), 99, $options)); diff --git a/admin/settings/security.php b/admin/settings/security.php index 048d453e5b..77e8f54cd3 100644 --- a/admin/settings/security.php +++ b/admin/settings/security.php @@ -38,25 +38,6 @@ $ADMIN->add('security', $temp); -// "userpolicies" settingpage -$temp = new admin_settingpage('userpolicies', get_string('userpolicies', 'admin')); -$temp->add(new admin_setting_configcheckbox('autologinguests', get_string('autologinguests', 'admin'), get_string('configautologinguests', 'admin'), 0)); -$temp->add(new admin_setting_configmultiselect('hiddenuserfields', get_string('hiddenuserfields', 'admin'), get_string('confighiddenuserfields', 'admin'), array(), array('none' => get_string('none'), - 'description' => get_string('description'), - 'city' => get_string('city'), - 'country' => get_string('country'), - 'webpage' => get_string('webpage'), - 'icqnumber' => get_string('icqnumber'), - 'skypeid' => get_string('skypeid'), - 'yahooid' => get_string('yahooid'), - 'aimid' => get_string('aimid'), - 'msnid' => get_string('msnid'), - 'lastaccess' => get_string('lastaccess')))); -$temp->add(new admin_setting_configcheckbox('allusersaresitestudents', get_string('allusersaresitestudents', 'admin'), get_string('configallusersaresitestudents','admin'), 1)); -$temp->add(new admin_setting_special_adminseesall()); -$ADMIN->add('security', $temp); - - // "httpsecurity" settingpage $temp = new admin_settingpage('httpsecurity', get_string('httpsecurity', 'admin')); diff --git a/admin/settings/users.php b/admin/settings/users.php index 7f43961e11..b8f896a47e 100644 --- a/admin/settings/users.php +++ b/admin/settings/users.php @@ -5,6 +5,36 @@ $ADMIN->add('users', new admin_externalpage('userauthentication', get_string('authentication','admin'), "$CFG->wwwroot/$CFG->admin/auth.php")); +// "userpolicies" settingpage +$temp = new admin_settingpage('userpolicies', get_string('userpolicies', 'admin')); +$temp->add(new admin_setting_configcheckbox('autologinguests', get_string('autologinguests', 'admin'), get_string('configautologinguests', 'admin'), 0)); +$temp->add(new admin_setting_configmultiselect('hiddenuserfields', get_string('hiddenuserfields', 'admin'), get_string('confighiddenuserfields', 'admin'), array(), array('none' => get_string('none'), + 'description' => get_string('description'), + 'city' => get_string('city'), + 'country' => get_string('country'), + 'webpage' => get_string('webpage'), + 'icqnumber' => get_string('icqnumber'), + 'skypeid' => get_string('skypeid'), + 'yahooid' => get_string('yahooid'), + 'aimid' => get_string('aimid'), + 'msnid' => get_string('msnid'), + 'lastaccess' => get_string('lastaccess')))); +$temp->add(new admin_setting_configcheckbox('allusersaresitestudents', get_string('allusersaresitestudents', 'admin'), get_string('configallusersaresitestudents','admin'), 1)); +$temp->add(new admin_setting_special_adminseesall()); + +$context = get_context_instance(CONTEXT_SYSTEM, SITEID); +if (!$guestrole = get_guest_role()) { + $guestrole->id = 999; +} +$temp->add(new admin_setting_configselect('notloggedinroleid', get_string('notloggedinroleid', 'admin'), + get_string('confignotloggedinroleid', 'admin'), $guestrole->id, get_assignable_roles($context))); +$temp->add(new admin_setting_configselect('defaultuserroleid', get_string('defaultuserroleid', 'admin'), + get_string('configdefaultuserroleid', 'admin'), $guestrole->id, get_assignable_roles($context))); + +$ADMIN->add('users', $temp); + + + // stuff under the "accounts" subcategory $ADMIN->add('users', new admin_category('accounts', get_string('accounts', 'admin'))); $ADMIN->add('accounts', new admin_externalpage('editusers', get_string('userlist','admin'), "$CFG->wwwroot/$CFG->admin/user.php")); @@ -18,4 +48,6 @@ $ADMIN->add('roles', new admin_externalpage('defineroles', get_string('definerol $ADMIN->add('roles', new admin_externalpage('assignroles', get_string('assignroles', 'role'), "$CFG->wwwroot/$CFG->admin/roles/assign.php?contextid=" . SITEID)); + + ?> diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php index 26cd82c358..bea82727f0 100644 --- a/lang/en_utf8/admin.php +++ b/lang/en_utf8/admin.php @@ -20,21 +20,24 @@ $string['log'] = 'Logs'; $string['simpletest'] = 'Unit tests'; $string['stats'] = 'Statistics'; $string['mymoodle'] = 'My Moodle'; +$string['locationsettings'] = 'Location settings'; +$string['languagesettings'] = 'Language settings'; +$string['themesettings'] = 'Theme settings'; $string['htmleditor'] = 'HTML Editor'; $string['misc'] = 'Miscellaneous'; -$string['filtersettings'] = 'Filter Settings'; -$string['generalsettings'] = 'General Settings'; +$string['filtersettings'] = 'Filter settings'; +$string['generalsettings'] = 'General settings'; $string['frontpage'] = 'Front Page'; $string['systempaths'] = 'System Paths'; $string['mail'] = 'Email'; $string['sessionhandling'] = 'Session Handling'; $string['http'] = 'HTTP'; -$string['httpsecurity'] = 'HTTP Security'; -$string['modulesecurity'] = 'Module Security'; +$string['httpsecurity'] = 'HTTP security'; +$string['modulesecurity'] = 'Module security'; $string['notifications'] = 'Notifications'; -$string['sitepolicies'] = 'Site Policies'; -$string['userpolicies'] = 'User Policies'; +$string['sitepolicies'] = 'Site policies'; +$string['userpolicies'] = 'User policies'; $string['antivirus'] = 'Anti-Virus'; $string['authentication'] = 'Authentication'; $string['backups'] = 'Backups'; @@ -42,8 +45,8 @@ $string['courserequests'] = 'Course Requests'; $string['themeselector'] = 'Theme Selector'; $string['nonewsettings'] = 'No new settings were added during this upgrade.'; -$string['upgradesettings'] = 'New Settings'; -$string['upgradesettingsintro'] = 'The settings shown below were added during your last Moodle upgrade. Make any changes necessary to the defaults and then click "Save Settings" at the bottom of this page.'; +$string['upgradesettings'] = 'New settings'; +$string['upgradesettingsintro'] = 'The settings shown below were added during your last Moodle upgrade. Make any changes necessary to the defaults and then click "Save settings" at the bottom of this page.'; $string['nonexistentbookmark'] = 'The bookmark you requested does not exist.'; $string['bookmarkdeleted'] = 'Bookmark deleted.'; @@ -119,7 +122,7 @@ $string['confightmleditor'] = 'Choose whether or not to allow use of the embedde $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.'; $string['configintro'] = 'On this page you can specify a number of configuration variables that help make Moodle work properly on your server. Don\'t worry too much about it - the defaults will usually work fine and you can always come back to this page later and change these settings.'; $string['configintroadmin'] = 'On this page you should configure your main administrator account which will have complete control over the site. Make sure you give it a secure username and password as well as a valid email address. You can create more admin accounts later on.'; -$string['configintrosite'] = 'This page allows you to configure the front page and name of this new site. You can come back here later to change these settings any time using the \'Site Settings\' link on the home page.'; +$string['configintrosite'] = 'This page allows you to configure the front page and name of this new site. You can come back here later to change these settings any time using the Administration menus.'; $string['configintrotimezones'] = 'This page will search for new information about world timezones (including daylight savings time rules) and update your local database with this information. These locations will be checked, in order: $a This procedure is generally very safe and can not break normal installations. Do you wish to update your timezones now?'; $string['configlang'] = 'Choose a default language for the whole site. Users can override this setting later.'; $string['configlangcache'] = 'Cache the language menu. Saves a lot of memory and processing power. If you enable this, the menu takes a few minutes to update after you have added or removed languages.'; diff --git a/lang/en_utf8/error.php b/lang/en_utf8/error.php index 2031b6c9a6..1880fd2bed 100644 --- a/lang/en_utf8/error.php +++ b/lang/en_utf8/error.php @@ -39,6 +39,7 @@ $string['missingrequiredfield'] = 'Some required field is missing'; $string['modulerequirementsnotmet'] = 'Module \"$a->modulename\" ($a->moduleversion) could not be installed. It requires a newer version of Moodle (currently you are using $a->currentmoodle, you need $a->requiremoodle).'; $string['modulemissingcode'] = 'Module $a is missing the code needed to perform this function'; $string['mustbeteacher'] = 'You must be a teacher to look at this page'; +$string['nocontext'] = 'Sorry, but that course is not a valid context'; $string['noinstances'] = 'There are no instances of $a in this course! '; $string['nonmeaningfulcontent'] = 'Non meaningful content'; $string['noparticipatorycms'] = 'Sorry, but you have no participatory course modules to report on.'; diff --git a/lib/accesslib.php b/lib/accesslib.php index bdccb57cd2..75c8235680 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -55,9 +55,7 @@ function load_guest_role($context=NULL) { } if (empty($guestrole)) { - if ($roles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) { - $guestrole = array_shift($roles); // Pick the first one - } else { + if (!$guestrole = get_guest_role()) { return false; } } @@ -84,8 +82,7 @@ function load_notloggedin_role() { } if (empty($CFG->notloggedinroleid)) { // Let's set the default to the guest role - if ($roles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) { - $role = array_shift($roles); // Pick the first one + if ($role = get_guest_role()) { set_config('notloggedinroleid', $role->id); } else { return false; @@ -102,6 +99,56 @@ function load_notloggedin_role() { return true; } +/** + * Load default not logged in role capabilities when user is not logged in + * @return bool + */ +function load_defaultuser_role() { + global $CFG, $USER; + + if (!$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID)) { + return false; + } + + if (empty($CFG->defaultuserroleid)) { // Let's set the default to the guest role + if ($role = get_guest_role()) { + set_config('defaultuserroleid', $role->id); + } else { + return false; + } + } + + if ($capabilities = get_records_select('role_capabilities', + "roleid = $CFG->defaultuserroleid AND contextid = $sitecontext->id")) { + foreach ($capabilities as $capability) { + $USER->capabilities[$sitecontext->id][$capability->capability] = $capability->permission; + } + + // SPECIAL EXCEPTION: If the default user role is actually a guest role, then + // remove some capabilities so this user doesn't get confused with a REAL guest + if (isset($USER->capabilities[$sitecontext->id]['moodle/legacy:guest'])) { + unset($USER->capabilities[$sitecontext->id]['moodle/legacy:guest']); + unset($USER->capabilities[$sitecontext->id]['moodle/course:view']); // No access to courses by default + } + } + + return true; +} + + +/** + * Get the default guest role + * @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 + } else { + return false; + } +} + + /** * This functions get all the course categories in proper order * @param int $context @@ -164,11 +211,6 @@ function get_parent_cats($context, $type) { -/************************************* - * Functions for Roles & Capabilites * - *************************************/ - - /** * This function checks for a capability assertion being true. If it isn't * then the page is terminated neatly with a standard error message @@ -219,8 +261,12 @@ function has_capability($capability, $context=NULL, $userid=NULL, $doanything=tr global $USER, $CONTEXT, $CFG; - if (empty($userid) && !isloggedin() && !isset($USER->capabilities)) { - load_notloggedin_role(); + if (empty($userid) && empty($USER->capabilities)) { // Real user, first time here + if (isloggedin()) { + load_defaultuser_role(); // All users get this by default + } else { + load_notloggedin_role(); // others get this by default + } } if ($userid && $userid != $USER->id) { @@ -453,9 +499,8 @@ function load_user_capability($capability='', $context ='', $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); - } + unset($USER->capabilities); // make sure it's cleaned when loaded (again) + $userid = $USER->id; $otheruserid = false; } else { diff --git a/lib/weblib.php b/lib/weblib.php index 1d13394126..b96dc1515c 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -2098,7 +2098,7 @@ function print_header ($title='', $heading='', $navigation='', $focus='', if (isset($SESSION->justloggedin)) { unset($SESSION->justloggedin); if (!empty($CFG->displayloginfailures)) { - if (!empty($USER->username) and !isguest()) { + if (!empty($USER->username) and $USER->username != 'guest') { if ($count = count_login_failures($CFG->displayloginfailures, $USER->username, $USER->lastlogin)) { $menu .= ' '; if (empty($count->accounts)) { @@ -2603,7 +2603,7 @@ function user_login_string($course=NULL, $user=NULL) { if (isset($user->id) and $user->id) { $fullname = fullname($user, true); $username = "framename}\" href=\"$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id\">$fullname"; - if (isguest($user->id)) { + if (isset($user->username) && $user->username == 'guest') { $loggedinas = $realuserinfo.get_string('loggedinasguest'). " (framename}\" href=\"$wwwroot/login/index.php\">".get_string('login').')'; } else { diff --git a/login/index.php b/login/index.php index b572ab0d43..7869a92f68 100644 --- a/login/index.php +++ b/login/index.php @@ -209,6 +209,7 @@ reset_login_count(); if (!empty($CFG->rolesactive)) { load_user_capability(); // load user's capabilities + load_defaultuser_role(); // All users get this by default } redirect($urltogo); diff --git a/version.php b/version.php index 8ca7f64d98..84b821d44b 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 = 2006091212; // YYYYMMDD = date + $version = 2006091400; // YYYYMMDD = date // XY = increments within a single day $release = '1.7 dev'; // Human-friendly version name