@@ -158,34 +158,64 @@ 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+ if ($ enabled !== null ) {
180+ [$ users , $ nextOffset , $ hasMore ] = $ this ->searchFilteredUsers (
181+ fn (?int $ limit , int $ offset ): array => $ this ->userManager ->search ($ search , $ limit , $ offset ),
182+ $ limit ,
183+ $ offset ,
184+ enabled: $ enabled ,
185+ );
186+ $ users = array_map (fn (IUser $ user ): string => $ user ->getUID (), $ users );
187+ } else {
188+ $ users = $ this ->userManager ->search ($ search , $ limit , $ offset );
189+ $ users = array_keys ($ users );
182190 }
191+ } elseif ($ subAdminManager ->isSubAdmin ($ currentUser )) {
192+ if ($ enabled !== null ) {
193+ $ users = [];
194+ /* The groups are searched together, so offset and limit are applied to the combined list */
195+ $ tempLimit = ($ limit === null ? null : $ limit + $ offset );
196+ foreach ($ subAdminManager ->getSubAdminsGroups ($ currentUser ) as $ group ) {
197+ foreach ($ group ->searchUsers ($ search ) as $ user ) {
198+ if ($ user ->isEnabled () === $ enabled ) {
199+ $ users [$ user ->getUID ()] = $ user ->getUID ();
200+ }
201+ }
202+ if (($ tempLimit !== null ) && (count ($ users ) >= $ tempLimit )) {
203+ break ;
204+ }
205+ }
206+ $ users = array_slice (array_values ($ users ), $ offset , $ limit );
207+ } else {
208+ $ subAdminOfGroups = $ subAdminManager ->getSubAdminsGroups ($ currentUser );
209+ foreach ($ subAdminOfGroups as $ key => $ group ) {
210+ $ subAdminOfGroups [$ key ] = $ group ->getGID ();
211+ }
183212
184- $ users = [];
185- foreach ($ subAdminOfGroups as $ group ) {
186- $ users [] = array_keys ($ this ->groupManager ->displayNamesInGroup ($ group , $ search , $ limit , $ offset ));
213+ $ users = [];
214+ foreach ($ subAdminOfGroups as $ group ) {
215+ $ users [] = array_keys ($ this ->groupManager ->displayNamesInGroup ($ group , $ search , $ limit , $ offset ));
216+ }
217+ $ users = array_merge (...$ users );
187218 }
188- $ users = array_merge (...$ users );
189219 }
190220
191221 $ usersDetails = [];
@@ -209,9 +239,11 @@ public function getUsersDetails(string $search = '', ?int $limit = null, int $of
209239 }
210240 }
211241
212- $ headers = $ this -> buildOffsetNextPageLinkHeader ( $ users , [
242+ $ params = [
213243 'search ' => $ search ,
214- ], $ limit , $ offset );
244+ 'enabled ' => $ enabled
245+ ];
246+ $ headers = $ this ->buildOffsetNextPageLinkHeader ($ hasMore ?? $ users , $ params , $ limit , $ offset , $ nextOffset );
215247 return new DataResponse ([
216248 'users ' => $ usersDetails ,
217249 'groups ' => $ this ->findGroupsWithDisplayname ($ usersDetails ),
@@ -309,6 +341,7 @@ public function getDisabledUsersDetails(string $search = '', ?int $limit = null,
309341 * @param string $search Text to search for
310342 * @param ?int $limit Limit the amount of users returned
311343 * @param int $offset Offset
344+ * @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
312345 * @return DataResponse<Http::STATUS_OK, array{users: array<string, Provisioning_APIUserDetails|array{id: string}>}, array{Link?: string}>
313346 *
314347 * 200: Users details returned based on last logged in information
@@ -318,6 +351,7 @@ public function getLastLoggedInUsers(
318351 string $ search = '' ,
319352 ?int $ limit = null ,
320353 int $ offset = 0 ,
354+ ?bool $ enabled = null ,
321355 ): DataResponse {
322356 $ currentUser = $ this ->userSession ->getUser ();
323357 if ($ currentUser === null ) {
@@ -331,9 +365,24 @@ public function getLastLoggedInUsers(
331365 }
332366
333367 $ users = [];
368+ $ hasMore = null ;
369+ $ nextOffset = null ;
334370
335371 // 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 );
372+ if ($ enabled !== null ) {
373+ [$ users , $ nextOffset , $ hasMore ] = $ this ->searchFilteredUsers (
374+ fn (?int $ limit , int $ offset ): array => array_map (
375+ fn (string $ userId ): ?IUser => $ this ->userManager ->get ($ userId ),
376+ $ this ->userManager ->getLastLoggedInUsers ($ limit , $ offset , $ search ),
377+ ),
378+ $ limit ,
379+ $ offset ,
380+ enabled: $ enabled ,
381+ );
382+ $ users = array_map (fn (IUser $ user ): string => $ user ->getUID (), $ users );
383+ } else {
384+ $ users = $ this ->userManager ->getLastLoggedInUsers ($ limit , $ offset , $ search );
385+ }
337386
338387 $ usersDetails = [];
339388 foreach ($ users as $ userId ) {
@@ -355,9 +404,11 @@ public function getLastLoggedInUsers(
355404 }
356405 }
357406
358- $ headers = $ this -> buildOffsetNextPageLinkHeader ( $ users , [
407+ $ params = [
359408 'search ' => $ search ,
360- ], $ limit , $ offset );
409+ 'enabled ' => $ enabled
410+ ];
411+ $ headers = $ this ->buildOffsetNextPageLinkHeader ($ hasMore ?? $ users , $ params , $ limit , $ offset , $ nextOffset );
361412 return new DataResponse ([
362413 'users ' => $ usersDetails
363414 ], headers: $ headers );
0 commit comments