diff --git a/admin/roles/lib.php b/admin/roles/lib.php
index 7fc5782eb2d..b09ed4f688a 100644
--- a/admin/roles/lib.php
+++ b/admin/roles/lib.php
@@ -996,13 +996,14 @@ abstract class role_assign_user_selector_base extends user_selector_base {
*/
public function __construct($name, $options) {
global $CFG;
- parent::__construct($name, $options);
- $this->roleid = $options['roleid'];
if (isset($options['context'])) {
$this->context = $options['context'];
} else {
$this->context = get_context_instance_by_id($options['contextid']);
}
+ $options['accesscontext'] = $this->context;
+ parent::__construct($name, $options);
+ $this->roleid = $options['roleid'];
require_once($CFG->dirroot . '/group/lib.php');
}
diff --git a/admin/settings/users.php b/admin/settings/users.php
index cf782b2980c..02d49b00abd 100644
--- a/admin/settings/users.php
+++ b/admin/settings/users.php
@@ -123,9 +123,24 @@ if ($hassiteconfig
'mycourses' => get_string('mycourses'),
'groups' => get_string('groups'))));
- $temp->add(new admin_setting_configmulticheckbox('extrauserselectorfields',
- get_string('extrauserselectorfields', 'admin'), get_string('configextrauserselectorfields', 'admin'), array('email' => '1'),
- array('email' => get_string('email'), 'idnumber' => get_string('idnumber'), 'username' => get_string('username'), )));
+ // Select fields to display as part of user identity (only to those
+ // with moodle/site:viewuseridentity).
+ // Options include fields from the user table that might be helpful to
+ // distinguish when adding or listing users ('I want to add the John
+ // Smith from Science faculty').
+ // Username is not included as an option because in some sites, it might
+ // be a security problem to reveal usernames even to trusted staff.
+ // Custom user profile fields are not currently supported.
+ $temp->add(new admin_setting_configmulticheckbox('showuseridentity',
+ get_string('showuseridentity', 'admin'),
+ get_string('showuseridentity_desc', 'admin'), array('email' => 1), array(
+ 'idnumber' => get_string('idnumber'),
+ 'email' => get_string('email'),
+ 'phone1' => get_string('phone'),
+ 'phone2' => get_string('phone2'),
+ 'department' => get_string('department'),
+ 'institution' => get_string('institution'),
+ )));
$temp->add(new admin_setting_configcheckbox('enablegravatar', get_string('enablegravatar', 'admin'), get_string('enablegravatar_help', 'admin'), 0));
}
diff --git a/group/members.php b/group/members.php
index 92e4f9a26bc..fd53b135f03 100644
--- a/group/members.php
+++ b/group/members.php
@@ -34,9 +34,7 @@ if ($cancel) {
}
$groupmembersselector = new group_members_selector('removeselect', array('groupid' => $groupid, 'courseid' => $course->id));
-$groupmembersselector->set_extra_fields(array());
$potentialmembersselector = new group_non_members_selector('addselect', array('groupid' => $groupid, 'courseid' => $course->id));
-$potentialmembersselector->set_extra_fields(array());
if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
$userstoadd = $potentialmembersselector->get_selected_users();
diff --git a/lang/en/admin.php b/lang/en/admin.php
index 5dfe0f234e7..002d272cad2 100644
--- a/lang/en/admin.php
+++ b/lang/en/admin.php
@@ -203,7 +203,6 @@ $string['configenablewsdocumentation'] = 'Enable auto-generation of web services
$string['configerrorlevel'] = 'Choose the amount of PHP warnings that you want to be displayed. Normal is usually the best choice.';
$string['configextendedusernamechars'] = 'Enable this setting to allow students to use any characters in their usernames (note this does not affect their actual names). The default is "false" which restricts usernames to be alphanumeric lowercase characters, underscore (_), hyphen (-), period (.) or at symbol (@).';
$string['configextramemorylimit'] = 'Some scripts like search, backup/restore or cron require more memory. Set higher values for large sites.';
-$string['configextrauserselectorfields'] = 'Select which fields are searched and displayed, in addition to full names, when selecting users, for example when assigning roles or when adding users to a group. For security reasons, it is recommended that the username field is NOT selected.';
$string['configfilterall'] = 'Filter all strings, including headings, titles, navigation bar and so on. This is mostly useful when using the multilang filter, otherwise it will just create extra load on your site for little gain.';
$string['configfiltermatchoneperpage'] = 'Automatic linking filters will only generate a single link for the first matching text instance found on the complete page. All others are ignored.';
$string['configfiltermatchonepertext'] = 'Automatic linking filters will only generate a single link for the first matching text instance found in each item of text (e.g., resource, block) on the page. All others are ignored. This setting is ignored if the one per page setting is yes.';
@@ -506,7 +505,6 @@ $string['experimental'] = 'Experimental';
$string['experimentalsettings'] = 'Experimental settings';
$string['extendedusernamechars'] = 'Allow extended characters in usernames';
$string['extramemorylimit'] = 'Extra PHP memory limit';
-$string['extrauserselectorfields'] = 'When selecting users, search and display';
$string['fatalmagicquotesruntime'] = '
Serious configuration error detected, please notify server administrator.
To operate properly, Moodle requires that administrator changes PHP settings.
magic_quotes_runtime must be set to off.
This setting is controlled by editing php.ini, Apache/IIS
configuration or .htaccess file on the server.
';
$string['fatalsessionautostart'] = 'Serious configuration error detected, please notify server administrator.
To operate properly, Moodle requires that administrator changes PHP settings.
session.auto_start must be set to off.
This setting is controlled by editing php.ini, Apache/IIS
configuration or .htaccess file on the server.
';
$string['filecreated'] = 'New file created';
@@ -884,6 +882,8 @@ $string['settingmemorylimit'] = 'Insufficient memory detected, please set higher
$string['settingsafemode'] = 'Moodle is not fully compatible with safe mode, please ask server administrator to turn it off. Running Moodle under safe mode is not supported, please expect various problems if you do so.';
$string['showcommentscount'] = 'Show comments count';
$string['showdetails'] = 'Show details';
+$string['showuseridentity'] = 'Show user identity';
+$string['showuseridentity_desc'] = 'When selecting or searching for users, and when displaying lists of users, these fields may be shown in addition to their full name. The fields are only shown to users who have the moodle/site:viewuseridentity capability; by default, teachers and managers. (This option makes most sense if you choose one or two fields that are mandatory at your institution.)';$string['simpletest'] = 'Unit tests';
$string['simplexmlrequired'] = 'The SimpleXML PHP extension is now required by Moodle.';
$string['sitemaintenance'] = 'The site is undergoing maintenance and is currently not available';
$string['sitemaintenancemode'] = 'Maintenance mode';
diff --git a/lang/en/role.php b/lang/en/role.php
index bda249f5612..35fc81f1ca1 100644
--- a/lang/en/role.php
+++ b/lang/en/role.php
@@ -334,6 +334,7 @@ $string['site:uploadusers'] = 'Upload new users from file';
$string['site:viewfullnames'] = 'Always see full names of users';
$string['site:viewparticipants'] = 'View participants';
$string['site:viewreports'] = 'View reports';
+$string['site:viewuseridentity'] = 'See full user identity in lists';
$string['tag:create'] = 'Create new tags';
$string['tag:edit'] = 'Edit existing tags';
$string['tag:editblocks'] = 'Edit blocks in tags pages';
diff --git a/lib/db/access.php b/lib/db/access.php
index 667e4b2d77c..1ec43820a3e 100644
--- a/lib/db/access.php
+++ b/lib/db/access.php
@@ -385,6 +385,20 @@ $capabilities = array(
)
),
+ // In reports that give lists of users, extra information about each user's
+ // identity (the fields configured in site option showuseridentity) will be
+ // displayed to users who have this capability.
+ 'moodle/site:viewuseridentity' => array(
+
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_COURSE,
+ 'archetypes' => array(
+ 'teacher' => CAP_ALLOW,
+ 'editingteacher' => CAP_ALLOW,
+ 'manager' => CAP_ALLOW
+ )
+ ),
+
'moodle/site:viewreports' => array(
'riskbitmask' => RISK_PERSONAL,
diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php
index 0184da5f5ca..1803a0f773c 100644
--- a/lib/db/upgrade.php
+++ b/lib/db/upgrade.php
@@ -6808,6 +6808,16 @@ FROM
upgrade_main_savepoint(true, 2011101900.02);
}
+ if ($oldversion < 2011102700.01) {
+ // Rename 'extrauserselectorfields' to 'showuseridentity' as it is
+ // being used more widely
+ if (isset($CFG->extrauserselectorfields)) {
+ set_config('showuseridentity', $CFG->extrauserselectorfields);
+ unset_config('extrauserselectorfields');
+ }
+ upgrade_main_savepoint(true, 2011102700.01);
+ }
+
return true;
}
diff --git a/mod/forum/lib.php b/mod/forum/lib.php
index 80c4edf9557..ac835cfa72f 100644
--- a/mod/forum/lib.php
+++ b/mod/forum/lib.php
@@ -7761,6 +7761,7 @@ abstract class forum_subscriber_selector_base extends user_selector_base {
* @param array $options
*/
public function __construct($name, $options) {
+ $options['accesscontext'] = $options['context'];
parent::__construct($name, $options);
if (isset($options['context'])) {
$this->context = $options['context'];
@@ -8357,4 +8358,4 @@ function forum_get_posts_by_user($user, array $courses, $musthaveaccess = false,
}
return $return;
-}
\ No newline at end of file
+}
diff --git a/user/selector/lib.php b/user/selector/lib.php
index 89bf61662b8..9dd55f63004 100644
--- a/user/selector/lib.php
+++ b/user/selector/lib.php
@@ -40,6 +40,9 @@ abstract class user_selector_base {
protected $name;
/** @var array Extra fields to search on and return in addition to firstname and lastname. */
protected $extrafields;
+ /** @var object Context used for capability checks regarding this selector (does
+ * not necessarily restrict user list) */
+ protected $accesscontext;
/** @var boolean Whether the conrol should allow selection of many users, or just one. */
protected $multiselect = true;
/** @var int The height this control should have, in rows. */
@@ -89,10 +92,20 @@ abstract class user_selector_base {
// Initialise member variables from constructor arguments.
$this->name = $name;
+
+ // Use specified context for permission checks, system context if not
+ // specified
+ if (isset($options['accesscontext'])) {
+ $this->accesscontext = $options['accesscontext'];
+ } else {
+ $this->accesscontext = get_context_instance(CONTEXT_SYSTEM);
+ }
+
if (isset($options['extrafields'])) {
$this->extrafields = $options['extrafields'];
- } else if (!empty($CFG->extrauserselectorfields)) {
- $this->extrafields = explode(',', $CFG->extrauserselectorfields);
+ } else if (!empty($CFG->showuseridentity) &&
+ has_capability('moodle/site:viewuseridentity', $this->accesscontext)) {
+ $this->extrafields = explode(',', $CFG->showuseridentity);
} else {
$this->extrafields = array();
}
@@ -331,7 +344,8 @@ abstract class user_selector_base {
'name' => $this->name,
'exclude' => $this->exclude,
'extrafields' => $this->extrafields,
- 'multiselect' => $this->multiselect
+ 'multiselect' => $this->multiselect,
+ 'accesscontext' => $this->accesscontext,
);
}
@@ -580,13 +594,15 @@ abstract class user_selector_base {
* @return string a string representation of the user.
*/
public function output_user($user) {
- $bits = array(
- fullname($user)
- );
- foreach ($this->extrafields as $field) {
- $bits[] = $user->$field;
+ $out = fullname($user);
+ if ($this->extrafields) {
+ $displayfields = array();
+ foreach ($this->extrafields as $field) {
+ $displayfields[] = $user->{$field};
+ }
+ $out .= ' (' . implode(', ', $displayfields) . ')';
}
- return implode(', ', $bits);
+ return $out;
}
/**
@@ -660,6 +676,7 @@ abstract class groups_user_selector_base extends user_selector_base {
*/
public function __construct($name, $options) {
global $CFG;
+ $options['accesscontext'] = get_context_instance(CONTEXT_COURSE, $options['courseid']);
parent::__construct($name, $options);
$this->groupid = $options['groupid'];
$this->courseid = $options['courseid'];
diff --git a/version.php b/version.php
index 6bcc026af5b..afc1128e65b 100644
--- a/version.php
+++ b/version.php
@@ -30,8 +30,7 @@
defined('MOODLE_INTERNAL') || die();
-
-$version = 2011102700.00; // YYYYMMDD = weekly release date of this DEV branch
+$version = 2011102700.01; // YYYYMMDD = weekly release date of this DEV branch
// RR = release increments - 00 in DEV branches
// .XX = incremental changes