Commit 9d7b93c7 authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1534398: Allow user creation to respect the 'nousernames' setting



Created a new function get_raw_user_urlid() to fetch the correct string to
pass to generate_urlid()

behatnotneeded

Change-Id: I1901045ef8e89d224e1ab9556587224ff1d7e6a0
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent cce535e8
......@@ -83,16 +83,7 @@ function regenerateurls_submit(Pieform $form, $values) {
$firstid = $lastid;
$values = array();
foreach ($records as $r) {
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);
$r->urlid = generate_urlid(get_raw_user_urlid($r), get_config('cleanurluserdefault'), 3, 30);
array_push($values, $r->id, $r->urlid);
$lastid = $r->id;
}
......
......@@ -310,7 +310,7 @@ class User {
public function create() {
$this->set('ctime', time());
if (get_config('cleanurls') && is_null($this->urlid)) {
$desiredurlid = generate_urlid($this->username, get_config('cleanurluserdefault'), 3, 30);
$desiredurlid = generate_urlid(get_raw_user_urlid($this), get_config('cleanurluserdefault'), 3, 30);
$this->set('urlid', get_new_profile_urlid($desiredurlid));
}
}
......
......@@ -2420,7 +2420,7 @@ function create_user($user, $profile=array(), $institution=null, $remoteauth=nul
$user->ctime = db_format_timestamp(time());
// Ensure this user has a profile urlid
if (get_config('cleanurls') && (!isset($user->urlid) || is_null($user->urlid))) {
$user->urlid = generate_urlid($user->username, get_config('cleanurluserdefault'), 3, 30);
$user->urlid = generate_urlid(get_raw_user_urlid($user), get_config('cleanurluserdefault'), 3, 30);
$user->urlid = get_new_profile_urlid($user->urlid);
}
if (empty($user->quota)) {
......
......@@ -4512,6 +4512,27 @@ function favicon_display_url($host) {
return $url;
}
/**
* Given an user object, return raw urlid string that will be used in generate_urlid().
* to make a clean url.
*
* @param object $user An object containing $username
* $firstname
* $lastname
* $preferredname (optional)
*
* @return string A raw urlid string
*/
function get_raw_user_urlid($user) {
if (!get_config('nousernames')) {
$urlid = $user->username;
}
else {
$urlid = display_default_name($user);
}
return $urlid;
}
/**
* Given an arbitrary string, generate a string containing only the allowed
* characters for use in a clean url.
......
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