-
Notifications
You must be signed in to change notification settings - Fork 12
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
ID-1300 Admin Get Users by ID #1498
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
package org.broadinstitute.dsde.workbench.sam.api | ||
package org.broadinstitute.dsde.workbench.sam | ||
package api | ||
|
||
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ | ||
import akka.http.scaladsl.model.StatusCodes | ||
import akka.http.scaladsl.model.StatusCodes.{NotFound, OK} | ||
import akka.http.scaladsl.server | ||
import akka.http.scaladsl.server.Directives._ | ||
import org.broadinstitute.dsde.workbench.model._ | ||
import org.broadinstitute.dsde.workbench.sam.model.api.SamJsonSupport._ | ||
import org.broadinstitute.dsde.workbench.sam.service.ResourceService | ||
import org.broadinstitute.dsde.workbench.sam.util.SamRequestContext | ||
import org.broadinstitute.dsde.workbench.model.WorkbenchIdentityJsonSupport._ | ||
import org.broadinstitute.dsde.workbench.sam.model.api.SamUser | ||
import spray.json.DefaultJsonProtocol._ | ||
|
||
trait ServiceAdminRoutes extends SecurityDirectives with SamRequestContextDirectives with SamUserDirectives with SamModelDirectives { | ||
|
@@ -53,7 +57,19 @@ trait ServiceAdminRoutes extends SecurityDirectives with SamRequestContextDirect | |
.map(users => (if (users.nonEmpty) OK else NotFound) -> users) | ||
} | ||
} | ||
} ~ | ||
postWithTelemetry(samRequestContext) { | ||
entity(as[Seq[WorkbenchUserId]]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldnt this be get? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking POST, since the number of IDs could get pretty unwieldy in a url. |
||
case Seq() => complete(OK -> Seq.empty[SamUser]) | ||
case userIds: Seq[WorkbenchUserId] if userIds.length > 1000 => | ||
throw new WorkbenchExceptionWithErrorReport( | ||
ErrorReport(StatusCodes.BadRequest, "Batch request too large. Batch request too large, must be less than 1000") | ||
) | ||
case userIds: Seq[WorkbenchUserId] => | ||
complete { | ||
userService.getUsersByIds(userIds, samRequestContext) | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we have a limit on how many you can get at one time? |
||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.broadinstitute.dsde.workbench.sam.service.UserServiceSpecs | ||
|
||
import org.broadinstitute.dsde.workbench.model.WorkbenchEmail | ||
import org.broadinstitute.dsde.workbench.sam.Generator.genWorkbenchUserBoth | ||
import org.broadinstitute.dsde.workbench.sam.model.BasicWorkbenchGroup | ||
import org.broadinstitute.dsde.workbench.sam.service.{CloudExtensions, TestUserServiceBuilder} | ||
|
||
import scala.concurrent.ExecutionContextExecutor | ||
|
||
class GetUsersByIdsSpec extends UserServiceTestTraits { | ||
implicit val ec: ExecutionContextExecutor = scala.concurrent.ExecutionContext.global | ||
|
||
val allUsersGroup: BasicWorkbenchGroup = BasicWorkbenchGroup(CloudExtensions.allUsersGroupName, Set(), WorkbenchEmail("[email protected]")) | ||
|
||
describe("When getting") { | ||
describe("users by IDs") { | ||
it("should be successful") { | ||
// Arrange | ||
val users = Seq.range(0, 10).map(_ => genWorkbenchUserBoth.sample.get) | ||
val userService = TestUserServiceBuilder() | ||
.withAllUsersGroup(allUsersGroup) | ||
.withExistingUsers(users) | ||
.withEnabledUsers(users) | ||
.build | ||
// Act | ||
val response = runAndWait(userService.getUsersByIds(users.map(_.id), samRequestContext)) | ||
|
||
// Assert | ||
assert(response.nonEmpty, "Getting users by ID should return a list of users") | ||
response should contain theSameElementsAs users | ||
} | ||
} | ||
|
||
} | ||
describe("a user that does not exist") { | ||
it("should be unsuccessful") { | ||
// Arrange | ||
val userWithBothIds = genWorkbenchUserBoth.sample.get | ||
val userService = TestUserServiceBuilder() | ||
.withAllUsersGroup(allUsersGroup) | ||
.build | ||
// Act | ||
val response = runAndWait(userService.getUser(userWithBothIds.id, samRequestContext)) | ||
|
||
// Assert | ||
assert(response.isEmpty, "Getting a nonexistent user should not find a user") | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we have any test cases that assert the admin only functionality or is that properly covered by other tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this is covered by other tests, but I'll check. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found the test, but it was just named slightly wrong. It tests that only authorized service accounts can call the API |
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you also need a block for a
400
response here (if someone requests > 1000 users)