Fix the user email issue while creating a user

When the user is created, the provisioning api
was not adding the email address of the user
when provided if the `send email to new user`
is not set.

Signed-off-by: Sujith Haridasan <sujith.h@gmail.com>
This commit is contained in:
Sujith Haridasan 2020-10-05 16:09:00 +05:30 committed by backportbot[bot]
parent 4f5a24bb50
commit c998209ec1
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 // 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); $newUser->setEMailAddress($email);
try { if ($this->config->getAppValue('core', 'newUser.sendEmail', 'yes') === 'yes') {
$emailTemplate = $this->newUserMailHelper->generateTemplate($newUser, $generatePasswordResetToken); try {
$this->newUserMailHelper->sendMail($newUser, $emailTemplate); $emailTemplate = $this->newUserMailHelper->generateTemplate($newUser, $generatePasswordResetToken);
} catch (\Exception $e) { $this->newUserMailHelper->sendMail($newUser, $emailTemplate);
// Mail could be failing hard or just be plain not configured } catch (\Exception $e) {
// Logging error as it is the hardest of the two // Mail could be failing hard or just be plain not configured
$this->logger->logException($e, [ // Logging error as it is the hardest of the two
'message' => "Unable to send the invitation mail to $email", $this->logger->logException($e, [
'level' => ILogger::ERROR, 'message' => "Unable to send the invitation mail to $email",
'app' => 'ocs_api', 'level' => ILogger::ERROR,
]); 'app' => 'ocs_api',
]);
}
} }
} }

View File

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