@@ -158,34 +158,65 @@ public function getUsers(string $search = '', ?int $limit = null, int $offset =
158158 * @param string $search Text to search for
159159 * @param int|null $limit Limit the amount of groups returned
160160 * @param int $offset Offset for searching for groups
161+ * @param bool|null $enabled Only return users with this enabled state, or all users if null. Use the `Link` header for the next page offset
161162 * @return DataResponse<Http::STATUS_OK, array{users: array<string, Provisioning_APIUserDetails|array{id: string}>, groups: list<Provisioning_APIUserDetailsGroupDisplayname>}, array{Link?: string}>
162163 *
163164 * 200: Users details returned
164165 */
165166 #[NoAdminRequired]
166- public function getUsersDetails (string $ search = '' , ?int $ limit = null , int $ offset = 0 ): DataResponse {
167+ public function getUsersDetails (string $ search = '' , ?int $ limit = null , int $ offset = 0 , ? bool $ enabled = null ): DataResponse {
167168 $ currentUser = $ this ->userSession ->getUser ();
168169 $ users = [];
170+ $ hasMore = null ;
171+ $ nextOffset = null ;
169172
170173 // Admin? Or SubAdmin?
171174 $ uid = $ currentUser ->getUID ();
172175 $ subAdminManager = $ this ->groupManager ->getSubAdmin ();
173176 $ isAdmin = $ this ->groupManager ->isAdmin ($ uid );
174177 $ isDelegatedAdmin = $ this ->groupManager ->isDelegatedAdmin ($ uid );
175178 if ($ isAdmin || $ isDelegatedAdmin ) {
176- $ users = $ this ->userManager ->search ($ search , $ limit , $ offset );
177- $ users = array_keys ($ users );
178- } elseif ($ subAdminManager ->isSubAdmin ($ currentUser )) {
179- $ subAdminOfGroups = $ subAdminManager ->getSubAdminsGroups ($ currentUser );
180- foreach ($ subAdminOfGroups as $ key => $ group ) {
181- $ subAdminOfGroups [$ key ] = $ group ->getGID ();
179+ $ searchUsers = fn (?int $ limit , int $ offset ): array => $ this ->userManager ->search ($ search , $ limit , $ offset );
180+ if ($ enabled !== null ) {
181+ [$ users , $ nextOffset , $ hasMore ] = $ this ->searchFilteredUsers (
182+ $ searchUsers ,
183+ $ limit ,
184+ $ offset ,
185+ enabled: $ enabled ,
186+ );
187+ $ users = array_map (fn (IUser $ user ): string => $ user ->getUID (), $ users );
188+ } else {
189+ $ users = $ searchUsers ($ limit , $ offset );
190+ $ users = array_keys ($ users );
182191 }
192+ } elseif ($ subAdminManager ->isSubAdmin ($ currentUser )) {
193+ if ($ enabled !== null ) {
194+ $ users = [];
195+ /* The groups are searched together, so offset and limit are applied to the combined list */
196+ $ tempLimit = ($ limit === null ? null : $ limit + $ offset );
197+ foreach ($ subAdminManager ->getSubAdminsGroups ($ currentUser ) as $ group ) {
198+ foreach ($ group ->searchUsers ($ search ) as $ user ) {
199+ if ($ user ->isEnabled () === $ enabled ) {
200+ $ users [$ user ->getUID ()] = $ user ->getUID ();
201+ }
202+ }
203+ if (($ tempLimit !== null ) && (count ($ users ) >= $ tempLimit )) {
204+ break ;
205+ }
206+ }
207+ $ users = array_slice (array_values ($ users ), $ offset , $ limit );
208+ } else {
209+ $ subAdminOfGroups = $ subAdminManager ->getSubAdminsGroups ($ currentUser );
210+ foreach ($ subAdminOfGroups as $ key => $ group ) {
211+ $ subAdminOfGroups [$ key ] = $ group ->getGID ();
212+ }
183213
184- $ users = [];
185- foreach ($ subAdminOfGroups as $ group ) {
186- $ users [] = array_keys ($ this ->groupManager ->displayNamesInGroup ($ group , $ search , $ limit , $ offset ));
214+ $ users = [];
215+ foreach ($ subAdminOfGroups as $ group ) {
216+ $ users [] = array_keys ($ this ->groupManager ->displayNamesInGroup ($ group , $ search , $ limit , $ offset ));
217+ }
218+ $ users = array_merge (...$ users );
187219 }
188- $ users = array_merge (...$ users );
189220 }
190221
191222 $ usersDetails = [];
@@ -209,9 +240,11 @@ public function getUsersDetails(string $search = '', ?int $limit = null, int $of
209240 }
210241 }
211242
212- $ headers = $ this -> buildOffsetNextPageLinkHeader ( $ users , [
243+ $ params = [
213244 'search ' => $ search ,
214- ], $ limit , $ offset );
245+ 'enabled ' => $ enabled
246+ ];
247+ $ headers = $ this ->buildOffsetNextPageLinkHeader ($ hasMore ?? $ users , $ params , $ limit , $ offset , $ nextOffset );
215248 return new DataResponse ([
216249 'users ' => $ usersDetails ,
217250 'groups ' => $ this ->findGroupsWithDisplayname ($ usersDetails ),
@@ -309,6 +342,7 @@ public function getDisabledUsersDetails(string $search = '', ?int $limit = null,
309342 * @param string $search Text to search for
310343 * @param ?int $limit Limit the amount of users returned
311344 * @param int $offset Offset
345+ * @param bool|null $enabled Only return users with this enabled state, or all users if null. Use the `Link` header for the next page offset
312346 * @return DataResponse<Http::STATUS_OK, array{users: array<string, Provisioning_APIUserDetails|array{id: string}>}, array{Link?: string}>
313347 *
314348 * 200: Users details returned based on last logged in information
@@ -318,6 +352,7 @@ public function getLastLoggedInUsers(
318352 string $ search = '' ,
319353 ?int $ limit = null ,
320354 int $ offset = 0 ,
355+ ?bool $ enabled = null ,
321356 ): DataResponse {
322357 $ currentUser = $ this ->userSession ->getUser ();
323358 if ($ currentUser === null ) {
@@ -331,9 +366,24 @@ public function getLastLoggedInUsers(
331366 }
332367
333368 $ users = [];
369+ $ hasMore = null ;
370+ $ nextOffset = null ;
334371
335372 // For Admin alone user sorting based on lastLogin. For sub admin and groups this is not supported
336- $ users = $ this ->userManager ->getLastLoggedInUsers ($ limit , $ offset , $ search );
373+ if ($ enabled !== null ) {
374+ [$ users , $ nextOffset , $ hasMore ] = $ this ->searchFilteredUsers (
375+ fn (?int $ limit , int $ offset ): array => array_map (
376+ fn (string $ userId ): ?IUser => $ this ->userManager ->get ($ userId ),
377+ $ this ->userManager ->getLastLoggedInUsers ($ limit , $ offset , $ search ),
378+ ),
379+ $ limit ,
380+ $ offset ,
381+ enabled: $ enabled ,
382+ );
383+ $ users = array_map (fn (IUser $ user ): string => $ user ->getUID (), $ users );
384+ } else {
385+ $ users = $ this ->userManager ->getLastLoggedInUsers ($ limit , $ offset , $ search );
386+ }
337387
338388 $ usersDetails = [];
339389 foreach ($ users as $ userId ) {
@@ -355,9 +405,11 @@ public function getLastLoggedInUsers(
355405 }
356406 }
357407
358- $ headers = $ this -> buildOffsetNextPageLinkHeader ( $ users , [
408+ $ params = [
359409 'search ' => $ search ,
360- ], $ limit , $ offset );
410+ 'enabled ' => $ enabled
411+ ];
412+ $ headers = $ this ->buildOffsetNextPageLinkHeader ($ hasMore ?? $ users , $ params , $ limit , $ offset , $ nextOffset );
361413 return new DataResponse ([
362414 'users ' => $ usersDetails
363415 ], headers: $ headers );
0 commit comments