From ceedfb46162e53d39460d25b781ddc21c5a9313f Mon Sep 17 00:00:00 2001 From: yemkareems Date: Thu, 4 Jul 2024 13:42:37 +0530 Subject: [PATCH] fix: removed default limit of 25. if null is given all users are fetched or if limit is given limit number of users are fetched Signed-off-by: yemkareems --- .../lib/Controller/UsersController.php | 2 +- lib/private/AllConfig.php | 13 +++++++++++-- lib/private/User/Manager.php | 2 +- lib/public/IConfig.php | 4 ++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index beb240681d0..66cce405335 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -278,7 +278,7 @@ class UsersController extends AUserData { * 200: Users details returned based on last logged in information */ public function getLastLoggedInUsers(string $search = '', - ?int $limit = 25, + ?int $limit = null, int $offset = 0, ): DataResponse { $currentUser = $this->userSession->getUser(); diff --git a/lib/private/AllConfig.php b/lib/private/AllConfig.php index 87b9c795f49..78546531dc6 100644 --- a/lib/private/AllConfig.php +++ b/lib/private/AllConfig.php @@ -494,12 +494,13 @@ class AllConfig implements IConfig { /** * Gets the list of users based on their lastLogin info asc or desc * - * @param int $limit how many users to fetch + * @param int|null $limit how many users to fetch * @param int $offset from which offset to fetch * @param string $search search users based on search params * @return array of user IDs */ - public function getLastLoggedInUsers(int $limit = 25, int $offset = 0, string $search = ''): array { + public function getLastLoggedInUsers(?int $limit = null, int $offset = 0, string $search = ''): array { + $limit = $this->fixLimit($limit); // TODO - FIXME $this->fixDIInit(); @@ -573,4 +574,12 @@ 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 93ba7f0eb6e..aeadb338ea0 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -345,7 +345,7 @@ class Manager extends PublicEmitter implements IUserManager { /** * @return IUser[] */ - public function getUsersSortedByLastLogin(?int $limit = 25, int $offset = 0, $search = ''): array { + public function getUsersSortedByLastLogin(?int $limit = null, int $offset = 0, $search = ''): array { $users = $this->config->getLastLoggedInUsers($limit, $offset, $search); return array_combine( $users, diff --git a/lib/public/IConfig.php b/lib/public/IConfig.php index b74292855a8..92dcfe7f8bc 100644 --- a/lib/public/IConfig.php +++ b/lib/public/IConfig.php @@ -253,11 +253,11 @@ interface IConfig { /** * Gets the list of users based on their lastLogin info asc or desc * - * @param int $limit how many records to fetch + * @param int|null $limit how many records to fetch * @param int $offset from which offset to fetch * @param string $search search users based on search params * @return array of user IDs * @since 30.0.0 */ - public function getLastLoggedInUsers(int $limit, int $offset, string $search): array; + public function getLastLoggedInUsers(?int $limit = null, int $offset = 0, string $search = ''): array; } -- 2.39.5