Skip to content

Commit

Permalink
fix(users): use correct active user count
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Gaussorgues <[email protected]>
  • Loading branch information
Altahrim committed Oct 16, 2024
1 parent 4121bdf commit 3287967
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/settings/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function usersList(): TemplateResponse {
$recentUsersGroup = [
'id' => '__nc_internal_recent',
'name' => $this->l10n->t('Recently active'),
'usercount' => $userCount,
'usercount' => $this->userManager->countSeenUsers(),
];

$disabledUsersGroup = [
Expand Down
5 changes: 4 additions & 1 deletion lib/private/User/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -743,12 +743,15 @@ public function validateUserId(string $uid, bool $checkDataDirectory = false): v
/**
* Gets the list of user ids sorted by lastLogin, from most recent to least recent
*
* @param int|null $limit how many users to fetch
* @param int|null $limit how many users to fetch (default: 25, max: 100)
* @param int $offset from which offset to fetch
* @param string $search search users based on search params
* @return list<string> list of user IDs

Check failure on line 749 in lib/private/User/Manager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MoreSpecificReturnType

lib/private/User/Manager.php:749:13: MoreSpecificReturnType: The declared return type 'list<string>' for OC\User\Manager::getLastLoggedInUsers is more specific than the inferred return type 'array<array-key, mixed>' (see https://psalm.dev/070)
*/
public function getLastLoggedInUsers(?int $limit = null, int $offset = 0, string $search = ''): array {
// We can't load all users who already logged in
$limit = min(100, $limit ?: 25);

$connection = \OC::$server->getDatabaseConnection();
$queryBuilder = $connection->getQueryBuilder();
$queryBuilder->select('login.userid')
Expand Down
13 changes: 9 additions & 4 deletions tests/lib/User/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;
use Test\TestCase;

Expand Down Expand Up @@ -579,7 +580,7 @@ public function testCountUsersTwoBackends(): void {
}

public function testCountUsersOnlyDisabled(): void {
$manager = \OC::$server->getUserManager();
$manager = \OCP\Server::get(IUserManager::class);
// count other users in the db before adding our own
$countBefore = $manager->countDisabledUsers();

Expand All @@ -604,7 +605,7 @@ public function testCountUsersOnlyDisabled(): void {
}

public function testCountUsersOnlySeen(): void {
$manager = \OC::$server->getUserManager();
$manager = \OCP\Server::get(IUserManager::class);
// count other users in the db before adding our own
$countBefore = $manager->countSeenUsers();

Expand All @@ -630,7 +631,7 @@ public function testCountUsersOnlySeen(): void {
}

public function testCallForSeenUsers(): void {
$manager = \OC::$server->getUserManager();
$manager = \OCP\Server::get(IUserManager::class);
// count other users in the db before adding our own
$count = 0;
$function = function (IUser $user) use (&$count) {
Expand Down Expand Up @@ -663,9 +664,13 @@ public function testCallForSeenUsers(): void {
$user4->delete();
}

/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testRecentlyActive(): void {
$manager = \OCP\Server::get(IUserManager::class);
$config = \OCP\Server::get(IConfig::class);
$manager = \OCP\Server::get(IUserManager::class);

// Create some users
$now = (string)time();
Expand Down

0 comments on commit 3287967

Please sign in to comment.