Skip to content

Commit

Permalink
MDL-80605 uploaduser: fixed username already existing when mail-matching
Browse files Browse the repository at this point in the history
  • Loading branch information
jbs1 committed Feb 19, 2024
1 parent 0f8e328 commit fbbb39c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions admin/tool/uploaduser/classes/process.php
Expand Up @@ -688,6 +688,17 @@ public function process_line(array $line) {
break;

case UU_USER_ADD_UPDATE:
if ($this->get_match_on_email()) {
if ($usersbyname = $DB->get_records('user', ['username' => $user->username])) {
foreach ($usersbyname as $userbyname) {
if (strtolower($userbyname->email) != strtolower($user->email)) {
$this->usersskipped++;
$this->upt->track('status', get_string('usernotaddedusernameexists', 'error'), 'warning');
$skip = true;
}
}
}
}
break;

case UU_USER_UPDATE:
Expand Down
22 changes: 22 additions & 0 deletions admin/tool/uploaduser/tests/behat/upload_users.feature
Expand Up @@ -296,3 +296,25 @@ Feature: Upload users
And I navigate to "Users > Accounts > Browse list of users" in site administration
And I should see "Bilbo Baggins"
And I should not see "Frodo Baggins"

@javascript
Scenario: Create a new user when matching them on email where where the username already exists
Given the following "users" exist:
| username | firstname | lastname | email |
| bilbob | Samwise | Gamgee | samwise@example.com |
| frodob | Frodeo | Baspins | frodo@example.com |
And I log in as "admin"
And I navigate to "Users > Accounts > Upload users" in site administration
When I upload "lib/tests/fixtures/upload_users_email_matching.csv" file to "File" filemanager
And I press "Upload users"
Then I should see "Upload users preview"
And I set the following fields to these values:
| Upload type | Add new and update existing users |
| Existing user details | Override with file |
| Match on email address | Yes |
And I press "Upload users"
And I should see "User not added - username already exists under a different email"
And I press "Continue"
And I navigate to "Users > Accounts > Browse list of users" in site administration
And I should see "Samwise Gamgee"
And I should see "Frodo Baggins"
1 change: 1 addition & 0 deletions lang/en/error.php
Expand Up @@ -614,6 +614,7 @@
$string['usernamelowercase'] = 'The username must be in lower case';
$string['usernotaddederror'] = 'User not added - error';
$string['usernotaddedregistered'] = 'User not added - already registered';
$string['usernotaddedusernameexists'] = 'User not added - username already exists under a different email';
$string['usernotavailable'] = 'The details of this user are not available to you';
$string['usernotdeletedadmin'] = 'User not deleted as administrator accounts cannot be deleted.';
$string['usernotdeleteddeleted'] = 'This user has already been deleted.';
Expand Down

0 comments on commit fbbb39c

Please sign in to comment.