Commit 5f14d7ae authored by Tony Butler's avatar Tony Butler Committed by Gerrit Code Review

Consolidate 'searchusernames' and 'nousernames' options (Bug #1353516)

Change-Id: Ib0d6028fd81ac0b66f0c9d49e201825c07c41d98
parent ce42fa63
......@@ -68,7 +68,12 @@ function regenerateurls_submit(Pieform $form, $values) {
execute_sql('UPDATE {usr} SET urlid = NULL WHERE NOT urlid IS NULL');
$usrcount = count_records_select('usr', 'deleted = 0 AND id > 0');
$sql = 'SELECT id, username FROM {usr} WHERE id > ? AND deleted = 0 ORDER BY id';
if (!get_config('nousernames')) {
$sql = 'SELECT id, username FROM {usr} WHERE id > ? AND deleted = 0 ORDER BY id';
}
else {
$sql = 'SELECT id, firstname, lastname, preferredname FROM {usr} WHERE id > ? AND deleted = 0 ORDER BY id';
}
$done = 0;
$lastid = 0;
......@@ -77,7 +82,16 @@ function regenerateurls_submit(Pieform $form, $values) {
$firstid = $lastid;
$values = array();
foreach ($records as $r) {
$r->urlid = generate_urlid($r->username, get_config('cleanurluserdefault'), 3, 30);
if (!empty($r->username)) {
$urlid = $r->username;
}
else if (!empty($r->preferredname)) {
$urlid = $r->preferredname;
}
else {
$urlid = $r->firstname . '-' . $r->lastname;
}
$r->urlid = generate_urlid($urlid, get_config('cleanurluserdefault'), 3, 30);
array_push($values, $r->id, $r->urlid);
$lastid = $r->id;
}
......
......@@ -147,13 +147,6 @@ $siteoptionform = array(
'defaultvalue' => get_config('nousernames'),
'disabled' => in_array('nousernames', $OVERRIDDEN),
),
'searchusernames' => array(
'type' => 'checkbox',
'title' => get_string('searchusernames', 'admin'),
'description' => get_string('searchusernamesdescription', 'admin'),
'defaultvalue' => get_config('searchusernames'),
'disabled' => in_array('searchusernames', $OVERRIDDEN),
),
'searchuserspublic' => array(
'type' => 'checkbox',
'title' => get_string('searchuserspublic', 'admin'),
......@@ -771,7 +764,7 @@ function siteoptions_submit(Pieform $form, $values) {
'defaultaccountlifetime', 'defaultregistrationexpirylifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn',
'defaultaccountlifetimeupdate', 'allowpublicviews', 'allowpublicprofiles', 'allowanonymouspages', 'generatesitemap',
'registration_sendweeklyupdates', 'institutionexpirynotification', 'institutionautosuspend', 'requireregistrationconfirm',
'showselfsearchsideblock', 'searchusernames', 'searchplugin', 'showtagssideblock',
'showselfsearchsideblock', 'nousernames', 'searchplugin', 'showtagssideblock',
'tagssideblockmaxtags', 'country', 'viewmicroheaders', 'userscanchooseviewthemes',
'remoteavatars', 'userscanhiderealnames', 'antispam', 'spamhaus', 'surbl', 'anonymouscomments',
'recaptchaonregisterform', 'recaptchapublickey', 'recaptchaprivatekey', 'loggedinprofileviewaccess', 'disableexternalresources',
......@@ -780,7 +773,7 @@ function siteoptions_submit(Pieform $form, $values) {
'registerterms', 'licensemetadata', 'licenseallowcustom', 'allowmobileuploads', 'creategroups', 'createpublicgroups', 'allowgroupcategories', 'wysiwyg',
'staffreports', 'staffstats', 'userscandisabledevicedetection', 'watchlistnotification_delay',
'masqueradingreasonrequired', 'masqueradingnotified', 'searchuserspublic',
'eventloglevel', 'eventlogexpiry', 'sitefilesaccess', 'exporttoqueue', 'defaultmultipleblogs', 'nousernames',
'eventloglevel', 'eventlogexpiry', 'sitefilesaccess', 'exporttoqueue', 'defaultmultipleblogs',
);
$count = 0;
$where_sql = " WHERE admin = 0 AND id != 0";
......
......@@ -361,7 +361,7 @@ $string['institutionexpirynotificationdescriptioninfo'] = 'A notification messag
$string['language'] = 'Language';
$string['none'] = 'None';
$string['nousernames'] = 'Never display usernames';
$string['nousernamesdescription'] = 'If checked, ordinary users will not be able to see the username of any other user.';
$string['nousernamesdescription'] = 'If checked, ordinary users will not be able to see the username of any other user, nor will they be able to search for users by username. These restrictions do not apply to staff and administrators. Additionally, Clean URLs for profile pages will be generated using display names (if provided) or real names, rather than usernames.';
$string['onlineuserssideblockmaxusers'] = 'Online users limit';
$string['onlineuserssideblockmaxusersdescription'] = 'The maximum number of users to display in the online users sidebar.';
$string['country'] = 'Country';
......@@ -389,8 +389,6 @@ $string['remoteavatarsdescription'] = 'If checked, the <a href="http://www.grava
$string['searchplugin'] = 'Search plugin';
$string['searchplugindescription'] = 'Search plugin to use';
$string['searchconfigerror1'] = 'The configuration settings for the search plugin "%s" are incorrect. Please check the configuration settings under "Extensions" → "Plugin type: search". You may need to hit the search\'s \'reset\' button when done.';
$string['searchusernames'] = 'Search usernames';
$string['searchusernamesdescription'] = 'If checked, allow usernames to be searched on as part of "Search users". This setting has no effect if "Never display usernames" above is enforced. Site administrators and staff members are always able to search by username.';
$string['searchuserspublic'] = 'Show users in public search';
$string['searchuserspublicdescription'] = 'Allow users\' names to appear in public search results. This needs to have \'publicsearchallowed\' set to true and be using a search plugin that allows public search, e.g. Elasticsearch. Changing this setting will require search re-indexing.';
$string['sessionlifetime'] = 'Session lifetime';
......
......@@ -3954,5 +3954,15 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2015030400) {
if (get_config('searchusernames') === 1) {
set_config('nousernames', 0);
}
else {
set_config('nousernames', 1);
}
delete_records('config', 'field', 'searchusernames');
}
return $status;
}
......@@ -848,7 +848,7 @@ function core_install_firstcoredata_defaults() {
set_config('homepageinfo', 1);
set_config('showonlineuserssideblock', 1);
set_config('footerlinks', serialize(array('privacystatement', 'about', 'contactus')));
set_config('searchusernames', 1);
set_config('nousernames', 0);
set_config('onlineuserssideblockmaxusers', 10);
set_config('loggedinprofileviewaccess', 1);
set_config('dropdownmenu', 0);
......
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/index.php/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2015021900;
$config->version = 2015030400;
$config->series = '15.04';
$config->release = '15.04dev';
$config->minupgradefrom = 2009022600;
......
......@@ -3978,8 +3978,8 @@ class View {
OR c.name $like '%' || ? || '%' OR c.description $like '%' || ? || '%' ";
array_push($whereparams, $query, $query);
}
if ($admin || $USER->get('staff') || (get_config('searchusernames') && !get_config('nousernames'))) {
// If the site setting 'Search usernames' is enabled, allow searching by username.
if ($admin || $USER->get('staff') || !get_config('nousernames')) {
// If the site setting 'Never display usernames' is disabled, allow searching by username.
$where .= "
OR qu.username $like '%' || ? || '%' ";
array_push($whereparams, $query);
......
......@@ -218,7 +218,7 @@ class PluginSearchInternal extends PluginSearch {
$querydata = self::split_query_string(strtolower(trim($query_string)));
$hidenameallowed = get_config('userscanhiderealnames') ? 'TRUE' : 'FALSE';
$searchusernamesallowed = $USER->get('admin') || $USER->get('staff') || (get_config('searchusernames') && !get_config('nousernames')) ? 'TRUE' : 'FALSE';
$searchusernamesallowed = $USER->get('admin') || $USER->get('staff') || !get_config('nousernames') ? 'TRUE' : 'FALSE';
$termsql = "$matches->preferredname
OR (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment