From c0c9466d56ccc7629cac385e3f8c6eaf58a25ce7 Mon Sep 17 00:00:00 2001 From: Greg Polumbo <> Date: Fri, 27 Oct 2023 15:42:27 -0400 Subject: [PATCH] ID-807 scalafmt --- .../sam/model/api/SamJsonSupport.scala | 37 ++++++++++++++++++- .../workbench/sam/service/TosService.scala | 17 ++++----- .../TermsOfServiceDetailsMatchers.scala | 3 +- .../sam/service/TosServiceSpec.scala | 12 +++--- 4 files changed, 51 insertions(+), 18 deletions(-) diff --git a/src/main/scala/org/broadinstitute/dsde/workbench/sam/model/api/SamJsonSupport.scala b/src/main/scala/org/broadinstitute/dsde/workbench/sam/model/api/SamJsonSupport.scala index 1b3c24f8c..e8306ae88 100644 --- a/src/main/scala/org/broadinstitute/dsde/workbench/sam/model/api/SamJsonSupport.scala +++ b/src/main/scala/org/broadinstitute/dsde/workbench/sam/model/api/SamJsonSupport.scala @@ -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 diff --git a/src/main/scala/org/broadinstitute/dsde/workbench/sam/service/TosService.scala b/src/main/scala/org/broadinstitute/dsde/workbench/sam/service/TosService.scala index 3b50b6f1e..50a28c0b1 100644 --- a/src/main/scala/org/broadinstitute/dsde/workbench/sam/service/TosService.scala +++ b/src/main/scala/org/broadinstitute/dsde/workbench/sam/service/TosService.scala @@ -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 { @@ -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) diff --git a/src/test/scala/org/broadinstitute/dsde/workbench/sam/matchers/TermsOfServiceDetailsMatchers.scala b/src/test/scala/org/broadinstitute/dsde/workbench/sam/matchers/TermsOfServiceDetailsMatchers.scala index 77ac3616e..faf45942b 100644 --- a/src/test/scala/org/broadinstitute/dsde/workbench/sam/matchers/TermsOfServiceDetailsMatchers.scala +++ b/src/test/scala/org/broadinstitute/dsde/workbench/sam/matchers/TermsOfServiceDetailsMatchers.scala @@ -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 ) - } } } diff --git a/src/test/scala/org/broadinstitute/dsde/workbench/sam/service/TosServiceSpec.scala b/src/test/scala/org/broadinstitute/dsde/workbench/sam/service/TosServiceSpec.scala index f4021f29e..8588f2089 100644 --- a/src/test/scala/org/broadinstitute/dsde/workbench/sam/service/TosServiceSpec.scala +++ b/src/test/scala/org/broadinstitute/dsde/workbench/sam/service/TosServiceSpec.scala @@ -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) } } @@ -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 {