Skip to content

Commit

Permalink
Merge branch 'MDL-52831-master-emptynames' of git://github.com/mudrd8…
Browse files Browse the repository at this point in the history
…mz/moodle
  • Loading branch information
David Monllao committed Feb 1, 2016
2 parents c9d91bb + 1ccd813 commit b831527
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/classes/task/delete_incomplete_users_task.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public function execute() {
if (isguestuser($user) or is_siteadmin($user)) {
continue;
}
if ($user->lastname !== '' and $user->firstname !== '' and $user->email !== '') {
// This can happen on MySQL - see MDL-52831.
continue;
}
delete_user($user);
mtrace(" Deleted not fully setup user $user->username ($user->id)");
}
Expand Down
5 changes: 5 additions & 0 deletions login/signup_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ function definition() {
function definition_after_data(){
$mform = $this->_form;
$mform->applyFilter('username', 'trim');

// Trim required name fields.
foreach (useredit_get_required_name_fields() as $field) {
$mform->applyFilter($field, 'trim');
}
}

function validation($data, $files) {
Expand Down
5 changes: 5 additions & 0 deletions user/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public function definition_after_data() {
$mform = $this->_form;
$userid = $mform->getElementValue('id');

// Trim required name fields.
foreach (useredit_get_required_name_fields() as $field) {
$mform->applyFilter($field, 'trim');
}

if ($user = $DB->get_record('user', array('id' => $userid))) {

// Remove description.
Expand Down
6 changes: 6 additions & 0 deletions user/editadvanced_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ public function definition_after_data() {
global $USER, $CFG, $DB, $OUTPUT;

$mform = $this->_form;

// Trim required name fields.
foreach (useredit_get_required_name_fields() as $field) {
$mform->applyFilter($field, 'trim');
}

if ($userid = $mform->getElementValue('id')) {
$user = $DB->get_record('user', array('id' => $userid));
} else {
Expand Down
8 changes: 7 additions & 1 deletion user/editlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,17 @@ function useredit_shared_definition(&$mform, $editoroptions, $filemanageroptions
}

$strrequired = get_string('required');
$stringman = get_string_manager();

// Add the necessary names.
foreach (useredit_get_required_name_fields() as $fullname) {
$mform->addElement('text', $fullname, get_string($fullname), 'maxlength="100" size="30"');
$mform->addRule($fullname, $strrequired, 'required', null, 'client');
if ($stringman->string_exists('missing'.$fullname, 'core')) {
$strmissingfield = get_string('missing'.$fullname, 'core');
} else {
$strmissingfield = $strrequired;
}
$mform->addRule($fullname, $strmissingfield, 'required', null, 'client');
$mform->setType($fullname, PARAM_NOTAGS);
}

Expand Down
50 changes: 50 additions & 0 deletions user/tests/behat/name_fields.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@core @core_user
Feature: Both first name and surname are always available for every user
In order to easily identify and display users on Moodle pages
As any user
I need to rely on both first name and surname are always available

Scenario: Attempting to self-register as a new user with empty names
Given the following config values are set as admin:
| registerauth | email |
| passwordpolicy | 0 |
And I am on site homepage
And I follow "Log in"
And I follow "New Account"
When I set the following fields to these values:
| Username | mrwhitespace |
| Password | Gue$$m3ifY0uC&n |
| Email address | mrwhitespace@nas.ty |
| Email (again) | mrwhitespace@nas.ty |
And I set the field "First name" to " "
And I set the field "Surname" to " "
And I click on "Create my new account" "button"
Then I should see "Missing given name"
And I should see "Missing surname"

Scenario: Attempting to change own names to whitespace
Given the following "users" exist:
| username | firstname | lastname | email |
| foobar | Foo | Bar | foo@bar.com |
And I log in as "foobar"
And I follow "Profile" in the user menu
And I follow "Edit profile"
When I set the field "First name" to " "
And I set the field "Surname" to " "
And I click on "Update profile" "button"
Then I should see "Missing given name"
And I should see "Missing surname"

Scenario: Attempting to change someone else's names to whitespace
Given the following "users" exist:
| username | firstname | lastname | email |
| foobar | Foo | Bar | foo@bar.com |
And I log in as "admin"
And I navigate to "Browse list of users" node in "Site administration > Users > Accounts"
And I follow "Foo Bar"
And I follow "Edit profile"
When I set the field "First name" to " "
And I set the field "Surname" to " "
And I click on "Update profile" "button"
Then I should see "Missing given name"
And I should see "Missing surname"

0 comments on commit b831527

Please sign in to comment.