Skip to content

Commit 20524cf

Browse files
authored
Merge pull request #23203 from nextcloud/backport/23182/stable20
[stable20] Fix the user email issue while creating a user
2 parents 4f5a24b + c998209 commit 20524cf

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

apps/provisioning_api/lib/Controller/UsersController.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -337,19 +337,21 @@ public function addUser(string $userid,
337337
}
338338

339339
// Send new user mail only if a mail is set
340-
if ($email !== '' && $this->config->getAppValue('core', 'newUser.sendEmail', 'yes') === 'yes') {
340+
if ($email !== '') {
341341
$newUser->setEMailAddress($email);
342-
try {
343-
$emailTemplate = $this->newUserMailHelper->generateTemplate($newUser, $generatePasswordResetToken);
344-
$this->newUserMailHelper->sendMail($newUser, $emailTemplate);
345-
} catch (\Exception $e) {
346-
// Mail could be failing hard or just be plain not configured
347-
// Logging error as it is the hardest of the two
348-
$this->logger->logException($e, [
349-
'message' => "Unable to send the invitation mail to $email",
350-
'level' => ILogger::ERROR,
351-
'app' => 'ocs_api',
352-
]);
342+
if ($this->config->getAppValue('core', 'newUser.sendEmail', 'yes') === 'yes') {
343+
try {
344+
$emailTemplate = $this->newUserMailHelper->generateTemplate($newUser, $generatePasswordResetToken);
345+
$this->newUserMailHelper->sendMail($newUser, $emailTemplate);
346+
} catch (\Exception $e) {
347+
// Mail could be failing hard or just be plain not configured
348+
// Logging error as it is the hardest of the two
349+
$this->logger->logException($e, [
350+
'message' => "Unable to send the invitation mail to $email",
351+
'level' => ILogger::ERROR,
352+
'app' => 'ocs_api',
353+
]);
354+
}
353355
}
354356
}
355357

apps/provisioning_api/tests/Controller/UsersControllerTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,13 @@ public function testAddUserSuccessfulGeneratePassword() {
500500
->method('userExists')
501501
->with('NewUser')
502502
->willReturn(false);
503+
$newUser = $this->createMock(IUser::class);
504+
$newUser->expects($this->once())
505+
->method('setEMailAddress');
503506
$this->userManager
504507
->expects($this->once())
505-
->method('createUser');
508+
->method('createUser')
509+
->willReturn($newUser);
506510
$this->logger
507511
->expects($this->once())
508512
->method('info')

0 commit comments

Comments
 (0)