diff --git a/backend/src/main/java/gov/cdc/usds/simplereport/api/apiuser/ManageUsersPageWrapper.java b/backend/src/main/java/gov/cdc/usds/simplereport/api/apiuser/ManageUsersPageWrapper.java new file mode 100644 index 0000000000..a47c7669dc --- /dev/null +++ b/backend/src/main/java/gov/cdc/usds/simplereport/api/apiuser/ManageUsersPageWrapper.java @@ -0,0 +1,22 @@ +package gov.cdc.usds.simplereport.api.apiuser; + +import gov.cdc.usds.simplereport.api.model.ApiUserWithStatus; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; +import org.springframework.data.domain.Page; + +/** + * When the page content contains zero entries, this could be due to either: - zero search results + * for the query string - OR due to zero users in the entire organization. The value for total users + * in the org helps differentiate this. + */ +@Getter +@Setter +@AllArgsConstructor +public class ManageUsersPageWrapper { + + Page pageContent; + + int totalUsersInOrg; +} diff --git a/backend/src/main/java/gov/cdc/usds/simplereport/api/apiuser/UserResolver.java b/backend/src/main/java/gov/cdc/usds/simplereport/api/apiuser/UserResolver.java index 02d5860e5f..4756c6c461 100644 --- a/backend/src/main/java/gov/cdc/usds/simplereport/api/apiuser/UserResolver.java +++ b/backend/src/main/java/gov/cdc/usds/simplereport/api/apiuser/UserResolver.java @@ -11,7 +11,6 @@ import java.util.List; import java.util.UUID; import org.apache.commons.lang3.StringUtils; -import org.springframework.data.domain.Page; import org.springframework.graphql.data.method.annotation.Argument; import org.springframework.graphql.data.method.annotation.QueryMapping; import org.springframework.stereotype.Controller; @@ -42,7 +41,7 @@ public List usersWithStatus() { } @QueryMapping - public Page usersWithStatusPage( + public ManageUsersPageWrapper usersWithStatusPage( @Argument int pageNumber, @Argument String searchQuery) { if (pageNumber < 0) { pageNumber = ApiUserService.DEFAULT_OKTA_USER_PAGE_OFFSET; diff --git a/backend/src/main/java/gov/cdc/usds/simplereport/service/ApiUserService.java b/backend/src/main/java/gov/cdc/usds/simplereport/service/ApiUserService.java index 87eb6d1f8f..d2cc279dc7 100644 --- a/backend/src/main/java/gov/cdc/usds/simplereport/service/ApiUserService.java +++ b/backend/src/main/java/gov/cdc/usds/simplereport/service/ApiUserService.java @@ -4,6 +4,7 @@ import gov.cdc.usds.simplereport.api.ApiUserContextHolder; import gov.cdc.usds.simplereport.api.CurrentAccountRequestContextHolder; import gov.cdc.usds.simplereport.api.WebhookContextHolder; +import gov.cdc.usds.simplereport.api.apiuser.ManageUsersPageWrapper; import gov.cdc.usds.simplereport.api.model.ApiUserWithStatus; import gov.cdc.usds.simplereport.api.model.Role; import gov.cdc.usds.simplereport.api.model.errors.ConflictingUserException; @@ -621,7 +622,7 @@ public List getUsersInCurrentOrg() { } @AuthorizationConfiguration.RequirePermissionManageUsers - public Page getPagedUsersAndStatusInCurrentOrg(int pageNumber, int pageSize) { + public ManageUsersPageWrapper getPagedUsersAndStatusInCurrentOrg(int pageNumber, int pageSize) { Organization org = _orgService.getCurrentOrganization(); final Map emailsToStatus = @@ -634,15 +635,18 @@ public Page getPagedUsersAndStatusInCurrentOrg(int pageNumber Integer userCountInOrg = _oktaRepo.getUsersCountInOrganization(org); PageRequest pageRequest = PageRequest.of(pageNumber, pageSize); + Page pageContent = + new PageImpl<>(userWithStatusList, pageRequest, userCountInOrg); - return new PageImpl<>(userWithStatusList, pageRequest, userCountInOrg); + return new ManageUsersPageWrapper(pageContent, userCountInOrg); } - public Page searchUsersAndStatusInCurrentOrgPaged( + @AuthorizationConfiguration.RequirePermissionManageUsers + public ManageUsersPageWrapper searchUsersAndStatusInCurrentOrgPaged( int pageNumber, int pageSize, String searchQuery) { List allUsers = getUsersAndStatusInCurrentOrg(); - List filteredUsersList = + List totalFilteredUsersList = allUsers.stream() .filter( u -> { @@ -655,14 +659,19 @@ public Page searchUsersAndStatusInCurrentOrgPaged( }) .toList(); - int totalResults = filteredUsersList.size(); + int totalSearchResults = totalFilteredUsersList.size(); int startIndex = pageNumber * pageSize; - int endIndex = Math.min((startIndex + pageSize), filteredUsersList.size()); + int endIndex = Math.min((startIndex + pageSize), totalFilteredUsersList.size()); + + Organization org = _orgService.getCurrentOrganization(); + Integer userCountInOrg = _oktaRepo.getUsersCountInOrganization(org); - List pageContent = filteredUsersList.subList(startIndex, endIndex); + List filteredSublist = totalFilteredUsersList.subList(startIndex, endIndex); PageRequest pageRequest = PageRequest.of(pageNumber, pageSize); + Page pageContent = + new PageImpl<>(filteredSublist, pageRequest, totalSearchResults); - return new PageImpl<>(pageContent, pageRequest, totalResults); + return new ManageUsersPageWrapper(pageContent, userCountInOrg); } // To be addressed in #8108