Skip to content

Commit

Permalink
Address tlang's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghost-in-a-Jar committed Nov 6, 2023
1 parent 70038ad commit 35776ed
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,14 @@ abstract class SamRoutes(
userRoutesV2(samRequestContext) ~
publicTermsOfServiceRoutes ~
withActiveUser(samRequestContext) { samUser =>
isWorkbenchAdmin(samUser) { isAdmin =>
val samRequestContextWithUser = samRequestContext.copy(samUser = Option(samUser))
resourceRoutes(samUser, samRequestContextWithUser) ~
adminRoutes(samUser, samRequestContextWithUser) ~
extensionRoutes(samUser, samRequestContextWithUser) ~
groupRoutes(samUser, samRequestContextWithUser) ~
azureRoutes(samUser, samRequestContextWithUser) ~
userRoutesV1(samUser, samRequestContextWithUser) ~
userTermsOfServiceRoutes(samUser, isAdmin, samRequestContextWithUser)
}
val samRequestContextWithUser = samRequestContext.copy(samUser = Option(samUser))
resourceRoutes(samUser, samRequestContextWithUser) ~
adminRoutes(samUser, samRequestContextWithUser) ~
extensionRoutes(samUser, samRequestContextWithUser) ~
groupRoutes(samUser, samRequestContextWithUser) ~
azureRoutes(samUser, samRequestContextWithUser) ~
userRoutesV1(samUser, samRequestContextWithUser) ~
userTermsOfServiceRoutes(samUser, samRequestContextWithUser)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.broadinstitute.dsde.workbench.sam.model.api.SamJsonSupport._
import scala.concurrent.ExecutionContext
import scala.util.matching.Regex

trait TermsOfServiceRoutes {
trait TermsOfServiceRoutes extends SamUserDirectives {
val tosService: TosService
implicit val executionContext: ExecutionContext
private val samUserIdPattern: Regex = "^[a-zA-Z0-9]+$".r
Expand Down Expand Up @@ -64,14 +64,16 @@ trait TermsOfServiceRoutes {
}
}

def userTermsOfServiceRoutes(samUser: SamUser, isAdmin: Boolean, samRequestContext: SamRequestContext): server.Route =
def userTermsOfServiceRoutes(samUser: SamUser, samRequestContext: SamRequestContext): server.Route =
pathPrefix("termsOfService") {
pathPrefix("v1") {
pathPrefix("user") { // api/termsOfService/v1/user
pathPrefix("self") { // api/termsOfService/v1/user/self
pathEndOrSingleSlash {
get {
complete(StatusCodes.OK, tosService.getTermsOfServiceDetailsForUser(samUser.id, samUser, isAdmin = false, samRequestContext))
complete {
tosService.getTermsOfServiceDetailsForUser(samUser.id, samUser, isAdmin = false, samRequestContext)
}
}
} ~
pathPrefix("accept") { // api/termsOfService/v1/user/accept
Expand All @@ -94,8 +96,12 @@ trait TermsOfServiceRoutes {
validate(samUserIdPattern.matches(userId), "User ID must be alpha numeric") {
val requestUserId = WorkbenchUserId(userId)
pathEndOrSingleSlash {
get {
complete(StatusCodes.OK, tosService.getTermsOfServiceDetailsForUser(requestUserId, samUser, isAdmin, samRequestContext))
isWorkbenchAdmin(samUser) { isAdmin =>
get {
complete {
tosService.getTermsOfServiceDetailsForUser(requestUserId, samUser, isAdmin, samRequestContext)
}
}
}
} ~
pathPrefix("history") { // api/termsOfService/v1/user/{userId}/history
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,14 @@ abstract class MockSamRoutes(
// IMPORTANT - all routes under /api must have an active user
publicTermsOfServiceRoutes ~
withActiveUser(samRequestContext) { samUser =>
isWorkbenchAdmin(samUser) { isAdmin =>
val samRequestContextWithUser = samRequestContext.copy(samUser = Option(samUser))
resourceRoutes(samUser, samRequestContextWithUser) ~
adminRoutes(samUser, samRequestContextWithUser) ~
extensionRoutes(samUser, samRequestContextWithUser) ~
groupRoutes(samUser, samRequestContextWithUser) ~
userRoutesV1(samUser, samRequestContextWithUser) ~
azureRoutes(samUser, samRequestContextWithUser) ~
userTermsOfServiceRoutes(samUser, isAdmin, samRequestContextWithUser)
}
val samRequestContextWithUser = samRequestContext.copy(samUser = Option(samUser))
resourceRoutes(samUser, samRequestContextWithUser) ~
adminRoutes(samUser, samRequestContextWithUser) ~
extensionRoutes(samUser, samRequestContextWithUser) ~
groupRoutes(samUser, samRequestContextWithUser) ~
userRoutesV1(samUser, samRequestContextWithUser) ~
azureRoutes(samUser, samRequestContextWithUser) ~
userTermsOfServiceRoutes(samUser, samRequestContextWithUser)
}
}
}
Expand Down

0 comments on commit 35776ed

Please sign in to comment.