]> source.dussan.org Git - nextcloud-server.git/commitdiff
make sure that we only update the email address if it really changed 2484/head
authorBjoern Schiessle <bjoern@schiessle.org>
Fri, 2 Dec 2016 15:54:17 +0000 (16:54 +0100)
committerBjoern Schiessle <bjoern@schiessle.org>
Fri, 2 Dec 2016 17:07:08 +0000 (18:07 +0100)
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
settings/Controller/UsersController.php
tests/Settings/Controller/UsersControllerTest.php

index 20440e6d395bc8a4f5f762657fad76515e6fecea..28b8d2648d99de90358fa370dd9dba02a0417ee1 100644 (file)
@@ -605,6 +605,7 @@ class UsersController extends Controller {
                // keep the user back-end up-to-date with the latest display name and email
                // address
                $oldDisplayName = $user->getDisplayName();
+               $oldDisplayName = is_null($oldDisplayName) ? '' : $oldDisplayName;
                if (isset($data[AccountManager::PROPERTY_DISPLAYNAME]['value'])
                        && $oldDisplayName !== $data[AccountManager::PROPERTY_DISPLAYNAME]['value']
                ) {
@@ -615,6 +616,7 @@ class UsersController extends Controller {
                }
 
                $oldEmailAddress = $user->getEMailAddress();
+               $oldEmailAddress = is_null($oldEmailAddress) ? '' : $oldEmailAddress;
                if (isset($data[AccountManager::PROPERTY_EMAIL]['value'])
                        && $oldEmailAddress !== $data[AccountManager::PROPERTY_EMAIL]['value']
                ) {
index 69082a7929cbf5a4ff2cfab2ecb292e59b918dd3..b85667740f7c4908e23a7d04a13f8c8a796b01f6 100644 (file)
@@ -2107,20 +2107,22 @@ class UsersControllerTest extends \Test\TestCase {
                $user->method('getEMailAddress')->willReturn($oldEmailAddress);
                $user->method('canChangeDisplayName')->willReturn(true);
 
-               if ($data[AccountManager::PROPERTY_EMAIL]['value'] !== $oldEmailAddress) {
+               if ($data[AccountManager::PROPERTY_EMAIL]['value'] === $oldEmailAddress ||
+               $oldEmailAddress === null && $data[AccountManager::PROPERTY_EMAIL]['value'] === '') {
+                       $user->expects($this->never())->method('setEMailAddress');
+               } else {
                        $user->expects($this->once())->method('setEMailAddress')
                                ->with($data[AccountManager::PROPERTY_EMAIL]['value'])
                                ->willReturn(true);
-               } else {
-                       $user->expects($this->never())->method('setEMailAddress');
                }
 
-               if ($data[AccountManager::PROPERTY_DISPLAYNAME]['value'] !== $oldDisplayName) {
+               if ($data[AccountManager::PROPERTY_DISPLAYNAME]['value'] === $oldDisplayName ||
+                       $oldDisplayName === null && $data[AccountManager::PROPERTY_DISPLAYNAME]['value'] === '') {
+                       $user->expects($this->never())->method('setDisplayName');
+               } else {
                        $user->expects($this->once())->method('setDisplayName')
                                ->with($data[AccountManager::PROPERTY_DISPLAYNAME]['value'])
                                ->willReturn(true);
-               } else {
-                       $user->expects($this->never())->method('setDisplayName');
                }
 
                $this->accountManager->expects($this->once())->method('updateUser')
@@ -2162,7 +2164,23 @@ class UsersControllerTest extends \Test\TestCase {
                                ],
                                'john@example.com',
                                'john New doe'
-                       ]
+                       ],
+                       [
+                               [
+                                       AccountManager::PROPERTY_EMAIL => ['value' => ''],
+                                       AccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
+                               ],
+                               null,
+                               'john New doe'
+                       ],
+                       [
+                               [
+                                       AccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
+                                       AccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
+                               ],
+                               'john@example.com',
+                               null
+                       ],
 
                ];
        }
@@ -2274,6 +2292,7 @@ class UsersControllerTest extends \Test\TestCase {
                        ->with(
                                $this->equalTo($mailAddress)
                        );
+               $user->method('getEMailAddress')->willReturn('oldEmailAddress');
                $this->mailer
                        ->expects($this->any())
                        ->method('validateMailAddress')