Skip to content

Commit

Permalink
ID-807 scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Polumbo committed Oct 27, 2023
1 parent 5d8c235 commit c0c9466
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@
package org.broadinstitute.dsde.workbench.sam.model.api

import org.broadinstitute.dsde.workbench.model.ValueObjectFormat
import org.broadinstitute.dsde.workbench.sam.model.{AccessPolicyDescendantPermissions, AccessPolicyName, AccessPolicyResponseEntry, CreateResourcePolicyResponse, CreateResourceRequest, CreateResourceResponse, FullyQualifiedPolicyId, FullyQualifiedResourceId, GroupSyncResponse, ManagedGroupAccessInstructions, ManagedGroupMembershipEntry, OldTermsOfServiceDetails, PolicyIdentifiers, RequesterPaysSignedUrlRequest, ResourceAction, ResourceActionPattern, ResourceId, ResourceRole, ResourceRoleName, ResourceType, ResourceTypeName, RolesAndActions, SamUserTos, SignedUrlRequest, TermsOfServiceAcceptance, TermsOfServiceComplianceStatus, TermsOfServiceDetails, UserIdInfo, UserPolicyResponse, UserResourcesResponse, UserStatus, UserStatusDetails, UserStatusDiagnostics, UserStatusInfo}
import org.broadinstitute.dsde.workbench.sam.model.{
AccessPolicyDescendantPermissions,
AccessPolicyName,
AccessPolicyResponseEntry,
CreateResourcePolicyResponse,
CreateResourceRequest,
CreateResourceResponse,
FullyQualifiedPolicyId,
FullyQualifiedResourceId,
GroupSyncResponse,
ManagedGroupAccessInstructions,
ManagedGroupMembershipEntry,
OldTermsOfServiceDetails,
PolicyIdentifiers,
RequesterPaysSignedUrlRequest,
ResourceAction,
ResourceActionPattern,
ResourceId,
ResourceRole,
ResourceRoleName,
ResourceType,
ResourceTypeName,
RolesAndActions,
SamUserTos,
SignedUrlRequest,
TermsOfServiceAcceptance,
TermsOfServiceComplianceStatus,
TermsOfServiceDetails,
UserIdInfo,
UserPolicyResponse,
UserResourcesResponse,
UserStatus,
UserStatusDetails,
UserStatusDiagnostics,
UserStatusInfo
}
import org.broadinstitute.dsde.workbench.model.google.GoogleModelJsonSupport.InstantFormat
import spray.json.{DefaultJsonProtocol, RootJsonFormat}
import org.broadinstitute.dsde.workbench.sam.model.api.SamApiJsonProtocol.PolicyInfoResponseBodyJsonFormat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,20 @@ class TosService(val directoryDao: DirectoryDAO, val tosConfig: TermsOfServiceCo
requestingUser: SamUser,
isAdmin: Boolean,
samRequestContext: SamRequestContext
): IO[TermsOfServiceDetails] = {
): IO[TermsOfServiceDetails] =
if (isAdmin || (requestedUserId == requestingUser.id)) {
for {
currentSamUserTos <- loadTosRecordForUser(requestedUserId, Option(tosConfig.version), samRequestContext)
previousSamUserTos <- loadTosRecordForUser(requestedUserId, tosConfig.previousVersion, samRequestContext)
requestedUser <- loadUser(requestedUserId, samRequestContext)
} yield {
TermsOfServiceDetails(
currentSamUserTos.version,
currentSamUserTos.createdAt,
tosAcceptancePermitsSystemUsage(requestedUser, Option(currentSamUserTos), Option(previousSamUserTos)))
}
} yield TermsOfServiceDetails(
currentSamUserTos.version,
currentSamUserTos.createdAt,
tosAcceptancePermitsSystemUsage(requestedUser, Option(currentSamUserTos), Option(previousSamUserTos))
)
} else {
IO.raiseError(new WorkbenchExceptionWithErrorReport(ErrorReport(StatusCodes.Unauthorized, "You are not allowed to make this request")))
}
}

private def loadUser(userId: WorkbenchUserId, samRequestContext: SamRequestContext): IO[SamUser] =
directoryDao.loadUser(userId, samRequestContext).map {
Expand All @@ -81,12 +79,11 @@ class TosService(val directoryDao: DirectoryDAO, val tosConfig: TermsOfServiceCo
}

// Note: if version is None, then the query will return the last accepted ToS info for the user
private def loadTosRecordForUser(userId: WorkbenchUserId, version: Option[String], samRequestContext: SamRequestContext): IO[SamUserTos] = {
private def loadTosRecordForUser(userId: WorkbenchUserId, version: Option[String], samRequestContext: SamRequestContext): IO[SamUserTos] =
directoryDao.getUserTosVersion(userId, version, samRequestContext).map {
case Some(samUserTos) => samUserTos
case None => throw new WorkbenchExceptionWithErrorReport(ErrorReport(StatusCodes.NotFound, s"Could not find Terms of Service entry for user:${userId}"))
}
}

def getTosComplianceStatus(samUser: SamUser, samRequestContext: SamRequestContext): IO[TermsOfServiceComplianceStatus] = for {
latestUserTos <- directoryDao.getUserTos(samUser.id, samRequestContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ trait TermsOfServiceDetailsMatchers {

def permitsSystemUsage(expectedValue: Boolean): HavePropertyMatcher[TermsOfServiceDetails, Boolean] =
new HavePropertyMatcher[TermsOfServiceDetails, Boolean] {
def apply(termsOfServiceDetails: TermsOfServiceDetails): HavePropertyMatchResult[Boolean] = {
def apply(termsOfServiceDetails: TermsOfServiceDetails): HavePropertyMatchResult[Boolean] =
HavePropertyMatchResult(
expectedValue == termsOfServiceDetails.permitsSystemUsage,
"permitsSystemUsage",
expectedValue,
termsOfServiceDetails.permitsSystemUsage
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,14 @@ class TosServiceSpec(_system: ActorSystem)
val tosService = new TosService(directoryDao, TestSupport.tosConfig)

// Act
val userTosDetails: TermsOfServiceDetails = runAndWait(tosService.getTermsOfServiceDetailsForUser(defaultUser.id, adminUser, isAdmin = true, samRequestContext))
val userTosDetails: TermsOfServiceDetails =
runAndWait(tosService.getTermsOfServiceDetailsForUser(defaultUser.id, adminUser, isAdmin = true, samRequestContext))

// Assert
userTosDetails should have {
latestAcceptedVersion (tosVersion)
acceptedOn (Instant.now)
permitsSystemUsage (true)
latestAcceptedVersion(tosVersion)
acceptedOn(Instant.now)
permitsSystemUsage(true)
}
}

Expand All @@ -464,7 +465,8 @@ class TosServiceSpec(_system: ActorSystem)
val tosService = new TosService(directoryDao, TestSupport.tosConfig)

// Act
val userTosDetails: TermsOfServiceDetails = runAndWait(tosService.getTermsOfServiceDetailsForUser(defaultUser.id, defaultUser, isAdmin = false, samRequestContext))
val userTosDetails: TermsOfServiceDetails =
runAndWait(tosService.getTermsOfServiceDetailsForUser(defaultUser.id, defaultUser, isAdmin = false, samRequestContext))

// Assert
userTosDetails should have {
Expand Down

0 comments on commit c0c9466

Please sign in to comment.