Merge pull request #23203 from nextcloud/backport/23182/stable20

[stable20] Fix the user email issue while creating a user
This commit is contained in:
Morris Jobke 2020-10-05 23:03:48 +02:00 committed by GitHub
commit 20524cff33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 13 deletions

View File

@ -337,19 +337,21 @@ class UsersController extends AUserData {
}
// Send new user mail only if a mail is set
if ($email !== '' && $this->config->getAppValue('core', 'newUser.sendEmail', 'yes') === 'yes') {
if ($email !== '') {
$newUser->setEMailAddress($email);
try {
$emailTemplate = $this->newUserMailHelper->generateTemplate($newUser, $generatePasswordResetToken);
$this->newUserMailHelper->sendMail($newUser, $emailTemplate);
} catch (\Exception $e) {
// Mail could be failing hard or just be plain not configured
// Logging error as it is the hardest of the two
$this->logger->logException($e, [
'message' => "Unable to send the invitation mail to $email",
'level' => ILogger::ERROR,
'app' => 'ocs_api',
]);
if ($this->config->getAppValue('core', 'newUser.sendEmail', 'yes') === 'yes') {
try {
$emailTemplate = $this->newUserMailHelper->generateTemplate($newUser, $generatePasswordResetToken);
$this->newUserMailHelper->sendMail($newUser, $emailTemplate);
} catch (\Exception $e) {
// Mail could be failing hard or just be plain not configured
// Logging error as it is the hardest of the two
$this->logger->logException($e, [
'message' => "Unable to send the invitation mail to $email",
'level' => ILogger::ERROR,
'app' => 'ocs_api',
]);
}
}
}

View File

@ -500,9 +500,13 @@ class UsersControllerTest extends TestCase {
->method('userExists')
->with('NewUser')
->willReturn(false);
$newUser = $this->createMock(IUser::class);
$newUser->expects($this->once())
->method('setEMailAddress');
$this->userManager
->expects($this->once())
->method('createUser');
->method('createUser')
->willReturn($newUser);
$this->logger
->expects($this->once())
->method('info')