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

CORE-131 adminGetUsersByIDs searches more kinds of ids #1576

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/main/resources/swagger/api-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ paths:
post:
tags:
- Admin
summary: Gets a list of users for a list of Sam User IDs
summary: Gets a list of users for a list of Sam, Azure B2C, or Google Subject IDs
operationId: adminGetUsersByIDs
requestBody:
content:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,19 @@ class PostgresDirectoryDAO(protected val writeDbRef: DbReference, protected val
} else {
readOnlyTransaction("batchLoadUsers", samRequestContext) { implicit session =>
val userTable = UserTable.syntax
val loadUserQuery = samsql"select ${userTable.resultAll} from ${UserTable as userTable} where ${userTable.id} in (${samUserIds})"
// the with clause is to keep the query size down, we only send the samUserIds once and reuse it in each unioned query
val loadUserQuery =
samsql"""
with sam_user_ids (user_id) as (values ${samUserIds.map(id => samsqls"($id)")})
select ${userTable.resultAll} from ${UserTable as userTable}
join sam_user_ids ids on ids.user_id = ${userTable.id}
union
select ${userTable.resultAll} from ${UserTable as userTable}
join sam_user_ids ids on ids.user_id = ${userTable.azureB2cId}
union
select ${userTable.resultAll} from ${UserTable as userTable}
join sam_user_ids ids on ids.user_id = ${userTable.googleSubjectId}
"""

loadUserQuery
.map(UserTable(userTable))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,19 @@ class PostgresDirectoryDAOSpec extends RetryableAnyFreeSpec with Matchers with B
assume(databaseEnabled, databaseEnabledClue)
val users = Seq.range(0, 10).map(_ => Generator.genWorkbenchUserBoth.sample.get)
users.foreach(user => dao.createUser(user, samRequestContext).unsafeRunSync())
val loadedUsers = dao.batchLoadUsers(users.map(_.id).toSet, samRequestContext).unsafeRunSync()
loadedUsers should contain theSameElementsAs users
val loadedUsersBySamId = dao.batchLoadUsers(users.map(_.id).toSet, samRequestContext).unsafeRunSync()
loadedUsersBySamId should contain theSameElementsAs users

val b2cIds = users.flatMap(_.azureB2CId.map(id => WorkbenchUserId(id.value))).toSet
val loadedUsersByAzureB2cId = dao.batchLoadUsers(b2cIds, samRequestContext).unsafeRunSync()
loadedUsersByAzureB2cId should contain theSameElementsAs users

val googleSubjectIds = users.flatMap(_.googleSubjectId.map(id => WorkbenchUserId(id.value))).toSet
val loadedUsersByGoogleSubjectId = dao.batchLoadUsers(googleSubjectIds, samRequestContext).unsafeRunSync()
loadedUsersByGoogleSubjectId should contain theSameElementsAs users

val loadedBy2Ids = dao.batchLoadUsers(googleSubjectIds ++ b2cIds, samRequestContext).unsafeRunSync()
loadedBy2Ids should contain theSameElementsAs users
}
}

Expand Down
Loading