mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
Merge branch 'MDL-52831-master-emptynames' of git://github.com/mudrd8mz/moodle
This commit is contained in:
commit
b831527ce8
@ -59,6 +59,10 @@ class delete_incomplete_users_task extends scheduled_task {
|
||||
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)");
|
||||
}
|
||||
|
@ -112,6 +112,11 @@ class login_signup_form extends moodleform {
|
||||
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) {
|
||||
|
@ -99,6 +99,11 @@ class user_edit_form extends moodleform {
|
||||
$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.
|
||||
|
@ -140,6 +140,12 @@ class user_editadvanced_form extends moodleform {
|
||||
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 {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
50
user/tests/behat/name_fields.feature
Normal file
50
user/tests/behat/name_fields.feature
Normal file
@ -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"
|
Loading…
x
Reference in New Issue
Block a user