]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix filtering for users when $gid is empty
authorLukas Reschke <lukas@owncloud.com>
Sun, 18 Jan 2015 17:31:03 +0000 (18:31 +0100)
committerLukas Reschke <lukas@owncloud.com>
Sun, 18 Jan 2015 17:31:03 +0000 (18:31 +0100)
Previously when $gid was empty the users were not filtered at all. Rendering the search function in the user management pretty useless.

Fixes itself

settings/controller/userscontroller.php
tests/settings/controller/userscontrollertest.php

index 844ed4759e3f06f185233d7f32c850356a2aea75..1be2f4db9b9af90e25f2dec67cbbd14538e55378 100644 (file)
@@ -161,7 +161,7 @@ class UsersController extends Controller {
                        if($gid !== '') {
                                $batch = $this->getUsersForUID($this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset));
                        } else {
-                               $batch = $this->userManager->search('', $limit, $offset);
+                               $batch = $this->userManager->search($pattern, $limit, $offset);
                        }
 
                        foreach ($batch as $user) {
index 41622737027515488dfb3b11977ac312e425826c..c6506ee440bf9ab800c1a39948dd3c33bfaba9c8 100644 (file)
@@ -130,6 +130,7 @@ class UsersControllerTest extends \Test\TestCase {
                $this->container['GroupManager']
                        ->expects($this->once())
                        ->method('displayNamesInGroup')
+                       ->with('gid', 'pattern')
                        ->will($this->returnValue(array('foo' => 'M. Foo', 'admin' => 'S. Admin', 'bar' => 'B. Ar')));
                $this->container['GroupManager']
                        ->expects($this->exactly(3))
@@ -198,6 +199,132 @@ class UsersControllerTest extends \Test\TestCase {
                $this->assertEquals($expectedResponse, $response);
        }
 
+       /**
+        * TODO: Since the function uses the static OC_Subadmin class it can't be mocked
+        * to test for subadmins. Thus the test always assumes you have admin permissions...
+        */
+       public function testIndexWithSearch() {
+               $foo = $this->getMockBuilder('\OC\User\User')
+                       ->disableOriginalConstructor()->getMock();
+               $foo
+                       ->expects($this->exactly(4))
+                       ->method('getUID')
+                       ->will($this->returnValue('foo'));
+               $foo
+                       ->expects($this->once())
+                       ->method('getDisplayName')
+                       ->will($this->returnValue('M. Foo'));
+               $foo
+                       ->method('getLastLogin')
+                       ->will($this->returnValue(500));
+               $foo
+                       ->method('getHome')
+                       ->will($this->returnValue('/home/foo'));
+               $foo
+                       ->expects($this->once())
+                       ->method('getBackendClassName')
+                       ->will($this->returnValue('OC_User_Database'));
+               $admin = $this->getMockBuilder('\OC\User\User')
+                       ->disableOriginalConstructor()->getMock();
+               $admin
+                       ->expects($this->exactly(4))
+                       ->method('getUID')
+                       ->will($this->returnValue('admin'));
+               $admin
+                       ->expects($this->once())
+                       ->method('getDisplayName')
+                       ->will($this->returnValue('S. Admin'));
+               $admin
+                       ->expects($this->once())
+                       ->method('getLastLogin')
+                       ->will($this->returnValue(12));
+               $admin
+                       ->expects($this->once())
+                       ->method('getHome')
+                       ->will($this->returnValue('/home/admin'));
+               $admin
+                       ->expects($this->once())
+                       ->method('getBackendClassName')
+                       ->will($this->returnValue('OC_User_Dummy'));
+               $bar = $this->getMockBuilder('\OC\User\User')
+                       ->disableOriginalConstructor()->getMock();
+               $bar
+                       ->expects($this->exactly(4))
+                       ->method('getUID')
+                       ->will($this->returnValue('bar'));
+               $bar
+                       ->expects($this->once())
+                       ->method('getDisplayName')
+                       ->will($this->returnValue('B. Ar'));
+               $bar
+                       ->method('getLastLogin')
+                       ->will($this->returnValue(3999));
+               $bar
+                       ->method('getHome')
+                       ->will($this->returnValue('/home/bar'));
+               $bar
+                       ->expects($this->once())
+                       ->method('getBackendClassName')
+                       ->will($this->returnValue('OC_User_Dummy'));
+
+               $this->container['UserManager']
+                       ->expects($this->once())
+                       ->method('search')
+                       ->with('pattern', 10, 0)
+                       ->will($this->returnValue([$foo, $admin, $bar]));
+               $this->container['GroupManager']
+                       ->expects($this->exactly(3))
+                       ->method('getUserGroupIds')
+                       ->will($this->onConsecutiveCalls(array('Users', 'Support'), array('admins', 'Support'), array('External Users')));
+               $this->container['Config']
+                       ->expects($this->exactly(6))
+                       ->method('getUserValue')
+                       ->will($this->onConsecutiveCalls(1024, 'foo@bar.com',
+                               404, 'admin@bar.com',
+                               2323, 'bar@dummy.com'));
+
+               $expectedResponse = new DataResponse(
+                       array(
+                               0 => array(
+                                       'name' => 'foo',
+                                       'displayname' => 'M. Foo',
+                                       'groups' => array('Users', 'Support'),
+                                       'subadmin' => array(),
+                                       'quota' => 1024,
+                                       'storageLocation' => '/home/foo',
+                                       'lastLogin' => 500,
+                                       'backend' => 'OC_User_Database',
+                                       'email' => 'foo@bar.com'
+                               ),
+                               1 => array(
+                                       'name' => 'admin',
+                                       'displayname' => 'S. Admin',
+                                       'groups' => array('admins', 'Support'),
+                                       'subadmin' => array(),
+                                       'quota' => 404,
+                                       'storageLocation' => '/home/admin',
+                                       'lastLogin' => 12,
+                                       'backend' => 'OC_User_Dummy',
+                                       'email' => 'admin@bar.com'
+                               ),
+                               2 => array(
+                                       'name' => 'bar',
+                                       'displayname' => 'B. Ar',
+                                       'groups' => array('External Users'),
+                                       'subadmin' => array(),
+                                       'quota' => 2323,
+                                       'storageLocation' => '/home/bar',
+                                       'lastLogin' => 3999,
+                                       'backend' => 'OC_User_Dummy',
+                                       'email' => 'bar@dummy.com'
+                               ),
+                       )
+               );
+               $response = $this->usersController->index(0, 10, '', 'pattern');
+               $this->assertEquals($expectedResponse, $response);
+       }
+
+
        public function testIndexWithBackend() {
                $user = $this->getMockBuilder('\OC\User\User')
                        ->disableOriginalConstructor()->getMock();