]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix the user email issue while creating a user 23203/head
authorSujith Haridasan <sujith.h@gmail.com>
Mon, 5 Oct 2020 10:39:00 +0000 (16:09 +0530)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Mon, 5 Oct 2020 19:34:24 +0000 (19:34 +0000)
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>
apps/provisioning_api/lib/Controller/UsersController.php
apps/provisioning_api/tests/Controller/UsersControllerTest.php

index 14e835ce338da4688f6c5a31085ae34b1c2e0ecc..5903292ed6b3827cb0d8e613c0621f06cd193d58 100644 (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',
+                                               ]);
+                                       }
                                }
                        }
 
index fec7fc9f1350b43d90e03987bac363c3bb617d2b..d508670d4f6ed7cb33331147e05625299b7dbfda 100644 (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')