From ae95e467871cbf54df55b1b4f3f512d66b8b8880 Mon Sep 17 00:00:00 2001 From: yemkareems Date: Thu, 4 Jul 2024 14:41:05 +0530 Subject: [PATCH] fix: limit and fixLimit removed. negative limit handled in controller. removed getUsersSortedByLastLogin from Manager and instead used the config in controller Signed-off-by: yemkareems --- .../lib/Controller/UsersController.php | 14 ++++---------- lib/private/AllConfig.php | 11 +---------- lib/private/User/Manager.php | 15 --------------- lib/public/IUserManager.php | 5 ----- 4 files changed, 5 insertions(+), 40 deletions(-) diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index 66cce405335..1d3c1006a59 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -266,9 +266,7 @@ class UsersController extends AUserData { } /** - * @NoAdminRequired - * - * Get the list of last logged-in users and their details + * Gets the list of users sorted by lastLogin, from most recent to least recent * * @param string $search Text to search for * @param ?int $limit Limit the amount of users returned @@ -278,8 +276,8 @@ class UsersController extends AUserData { * 200: Users details returned based on last logged in information */ public function getLastLoggedInUsers(string $search = '', - ?int $limit = null, - int $offset = 0, + ?int $limit = null, + int $offset = 0, ): DataResponse { $currentUser = $this->userSession->getUser(); if ($currentUser === null) { @@ -295,11 +293,7 @@ class UsersController extends AUserData { $users = []; // For Admin alone user sorting based on lastLogin. For sub admin and groups this is not supported - $uid = $currentUser->getUID(); - if ($this->groupManager->isAdmin($uid)) { - $users = $this->userManager->getUsersSortedByLastLogin($limit, $offset, $search); - $users = array_map(fn (IUser $user): string => $user->getUID(), $users); - } + $users = $this->config->getLastLoggedInUsers($limit, $offset, $search); $usersDetails = []; foreach ($users as $userId) { diff --git a/lib/private/AllConfig.php b/lib/private/AllConfig.php index 78546531dc6..f39182683f5 100644 --- a/lib/private/AllConfig.php +++ b/lib/private/AllConfig.php @@ -492,7 +492,7 @@ class AllConfig implements IConfig { } /** - * Gets the list of users based on their lastLogin info asc or desc + * 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 $offset from which offset to fetch @@ -500,7 +500,6 @@ class AllConfig implements IConfig { * @return array of user IDs */ public function getLastLoggedInUsers(?int $limit = null, int $offset = 0, string $search = ''): array { - $limit = $this->fixLimit($limit); // TODO - FIXME $this->fixDIInit(); @@ -574,12 +573,4 @@ class AllConfig implements IConfig { public function getSystemConfig() { return $this->systemConfig; } - - private function fixLimit($limit) { - if (is_int($limit) && $limit >= 0) { - return $limit; - } - - return null; - } } diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index aeadb338ea0..d93431a2699 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -342,21 +342,6 @@ class Manager extends PublicEmitter implements IUserManager { return array_slice($users, $offset, $limit); } - /** - * @return IUser[] - */ - public function getUsersSortedByLastLogin(?int $limit = null, int $offset = 0, $search = ''): array { - $users = $this->config->getLastLoggedInUsers($limit, $offset, $search); - return array_combine( - $users, - array_map( - fn (string $uid): IUser => new LazyUser($uid, $this), - $users - ) - ); - } - - /** * Search known users (from phonebook sync) by displayName * diff --git a/lib/public/IUserManager.php b/lib/public/IUserManager.php index 8b080fd75c5..851b565f617 100644 --- a/lib/public/IUserManager.php +++ b/lib/public/IUserManager.php @@ -124,11 +124,6 @@ interface IUserManager { */ public function getDisabledUsers(?int $limit = null, int $offset = 0, string $search = ''): array; - /** - * @return IUser[] - * @since 30.0.0 - */ - public function getUsersSortedByLastLogin(?int $limit = null, int $offset = 0, $search = ''): array; /** * Search known users (from phonebook sync) by displayName * -- 2.39.5