]> source.dussan.org Git - nextcloud-server.git/commitdiff
add groups to user info output 3418/head
authorBjoern Schiessle <bjoern@schiessle.org>
Thu, 9 Feb 2017 15:12:57 +0000 (16:12 +0100)
committerBjoern Schiessle <bjoern@schiessle.org>
Thu, 9 Feb 2017 15:23:10 +0000 (16: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 1e8a767b33a497114ee2497b80a4ed399b8be8ca..766775dfdbed79946e58115150acd9d6a6ca5860 100644 (file)
@@ -252,6 +252,11 @@ class UsersController extends OCSController {
                }
 
                $userAccount = $this->accountManager->getUser($targetUserObject);
+               $groups = $this->groupManager->getUserGroups($targetUserObject);
+               $gids = [];
+               foreach ($groups as $group) {
+                       $gids[] = $group->getDisplayName();
+               }
 
                // Find the data
                $data['id'] = $targetUserObject->getUID();
@@ -262,6 +267,7 @@ class UsersController extends OCSController {
                $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'];
+               $data['groups'] = $gids;
 
                return $data;
        }
index a3e5bf6fde6a077ab537c3eb12f83e64e15076b5..a049b15bf03b5129d22333672ca2c1f8b00ed4e6 100644 (file)
@@ -635,6 +635,9 @@ class UsersControllerTest extends OriginalTest {
        }
 
        public function testGetUserDataAsAdmin() {
+               $group = $this->getMockBuilder(IGroup::class)
+                       ->disableOriginalConstructor()
+                       ->getMock();
                $loggedInUser = $this->getMockBuilder('OCP\IUser')
                        ->disableOriginalConstructor()
                        ->getMock();
@@ -662,6 +665,19 @@ class UsersControllerTest extends OriginalTest {
                        ->method('isAdmin')
                        ->with('admin')
                        ->will($this->returnValue(true));
+               $this->groupManager
+                       ->expects($this->any())
+                       ->method('getUserGroups')
+                       ->willReturn([$group, $group, $group]);
+               $group->expects($this->at(0))
+                       ->method('getDisplayName')
+                       ->willReturn('group0');
+               $group->expects($this->at(1))
+                       ->method('getDisplayName')
+                       ->willReturn('group1');
+               $group->expects($this->at(2))
+                       ->method('getDisplayName')
+                       ->willReturn('group2');
                $this->accountManager->expects($this->any())->method('getUser')
                        ->with($targetUser)
                        ->willReturn(
@@ -700,7 +716,8 @@ class UsersControllerTest extends OriginalTest {
                        'phone' => 'phone',
                        'address' => 'address',
                        'webpage' => 'website',
-                       'twitter' => 'twitter'
+                       'twitter' => 'twitter',
+                       'groups' => ['group0', 'group1', 'group2']
                ];
                $this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UserToGet']));
        }
@@ -734,6 +751,10 @@ class UsersControllerTest extends OriginalTest {
                        ->method('isAdmin')
                        ->with('subadmin')
                        ->will($this->returnValue(false));
+               $this->groupManager
+                       ->expects($this->any())
+                       ->method('getUserGroups')
+                       ->willReturn([]);
                $subAdminManager = $this->getMockBuilder('OC\SubAdmin')
                        ->disableOriginalConstructor()
                        ->getMock();
@@ -784,7 +805,8 @@ class UsersControllerTest extends OriginalTest {
                        'phone' => 'phone',
                        'address' => 'address',
                        'webpage' => 'website',
-                       'twitter' => 'twitter'
+                       'twitter' => 'twitter',
+                       'groups' => []
                ];
                $this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UserToGet']));
        }
@@ -872,6 +894,10 @@ class UsersControllerTest extends OriginalTest {
                        ->expects($this->once())
                        ->method('getSubAdmin')
                        ->will($this->returnValue($subAdminManager));
+               $this->groupManager
+                       ->expects($this->any())
+                       ->method('getUserGroups')
+                       ->willReturn([]);
                $this->api
                        ->expects($this->once())
                        ->method('fillStorageInfo')
@@ -908,7 +934,8 @@ class UsersControllerTest extends OriginalTest {
                        'phone' => 'phone',
                        'address' => 'address',
                        'webpage' => 'website',
-                       'twitter' => 'twitter'
+                       'twitter' => 'twitter',
+                       'groups' => []
                ];
                $this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['subadmin']));
        }