]> source.dussan.org Git - nextcloud-server.git/commitdiff
add data from the users profile to the provisioning api
authorBjoern Schiessle <bjoern@schiessle.org>
Tue, 24 Jan 2017 13:07:52 +0000 (14:07 +0100)
committerBjoern Schiessle <bjoern@schiessle.org>
Tue, 24 Jan 2017 13:23:18 +0000 (14:23 +0100)
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
apps/provisioning_api/lib/Controller/UsersController.php
apps/provisioning_api/tests/Controller/UsersControllerTest.php

index 2e8a2ffe5ed2b34e27b45b7eabf5e7d32f16e8cf..e659b49443b728c6b3f7175e964cb2b838103de6 100644 (file)
@@ -29,6 +29,7 @@
 
 namespace OCA\Provisioning_API\Controller;
 
+use OC\Accounts\AccountManager;
 use \OC_Helper;
 use OCP\AppFramework\Http\DataResponse;
 use OCP\AppFramework\OCS\OCSException;
@@ -53,6 +54,8 @@ class UsersController extends OCSController {
        private $groupManager;
        /** @var IUserSession */
        private $userSession;
+       /** @var AccountManager */
+       private $accountManager;
        /** @var ILogger */
        private $logger;
 
@@ -63,6 +66,7 @@ class UsersController extends OCSController {
         * @param IConfig $config
         * @param IGroupManager $groupManager
         * @param IUserSession $userSession
+        * @param AccountManager $accountManager
         * @param ILogger $logger
         */
        public function __construct($appName,
@@ -71,6 +75,7 @@ class UsersController extends OCSController {
                                                                IConfig $config,
                                                                IGroupManager $groupManager,
                                                                IUserSession $userSession,
+                                                               AccountManager $accountManager,
                                                                ILogger $logger) {
                parent::__construct($appName, $request);
 
@@ -78,6 +83,7 @@ class UsersController extends OCSController {
                $this->config = $config;
                $this->groupManager = $groupManager;
                $this->userSession = $userSession;
+               $this->accountManager = $accountManager;
                $this->logger = $logger;
        }
 
@@ -107,7 +113,7 @@ class UsersController extends OCSController {
                        }
 
                        if($offset === null) {
-                               $offset = 0; 
+                               $offset = 0;
                        }
 
                        $users = [];
@@ -159,7 +165,7 @@ class UsersController extends OCSController {
                                throw new OCSException('no group specified (required for subadmins)', 106);
                        }
                }
-               
+
                try {
                        $newUser = $this->userManager->createUser($userid, $password);
                        $this->logger->info('Successful addUser call with userid: '.$userid, ['app' => 'ocs_api']);
@@ -209,10 +215,16 @@ class UsersController extends OCSController {
                        }
                }
 
+               $userAccount = $this->accountManager->getUser($targetUserObject);
+
                // Find the data
                $data['quota'] = $this->fillStorageInfo($userId);
                $data['email'] = $targetUserObject->getEMailAddress();
                $data['displayname'] = $targetUserObject->getDisplayName();
+               $data['phone'] = $userAccount[\OC\Accounts\AccountManager::PROPERTY_PHONE]['value'];
+               $data['address'] = $userAccount[\OC\Accounts\AccountManager::PROPERTY_ADDRESS]['value'];
+               $data['webpage'] = $userAccount[\OC\Accounts\AccountManager::PROPERTY_WEBSITE]['value'];
+               $data['twitter'] = $userAccount[\OC\Accounts\AccountManager::PROPERTY_TWITTER]['value'];
 
                return new DataResponse($data);
        }
@@ -436,7 +448,7 @@ class UsersController extends OCSController {
                                throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
                        }
                }
-               
+
        }
 
        /**
index 4d3da5fd33af77b4cd9e0e15d8f3169f506adb3f..1565407b8395ef05df908743abeb4f689019806c 100644 (file)
@@ -29,6 +29,7 @@
 
 namespace OCA\Provisioning_API\Tests\Controller;
 
+use OC\Accounts\AccountManager;
 use OCA\Provisioning_API\Controller\UsersController;
 use OCP\AppFramework\Http\DataResponse;
 use OCP\IGroup;
@@ -41,7 +42,7 @@ use Test\TestCase as OriginalTest;
 use OCP\ILogger;
 
 class UsersControllerTest extends OriginalTest {
-       
+
        /** @var IUserManager | PHPUnit_Framework_MockObject_MockObject */
        protected $userManager;
        /** @var IConfig | PHPUnit_Framework_MockObject_MockObject */
@@ -54,6 +55,8 @@ class UsersControllerTest extends OriginalTest {
        protected $logger;
        /** @var UsersController | PHPUnit_Framework_MockObject_MockObject */
        protected $api;
+       /** @var  AccountManager | PHPUnit_Framework_MockObject_MockObject */
+       protected $accountManager;
 
        protected function tearDown() {
                parent::tearDown();
@@ -80,6 +83,9 @@ class UsersControllerTest extends OriginalTest {
                $request = $this->getMockBuilder('OCP\IRequest')
                        ->disableOriginalConstructor()
                        ->getMock();
+               $this->accountManager = $this->getMockBuilder(AccountManager::class)
+                       ->disableOriginalConstructor()
+                       ->getMock();
                $this->api = $this->getMockBuilder('OCA\Provisioning_API\Controller\UsersController')
                        ->setConstructorArgs([
                                'provisioning_api',
@@ -88,6 +94,7 @@ class UsersControllerTest extends OriginalTest {
                                $this->config,
                                $this->groupManager,
                                $this->userSession,
+                               $this->accountManager,
                                $this->logger,
                        ])
                        ->setMethods(['fillStorageInfo'])
@@ -652,6 +659,16 @@ class UsersControllerTest extends OriginalTest {
                        ->method('isAdmin')
                        ->with('admin')
                        ->will($this->returnValue(true));
+               $this->accountManager->expects($this->any())->method('getUser')
+                       ->with($targetUser)
+                       ->willReturn(
+                               [
+                                       AccountManager::PROPERTY_ADDRESS => ['value' => 'address'],
+                                       AccountManager::PROPERTY_PHONE => ['value' => 'phone'],
+                                       AccountManager::PROPERTY_TWITTER => ['value' => 'twitter'],
+                                       AccountManager::PROPERTY_WEBSITE => ['value' => 'website'],
+                               ]
+                       );
                $this->config
                        ->expects($this->at(0))
                        ->method('getUserValue')
@@ -672,6 +689,10 @@ class UsersControllerTest extends OriginalTest {
                        'quota' => ['DummyValue'],
                        'email' => 'demo@owncloud.org',
                        'displayname' => 'Demo User',
+                       'phone' => 'phone',
+                       'address' => 'address',
+                       'webpage' => 'website',
+                       'twitter' => 'twitter'
                ];
                $this->assertEquals($expected, $this->api->getUser('UserToGet')->getData());
        }
@@ -731,12 +752,26 @@ class UsersControllerTest extends OriginalTest {
                        ->expects($this->once())
                        ->method('getDisplayName')
                        ->will($this->returnValue('Demo User'));
+               $this->accountManager->expects($this->any())->method('getUser')
+                       ->with($targetUser)
+                       ->willReturn(
+                               [
+                                       AccountManager::PROPERTY_ADDRESS => ['value' => 'address'],
+                                       AccountManager::PROPERTY_PHONE => ['value' => 'phone'],
+                                       AccountManager::PROPERTY_TWITTER => ['value' => 'twitter'],
+                                       AccountManager::PROPERTY_WEBSITE => ['value' => 'website'],
+                               ]
+                       );
 
                $expected = [
                        'enabled' => 'true',
                        'quota' => ['DummyValue'],
                        'email' => 'demo@owncloud.org',
                        'displayname' => 'Demo User',
+                       'phone' => 'phone',
+                       'address' => 'address',
+                       'webpage' => 'website',
+                       'twitter' => 'twitter'
                ];
                $this->assertEquals($expected, $this->api->getUser('UserToGet')->getData());
        }
@@ -837,11 +872,25 @@ class UsersControllerTest extends OriginalTest {
                        ->expects($this->once())
                        ->method('getEMailAddress')
                        ->will($this->returnValue('subadmin@owncloud.org'));
+               $this->accountManager->expects($this->any())->method('getUser')
+                       ->with($targetUser)
+                       ->willReturn(
+                               [
+                                       AccountManager::PROPERTY_ADDRESS => ['value' => 'address'],
+                                       AccountManager::PROPERTY_PHONE => ['value' => 'phone'],
+                                       AccountManager::PROPERTY_TWITTER => ['value' => 'twitter'],
+                                       AccountManager::PROPERTY_WEBSITE => ['value' => 'website'],
+                               ]
+                       );
 
                $expected = [
                        'quota' => ['DummyValue'],
                        'email' => 'subadmin@owncloud.org',
                        'displayname' => 'Subadmin User',
+                       'phone' => 'phone',
+                       'address' => 'address',
+                       'webpage' => 'website',
+                       'twitter' => 'twitter'
                ];
                $this->assertEquals($expected, $this->api->getUser('subadmin')->getData());
        }