Skip to content

Commit

Permalink
Added a new setting called $CFG->defaultuserroleid which defines
Browse files Browse the repository at this point in the history
the role that ALL users get by default when they log in.
  • Loading branch information
moodler committed Sep 14, 2006
1 parent ea8158c commit 8f8ed47
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 51 deletions.
3 changes: 1 addition & 2 deletions admin/roles/assign.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion admin/settings/appearance.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion admin/settings/language.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion admin/settings/location.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php // $Id$

// "locations" settingpage
$temp = new admin_settingpage('locationsettings', get_string('settings'));
$temp = new admin_settingpage('locationsettings', get_string('locationsettings', 'admin'));
$options = get_list_of_timezones();
$options[99] = get_string('serverlocaltime');
$temp->add(new admin_setting_configselect('timezone', get_string('timezone','admin'), get_string('configtimezone', 'admin'), 99, $options));
Expand Down
19 changes: 0 additions & 19 deletions admin/settings/security.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,6 @@



// "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'));
Expand Down
32 changes: 32 additions & 0 deletions admin/settings/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -18,4 +48,6 @@
$ADMIN->add('roles', new admin_externalpage('assignroles', get_string('assignroles', 'role'), "$CFG->wwwroot/$CFG->admin/roles/assign.php?contextid=" . SITEID));




?>
21 changes: 12 additions & 9 deletions lang/en_utf8/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,33 @@
$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';
$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 &quot;Save Settings&quot; 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 &quot;Save settings&quot; at the bottom of this page.';

$string['nonexistentbookmark'] = 'The bookmark you requested does not exist.';
$string['bookmarkdeleted'] = 'Bookmark deleted.';
Expand Down Expand Up @@ -119,7 +122,7 @@
$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.';
Expand Down
1 change: 1 addition & 0 deletions lang/en_utf8/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
$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.';
Expand Down
75 changes: 60 additions & 15 deletions lib/accesslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions lib/weblib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 .= '&nbsp;<font size="1">';
if (empty($count->accounts)) {
Expand Down Expand Up @@ -2603,7 +2603,7 @@ function user_login_string($course=NULL, $user=NULL) {
if (isset($user->id) and $user->id) {
$fullname = fullname($user, true);
$username = "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a>";
if (isguest($user->id)) {
if (isset($user->username) && $user->username == 'guest') {
$loggedinas = $realuserinfo.get_string('loggedinasguest').
" (<a target=\"{$CFG->framename}\" href=\"$wwwroot/login/index.php\">".get_string('login').'</a>)';
} else {
Expand Down
1 change: 1 addition & 0 deletions login/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8f8ed47

Please sign in to comment.