Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backend support for Manage Users pagination #8370

Merged
merged 8 commits into from
Jan 15, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add paginated search backend
mpbrown committed Jan 2, 2025

Verified

This commit was signed with the committer’s verified signature.
mpbrown Mike Brown
commit bfb92d54074239850f01710c82f5d0a84f7a97b3
Original file line number Diff line number Diff line change
@@ -42,10 +42,15 @@ public List<ApiUserWithStatus> usersWithStatus() {
}

@QueryMapping
public Page<ApiUserWithStatus> usersWithStatusPage(@Argument int pageNumber) {
public Page<ApiUserWithStatus> usersWithStatusPage(
@Argument int pageNumber, @Argument String searchQuery) {
if (pageNumber < 0) {
pageNumber = ApiUserService.DEFAULT_OKTA_USER_PAGE_OFFSET;
}
if (!searchQuery.isBlank()) {
return _userService.searchUsersAndStatusInCurrentOrgPaged(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Search is being handled by a different service method here only as an intermediate step between now and the rest of the Okta migration. Currently, we have to fetch the entire organization's user list from Okta in order to do this search. Once we switch to getting users from our database, we can have the other method below use the search filter easily.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to confirm, we aren't using this search functionality on the frontend just yet, right? That's being introduced with your frontend PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, so this new endpoint is not currently being used anywhere in the app until the frontend PR

pageNumber, DEFAULT_OKTA_USER_PAGE_SIZE, searchQuery);
}
return _userService.getPagedUsersAndStatusInCurrentOrg(pageNumber, DEFAULT_OKTA_USER_PAGE_SIZE);
}

Original file line number Diff line number Diff line change
@@ -638,6 +638,33 @@ public Page<ApiUserWithStatus> getPagedUsersAndStatusInCurrentOrg(int pageNumber
return new PageImpl<>(userWithStatusList, pageRequest, userCountInOrg);
}

public Page<ApiUserWithStatus> searchUsersAndStatusInCurrentOrgPaged(
int pageNumber, int pageSize, String searchQuery) {
List<ApiUserWithStatus> allUsers = getUsersAndStatusInCurrentOrg();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


List<ApiUserWithStatus> filteredUsersList =
allUsers.stream()
.filter(
u -> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we do u.getNameInfo().toString().toLowerCase() to get the full name here instead or are we purposefully trying to avoid including a user's suffix in their name? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are purposefully excluding suffix based on the existing frontend search in UsersSideNav that filters based on first, middle, and last names

String firstName =
u.getFirstName() == null ? "" : String.format("%s ", u.getFirstName());
String middleName =
u.getMiddleName() == null ? "" : String.format("%s ", u.getMiddleName());
String fullName = firstName + middleName + u.getLastName();
return fullName.toLowerCase().contains(searchQuery.toLowerCase());
})
.toList();

int totalResults = filteredUsersList.size();
int startIndex = pageNumber * pageSize;
int endIndex = Math.min((startIndex + pageSize), filteredUsersList.size());

List<ApiUserWithStatus> pageContent = filteredUsersList.subList(startIndex, endIndex);
PageRequest pageRequest = PageRequest.of(pageNumber, pageSize);

return new PageImpl<>(pageContent, pageRequest, totalResults);
}

// To be addressed in #8108
@AuthorizationConfiguration.RequirePermissionManageUsers
public List<ApiUserWithStatus> getUsersAndStatusInCurrentOrg() {
Original file line number Diff line number Diff line change
@@ -173,6 +173,17 @@ void getPagedUsersAndStatusInCurrentOrg_success() {
users2ndList.get(2), "[email protected]", "Reynolds", UserStatus.ACTIVE);
}

@Test
@WithSimpleReportOrgAdminUser
void searchUsersAndStatusInCurrentOrgPaged_success() {
initSampleData();
Page<ApiUserWithStatus> usersPage =
_service.searchUsersAndStatusInCurrentOrgPaged(0, 10, "Bob");
List<ApiUserWithStatus> users = usersPage.stream().toList();
assertEquals(1, users.size());
checkApiUserWithStatus(users.get(0), "[email protected]", "Bobberoo", UserStatus.ACTIVE);
}

@Test
@WithSimpleReportOrgAdminUser
void getUser_withAdminUser_withOktaMigrationDisabled_success() {