diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index 957dbd6d7cc77..7929bfe91d567 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -425,7 +425,7 @@ public function callForAllUsers(\Closure $callback, $search = '', $onlySeen = fa * @return int * @since 12.0.0 */ - public function countDisabledUsers() { + public function countDisabledUsers():int { $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); $queryBuilder->select($queryBuilder->createFunction('COUNT(*)')) ->from('preferences') @@ -448,7 +448,7 @@ public function countDisabledUsers() { * @return int * @since 14.0.0 */ - public function countDisabledUsersOfGroups(array $groups) { + public function countDisabledUsersOfGroups(array $groups):int { $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); $queryBuilder->select($queryBuilder->createFunction('COUNT(Distinct uid)')) ->from('preferences', 'p') diff --git a/lib/public/IUserManager.php b/lib/public/IUserManager.php index 3aaf0db55ce27..6dd2406c46395 100644 --- a/lib/public/IUserManager.php +++ b/lib/public/IUserManager.php @@ -167,7 +167,7 @@ public function callForAllUsers(\Closure $callback, $search = ''); * @return int * @since 12.0.0 */ - public function countDisabledUsers(); + public function countDisabledUsers():int; /** * returns how many users are disabled in the requested groups @@ -176,7 +176,7 @@ public function countDisabledUsers(); * @return int * @since 14.0.0 */ - public function countDisabledUsersOfGroups(array $groups); + public function countDisabledUsersOfGroups(array $groups):int; /** * returns how many users have logged in once diff --git a/settings/Controller/GroupsController.php b/settings/Controller/GroupsController.php index 19b7c53f8b9ed..b7430ed492aa5 100644 --- a/settings/Controller/GroupsController.php +++ b/settings/Controller/GroupsController.php @@ -32,6 +32,7 @@ use OCP\IGroupManager; use OCP\IL10N; use OCP\IRequest; +use OCP\IUserManager; use OCP\IUserSession; /** @@ -40,6 +41,8 @@ class GroupsController extends Controller { /** @var IGroupManager */ private $groupManager; + /** @var IUserManager */ + private $userManager; /** @var IL10N */ private $l10n; /** @var IUserSession */ @@ -58,11 +61,13 @@ class GroupsController extends Controller { public function __construct($appName, IRequest $request, IGroupManager $groupManager, + IUserManager $userManager, IUserSession $userSession, $isAdmin, IL10N $l10n) { parent::__construct($appName, $request); $this->groupManager = $groupManager; + $this->userManager = $userManager; $this->userSession = $userSession; $this->isAdmin = $isAdmin; $this->l10n = $l10n; @@ -83,6 +88,7 @@ public function index($pattern = '', $filterGroups = false, $sortGroups = MetaDa $this->userSession->getUser()->getUID(), $this->isAdmin, $this->groupManager, + $this->userManager, $this->userSession ); $groupsInfo->setSorting($sortGroups); diff --git a/tests/Settings/Controller/GroupsControllerTest.php b/tests/Settings/Controller/GroupsControllerTest.php index d43d4faf2189a..095faa8503750 100644 --- a/tests/Settings/Controller/GroupsControllerTest.php +++ b/tests/Settings/Controller/GroupsControllerTest.php @@ -19,6 +19,7 @@ use OCP\IGroupManager; use OCP\IL10N; use OCP\IRequest; +use OCP\IUserManager; use OCP\IUserSession; /** @@ -29,6 +30,9 @@ class GroupsControllerTest extends \Test\TestCase { /** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */ private $groupManager; + /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ + private $userManager; + /** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */ private $userSession; @@ -39,6 +43,7 @@ protected function setUp() { parent::setUp(); $this->groupManager = $this->createMock(IGroupManager::class); + $this->userManager = $this->createMock(IUserManager::class); $this->userSession = $this->createMock(IUserSession::class); $l = $this->createMock(IL10N::class); $l->method('t') @@ -49,6 +54,7 @@ protected function setUp() { 'settings', $this->createMock(IRequest::class), $this->groupManager, + $this->userManager, $this->userSession, true, $l @@ -112,8 +118,15 @@ public function testIndexSortByName() { $groups[] = $thirdGroup; $groups[] = $fourthGroup; + // Get disabled count + $this->userManager->expects($this->exactly(4)) + ->method('countDisabledUsersOfGroups') + ->will($this->returnValue(0)); + $user = $this->getMockBuilder(User::class) ->disableOriginalConstructor()->getMock(); + + // Get connected user $this->userSession ->expects($this->once()) ->method('getUser') @@ -132,7 +145,8 @@ public function testIndexSortByName() { 0 => array( 'id' => 'admin', 'name' => 'Admin', - 'usercount' => 0,//User count disabled 18, + 'usercount' => 0, // User count disabled, should be 18, + 'disabled' => 0 ) ), 'groups' => @@ -140,17 +154,20 @@ public function testIndexSortByName() { 0 => array( 'id' => 'firstGroup', 'name' => 'First group', - 'usercount' => 0,//User count disabled 12, + 'usercount' => 0, // User count disabled, should be 12, + 'disabled' => 0 ), 1 => array( 'id' => 'secondGroup', 'name' => 'Second group', - 'usercount' => 0,//User count disabled 25, + 'usercount' => 0, // User count disabled, should be 25, + 'disabled' => 0 ), 2 => array( 'id' => 'thirdGroup', 'name' => 'Third group', - 'usercount' => 0,//User count disabled 14, + 'usercount' => 0, // User count disabled, should be 14, + 'disabled' => 0 ), ) ) @@ -216,8 +233,15 @@ public function testIndexSortbyCount() { $groups[] = $thirdGroup; $groups[] = $fourthGroup; + // Get disabled count + $this->userManager->expects($this->exactly(4)) + ->method('countDisabledUsersOfGroups') + ->will($this->returnValue(0)); + $user = $this->getMockBuilder(User::class) ->disableOriginalConstructor()->getMock(); + + // Get connected user $this->userSession ->expects($this->once()) ->method('getUser') @@ -238,6 +262,7 @@ public function testIndexSortbyCount() { 'id' => 'admin', 'name' => 'Admin', 'usercount' => 18, + 'disabled' => 0 ) ), 'groups' => @@ -246,16 +271,19 @@ public function testIndexSortbyCount() { 'id' => 'secondGroup', 'name' => 'Second group', 'usercount' => 25, + 'disabled' => 0 ), 1 => array( 'id' => 'thirdGroup', 'name' => 'Third group', 'usercount' => 14, + 'disabled' => 0 ), 2 => array( 'id' => 'firstGroup', 'name' => 'First group', 'usercount' => 12, + 'disabled' => 0 ), ) )