]> source.dussan.org Git - nextcloud-server.git/commitdiff
Introduce \OCP\IUser::getEMailAddress()
authorThomas Müller <thomas.mueller@tmit.eu>
Tue, 24 Nov 2015 22:28:24 +0000 (23:28 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Wed, 25 Nov 2015 21:23:34 +0000 (22:23 +0100)
apps/dav/lib/connector/sabre/principal.php
apps/dav/tests/unit/connector/sabre/principal.php
lib/private/user/user.php
lib/public/iuser.php
tests/lib/contacts/localadressbook.php

index cd3b14b68412c2a37b1a052ec991189c87989a3f..cc9c1c40d59cebb7674c94fe54d5dacec4856a83 100644 (file)
@@ -203,7 +203,7 @@ class Principal implements \Sabre\DAVACL\PrincipalBackend\BackendInterface {
                                '{DAV:}displayname' => is_null($displayName) ? $userId : $displayName,
                ];
 
-               $email = $this->config->getUserValue($user->getUID(), 'settings', 'email');
+               $email = $user->getEMailAddress();
                if (!empty($email)) {
                        $principal['{http://sabredav.org/ns}email-address'] = $email;
                        return $principal;
index 1d7721c546dd2172450d5d9d940fc6bc44247d76..9a6ae545b587b68901b2bcc3ff5ddcbfda299d9f 100644 (file)
@@ -41,34 +41,32 @@ class Principal extends \Test\TestCase {
                $fooUser = $this->getMockBuilder('\OC\User\User')
                        ->disableOriginalConstructor()->getMock();
                $fooUser
-                               ->expects($this->exactly(2))
+                               ->expects($this->exactly(1))
                                ->method('getUID')
                                ->will($this->returnValue('foo'));
                $fooUser
                                ->expects($this->exactly(1))
                                ->method('getDisplayName')
                                ->will($this->returnValue('Dr. Foo-Bar'));
+               $fooUser
+                               ->expects($this->exactly(1))
+                               ->method('getEMailAddress')
+                               ->will($this->returnValue(''));
                $barUser = $this->getMockBuilder('\OC\User\User')
                        ->disableOriginalConstructor()->getMock();
                $barUser
-                       ->expects($this->exactly(2))
+                       ->expects($this->exactly(1))
                        ->method('getUID')
                        ->will($this->returnValue('bar'));
+               $barUser
+                               ->expects($this->exactly(1))
+                               ->method('getEMailAddress')
+                               ->will($this->returnValue('bar@owncloud.org'));
                $this->userManager
                        ->expects($this->once())
                        ->method('search')
                        ->with('')
                        ->will($this->returnValue([$fooUser, $barUser]));
-               $this->config
-                       ->expects($this->at(0))
-                       ->method('getUserValue')
-                       ->with('foo', 'settings', 'email')
-                       ->will($this->returnValue(''));
-               $this->config
-                       ->expects($this->at(1))
-                       ->method('getUserValue')
-                       ->with('bar', 'settings', 'email')
-                       ->will($this->returnValue('bar@owncloud.org'));
 
                $expectedResponse = [
                        0 => [
@@ -100,7 +98,7 @@ class Principal extends \Test\TestCase {
                $fooUser = $this->getMockBuilder('\OC\User\User')
                        ->disableOriginalConstructor()->getMock();
                $fooUser
-                       ->expects($this->exactly(2))
+                       ->expects($this->exactly(1))
                        ->method('getUID')
                        ->will($this->returnValue('foo'));
                $this->userManager
@@ -108,11 +106,6 @@ class Principal extends \Test\TestCase {
                        ->method('get')
                        ->with('foo')
                        ->will($this->returnValue($fooUser));
-               $this->config
-                       ->expects($this->once())
-                       ->method('getUserValue')
-                       ->with('foo', 'settings', 'email')
-                       ->will($this->returnValue(''));
 
                $expectedResponse = [
                        'uri' => 'principals/users/foo',
@@ -126,19 +119,18 @@ class Principal extends \Test\TestCase {
                $fooUser = $this->getMockBuilder('\OC\User\User')
                        ->disableOriginalConstructor()->getMock();
                $fooUser
-                       ->expects($this->exactly(2))
-                       ->method('getUID')
-                       ->will($this->returnValue('foo'));
+                               ->expects($this->exactly(1))
+                               ->method('getEMailAddress')
+                               ->will($this->returnValue('foo@owncloud.org'));
+               $fooUser
+                               ->expects($this->exactly(1))
+                               ->method('getUID')
+                               ->will($this->returnValue('foo'));
                $this->userManager
                        ->expects($this->once())
                        ->method('get')
                        ->with('foo')
                        ->will($this->returnValue($fooUser));
-               $this->config
-                       ->expects($this->once())
-                       ->method('getUserValue')
-                       ->with('foo', 'settings', 'email')
-                       ->will($this->returnValue('foo@owncloud.org'));
 
                $expectedResponse = [
                        'uri' => 'principals/users/foo',
@@ -164,7 +156,7 @@ class Principal extends \Test\TestCase {
                $fooUser = $this->getMockBuilder('\OC\User\User')
                        ->disableOriginalConstructor()->getMock();
                $fooUser
-                       ->expects($this->exactly(2))
+                       ->expects($this->exactly(1))
                        ->method('getUID')
                        ->will($this->returnValue('foo'));
                $this->userManager
@@ -172,11 +164,6 @@ class Principal extends \Test\TestCase {
                        ->method('get')
                        ->with('foo')
                        ->will($this->returnValue($fooUser));
-               $this->config
-                       ->expects($this->once())
-                       ->method('getUserValue')
-                       ->with('foo', 'settings', 'email')
-                       ->will($this->returnValue('foo@owncloud.org'));
 
                $response = $this->connector->getGroupMemberSet('principals/users/foo');
                $this->assertSame(['principals/users/foo'], $response);
@@ -200,7 +187,7 @@ class Principal extends \Test\TestCase {
                $fooUser = $this->getMockBuilder('\OC\User\User')
                        ->disableOriginalConstructor()->getMock();
                $fooUser
-                       ->expects($this->exactly(2))
+                       ->expects($this->exactly(1))
                        ->method('getUID')
                        ->will($this->returnValue('foo'));
                $this->userManager
@@ -208,11 +195,6 @@ class Principal extends \Test\TestCase {
                        ->method('get')
                        ->with('foo')
                        ->will($this->returnValue($fooUser));
-               $this->config
-                       ->expects($this->once())
-                       ->method('getUserValue')
-                       ->with('foo', 'settings', 'email')
-                       ->will($this->returnValue('foo@owncloud.org'));
 
                $expectedResponse = [
                        'principals/users/foo/calendar-proxy-read',
index 28b66d7f5bae5bbb08615194d0352753a2ad2603..2740b25d5d36162a340e9b3aec1da65fc658e936 100644 (file)
@@ -306,4 +306,14 @@ class User implements IUser {
                        $this->config->setUserValue($this->uid, 'core', 'enabled', $enabled);
                }
        }
+
+       /**
+        * get the users email address
+        *
+        * @return string|null
+        * @since 9.0.0
+        */
+       public function getEMailAddress() {
+               return $this->config->getUserValue($this->uid, 'settings', 'email');
+       }
 }
index 6cbcfbf23120098c407c5c790dac9e723ce54bc8..1e52cd590360f403e3ff442b68a08cc55c65ced1 100644 (file)
@@ -144,4 +144,12 @@ interface IUser {
         * @since 8.0.0
         */
        public function setEnabled($enabled);
+
+       /**
+        * get the users email address
+        *
+        * @return string|null
+        * @since 9.0.0
+        */
+       public function getEMailAddress();
 }
index a34d45bf3d08c96fa6b4e5a74750173be065acb8..6bfcf3d890a7f4dc3a81f7fbc71f19fb19d93df1 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 use OC\Contacts\LocalAddressBook;
+use OCP\IUser;
 
 /**
  * ownCloud
@@ -44,7 +45,7 @@ class Test_LocalAddressBook extends \Test\TestCase
 }
 
 
-class SimpleUserForTesting implements \OCP\IUser {
+class SimpleUserForTesting implements IUser {
 
        public function __construct($uid, $displayName) {
 
@@ -95,4 +96,8 @@ class SimpleUserForTesting implements \OCP\IUser {
 
        public function setEnabled($enabled) {
        }
+
+       public function getEMailAddress() {
+               // TODO: Implement getEMailAddress() method.
+       }
 }