From c075f7534af7d1b2d75104730ff5e12bcbd5e462 Mon Sep 17 00:00:00 2001 From: Tristan Garwood Date: Thu, 16 Nov 2023 13:55:49 -0500 Subject: [PATCH] Refactor Tos -> TermsOfService --- .../workbench/sam/api/OldUserRoutes.scala | 4 +- .../sam/api/TermsOfServiceRoutes.scala | 2 +- .../sam/dataAccess/DirectoryDAO.scala | 6 +- .../sam/dataAccess/PostgresDirectoryDAO.scala | 6 +- .../workbench/sam/service/TosService.scala | 14 +- .../workbench/sam/service/UserService.scala | 8 +- .../sam/api/MockSamRoutesBuilder.scala | 4 +- .../sam/api/TermsOfServiceRouteSpec.scala | 4 +- .../sam/dataAccess/MockDirectoryDAO.scala | 6 +- .../dataAccess/MockDirectoryDaoBuilder.scala | 16 +-- .../dataAccess/PostgresDirectoryDAOSpec.scala | 10 +- .../sam/service/MockTosServiceBuilder.scala | 6 +- .../sam/service/TosServiceSpec.scala | 128 +++++++++--------- .../sam/service/UserServiceSpec.scala | 4 +- 14 files changed, 109 insertions(+), 109 deletions(-) diff --git a/src/main/scala/org/broadinstitute/dsde/workbench/sam/api/OldUserRoutes.scala b/src/main/scala/org/broadinstitute/dsde/workbench/sam/api/OldUserRoutes.scala index 203d2c4c5..bb7b72389 100644 --- a/src/main/scala/org/broadinstitute/dsde/workbench/sam/api/OldUserRoutes.scala +++ b/src/main/scala/org/broadinstitute/dsde/workbench/sam/api/OldUserRoutes.scala @@ -66,7 +66,7 @@ trait OldUserRoutes extends SamUserDirectives with SamRequestContextDirectives { get { withUserAllowInactive(samRequestContext) { samUser => complete { - tosService.getTosComplianceStatus(samUser, samRequestContext).map { tosAcceptanceStatus => + tosService.getTermsOfServiceComplianceStatus(samUser, samRequestContext).map { tosAcceptanceStatus => StatusCodes.OK -> Option(JsBoolean(tosAcceptanceStatus.permitsSystemUsage)) } } @@ -144,7 +144,7 @@ trait OldUserRoutes extends SamUserDirectives with SamRequestContextDirectives { } ~ path("termsOfServiceComplianceStatus") { get { - complete(tosService.getTosComplianceStatus(user, samRequestContext)) + complete(tosService.getTermsOfServiceComplianceStatus(user, samRequestContext)) } } } diff --git a/src/main/scala/org/broadinstitute/dsde/workbench/sam/api/TermsOfServiceRoutes.scala b/src/main/scala/org/broadinstitute/dsde/workbench/sam/api/TermsOfServiceRoutes.scala index 17f5b2db5..64c7518c4 100644 --- a/src/main/scala/org/broadinstitute/dsde/workbench/sam/api/TermsOfServiceRoutes.scala +++ b/src/main/scala/org/broadinstitute/dsde/workbench/sam/api/TermsOfServiceRoutes.scala @@ -53,7 +53,7 @@ trait TermsOfServiceRoutes extends SamUserDirectives { parameters("doc".as[String].?) { (doc: Option[String]) => val docSet = doc.map(_.split(",").toSet).getOrElse(Set.empty) if (docSet.subsetOf(Set(tosService.termsOfServiceTextKey, tosService.privacyPolicyTextKey))) - complete(tosService.getTosText(docSet)) + complete(tosService.getTermsOfServiceText(docSet)) else complete(StatusCodes.BadRequest) } diff --git a/src/main/scala/org/broadinstitute/dsde/workbench/sam/dataAccess/DirectoryDAO.scala b/src/main/scala/org/broadinstitute/dsde/workbench/sam/dataAccess/DirectoryDAO.scala index 613ababc5..4532e9ecd 100644 --- a/src/main/scala/org/broadinstitute/dsde/workbench/sam/dataAccess/DirectoryDAO.scala +++ b/src/main/scala/org/broadinstitute/dsde/workbench/sam/dataAccess/DirectoryDAO.scala @@ -76,9 +76,9 @@ trait DirectoryDAO { def acceptTermsOfService(userId: WorkbenchUserId, tosVersion: String, samRequestContext: SamRequestContext): IO[Boolean] def rejectTermsOfService(userId: WorkbenchUserId, tosVersion: String, samRequestContext: SamRequestContext): IO[Boolean] - def getUserTos(userId: WorkbenchUserId, samRequestContext: SamRequestContext): IO[Option[SamUserTos]] - def getUserTosVersion(userId: WorkbenchUserId, tosVersion: Option[String], samRequestContext: SamRequestContext): IO[Option[SamUserTos]] - def getUserTosHistory(userId: WorkbenchUserId, samRequestContext: SamRequestContext, limit: Integer): IO[List[SamUserTos]] + def getUserTermsOfService(userId: WorkbenchUserId, samRequestContext: SamRequestContext): IO[Option[SamUserTos]] + def getUserTermsOfServiceVersion(userId: WorkbenchUserId, tosVersion: Option[String], samRequestContext: SamRequestContext): IO[Option[SamUserTos]] + def getUserTermsOfServiceHistory(userId: WorkbenchUserId, samRequestContext: SamRequestContext, limit: Integer): IO[List[SamUserTos]] def createPetManagedIdentity(petManagedIdentity: PetManagedIdentity, samRequestContext: SamRequestContext): IO[PetManagedIdentity] def loadPetManagedIdentity(petManagedIdentityId: PetManagedIdentityId, samRequestContext: SamRequestContext): IO[Option[PetManagedIdentity]] def getUserFromPetManagedIdentity(petManagedIdentityObjectId: ManagedIdentityObjectId, samRequestContext: SamRequestContext): IO[Option[SamUser]] diff --git a/src/main/scala/org/broadinstitute/dsde/workbench/sam/dataAccess/PostgresDirectoryDAO.scala b/src/main/scala/org/broadinstitute/dsde/workbench/sam/dataAccess/PostgresDirectoryDAO.scala index 4ac16d076..d702dc54b 100644 --- a/src/main/scala/org/broadinstitute/dsde/workbench/sam/dataAccess/PostgresDirectoryDAO.scala +++ b/src/main/scala/org/broadinstitute/dsde/workbench/sam/dataAccess/PostgresDirectoryDAO.scala @@ -648,7 +648,7 @@ class PostgresDirectoryDAO(protected val writeDbRef: DbReference, protected val } } - override def getUserTos(userId: WorkbenchUserId, samRequestContext: SamRequestContext): IO[Option[SamUserTos]] = + override def getUserTermsOfService(userId: WorkbenchUserId, samRequestContext: SamRequestContext): IO[Option[SamUserTos]] = readOnlyTransaction("getUserTos", samRequestContext) { implicit session => val tosTable = TosTable.syntax val column = TosTable.column @@ -664,7 +664,7 @@ class PostgresDirectoryDAO(protected val writeDbRef: DbReference, protected val userTosRecordOpt.map(TosTable.unmarshalUserRecord) } - override def getUserTosVersion(userId: WorkbenchUserId, tosVersion: Option[String], samRequestContext: SamRequestContext): IO[Option[SamUserTos]] = { + override def getUserTermsOfServiceVersion(userId: WorkbenchUserId, tosVersion: Option[String], samRequestContext: SamRequestContext): IO[Option[SamUserTos]] = { if (tosVersion.isEmpty) return IO(None) readOnlyTransaction("getUserTos", samRequestContext) { implicit session => val tosTable = TosTable.syntax @@ -682,7 +682,7 @@ class PostgresDirectoryDAO(protected val writeDbRef: DbReference, protected val } } - override def getUserTosHistory(userId: WorkbenchUserId, samRequestContext: SamRequestContext, limit: Integer): IO[List[SamUserTos]] = + override def getUserTermsOfServiceHistory(userId: WorkbenchUserId, samRequestContext: SamRequestContext, limit: Integer): IO[List[SamUserTos]] = readOnlyTransaction("getUserTosHistory", samRequestContext) { implicit session => val tosTable = TosTable.syntax val column = TosTable.column 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 1d929e432..57267d117 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 @@ -70,7 +70,7 @@ class TosService( ) ) - def getTosText(docSet: Set[String]): IO[String] = + def getTermsOfServiceText(docSet: Set[String]): IO[String] = docSet match { case set if set.isEmpty => IO.pure(termsOfServiceText) case set if set.equals(Set(privacyPolicyTextKey)) => IO.pure(privacyPolicyText) @@ -86,7 +86,7 @@ class TosService( @Deprecated def getTosDetails(samUser: SamUser, samRequestContext: SamRequestContext): IO[OldTermsOfServiceDetails] = - directoryDao.getUserTos(samUser.id, samRequestContext).map { tos => + directoryDao.getUserTermsOfService(samUser.id, samRequestContext).map { tos => OldTermsOfServiceDetails(isEnabled = true, tosConfig.isGracePeriodEnabled, tosConfig.version, tos.map(_.version)) } @@ -114,14 +114,14 @@ class TosService( // 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] = - directoryDao.getUserTosVersion(userId, version, samRequestContext).map { + directoryDao.getUserTermsOfServiceVersion(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 getTermsOfServiceHistoryForUser(userId: WorkbenchUserId, samRequestContext: SamRequestContext, limit: Integer): IO[TermsOfServiceHistory] = ensureAdminIfNeeded[TermsOfServiceHistory](userId, samRequestContext) { - directoryDao.getUserTosHistory(userId, samRequestContext, limit).map { + directoryDao.getUserTermsOfServiceHistory(userId, samRequestContext, limit).map { case samUserTosHistory if samUserTosHistory.isEmpty => throw new WorkbenchExceptionWithErrorReport(ErrorReport(StatusCodes.NotFound, s"Could not find any Terms of Service entries for user:${userId}")) case samUserTosHistory => @@ -131,9 +131,9 @@ class TosService( } } - def getTosComplianceStatus(samUser: SamUser, samRequestContext: SamRequestContext): IO[TermsOfServiceComplianceStatus] = for { - latestUserTos <- directoryDao.getUserTos(samUser.id, samRequestContext) - previousUserTos <- directoryDao.getUserTosVersion(samUser.id, tosConfig.previousVersion, samRequestContext) + def getTermsOfServiceComplianceStatus(samUser: SamUser, samRequestContext: SamRequestContext): IO[TermsOfServiceComplianceStatus] = for { + latestUserTos <- directoryDao.getUserTermsOfService(samUser.id, samRequestContext) + previousUserTos <- directoryDao.getUserTermsOfServiceVersion(samUser.id, tosConfig.previousVersion, samRequestContext) userHasAcceptedLatestVersion = userHasAcceptedLatestTosVersion(latestUserTos) permitsSystemUsage = tosAcceptancePermitsSystemUsage(samUser, latestUserTos, previousUserTos) } yield TermsOfServiceComplianceStatus(samUser.id, userHasAcceptedLatestVersion, permitsSystemUsage) diff --git a/src/main/scala/org/broadinstitute/dsde/workbench/sam/service/UserService.scala b/src/main/scala/org/broadinstitute/dsde/workbench/sam/service/UserService.scala index 9c06fe5b2..1c1f4dfee 100644 --- a/src/main/scala/org/broadinstitute/dsde/workbench/sam/service/UserService.scala +++ b/src/main/scala/org/broadinstitute/dsde/workbench/sam/service/UserService.scala @@ -339,7 +339,7 @@ class UserService( allUsersStatus <- directoryDAO.isGroupMember(allUsersGroup.id, user.id, samRequestContext) recover { case _: NameNotFoundException => false } - tosComplianceStatus <- tosService.getTosComplianceStatus(user, samRequestContext) + tosComplianceStatus <- tosService.getTermsOfServiceComplianceStatus(user, samRequestContext) adminEnabled <- directoryDAO.isEnabled(user.id, samRequestContext) } yield { // We are removing references to LDAP but this will require an API version change here, so we are leaving @@ -382,7 +382,7 @@ class UserService( // Mixing up the endpoint to return user info AND status information is only causing problems and confusion def getUserStatusInfo(user: SamUser, samRequestContext: SamRequestContext): IO[UserStatusInfo] = for { - tosAcceptanceDetails <- tosService.getTosComplianceStatus(user, samRequestContext) + tosAcceptanceDetails <- tosService.getTermsOfServiceComplianceStatus(user, samRequestContext) } yield UserStatusInfo(user.id.value, user.email.value, tosAcceptanceDetails.permitsSystemUsage && user.enabled, user.enabled) def getUserStatusDiagnostics(userId: WorkbenchUserId, samRequestContext: SamRequestContext): IO[Option[UserStatusDiagnostics]] = @@ -390,7 +390,7 @@ class UserService( directoryDAO.loadUser(userId, samRequestContext).flatMap { case Some(user) => // pulled out of for comprehension to allow concurrent execution - val tosAcceptanceStatus = tosService.getTosComplianceStatus(user, samRequestContext) + val tosAcceptanceStatus = tosService.getTermsOfServiceComplianceStatus(user, samRequestContext) val adminEnabledStatus = directoryDAO.isEnabled(user.id, samRequestContext) val allUsersStatus = cloudExtensions.getOrCreateAllUsersGroup(directoryDAO, samRequestContext).flatMap { allUsersGroup => directoryDAO.isGroupMember(allUsersGroup.id, user.id, samRequestContext) recover { case e: NameNotFoundException => false } @@ -496,7 +496,7 @@ class UserService( def getUserAllowances(samUser: SamUser, samRequestContext: SamRequestContext): IO[SamUserAllowances] = for { - tosStatus <- tosService.getTosComplianceStatus(samUser, samRequestContext) + tosStatus <- tosService.getTermsOfServiceComplianceStatus(samUser, samRequestContext) } yield SamUserAllowances( allowed = samUser.enabled && tosStatus.permitsSystemUsage, enabled = samUser.enabled, diff --git a/src/test/scala/org/broadinstitute/dsde/workbench/sam/api/MockSamRoutesBuilder.scala b/src/test/scala/org/broadinstitute/dsde/workbench/sam/api/MockSamRoutesBuilder.scala index 94a33bd5a..d9be04155 100644 --- a/src/test/scala/org/broadinstitute/dsde/workbench/sam/api/MockSamRoutesBuilder.scala +++ b/src/test/scala/org/broadinstitute/dsde/workbench/sam/api/MockSamRoutesBuilder.scala @@ -77,8 +77,8 @@ class MockSamRoutesBuilder(allUsersGroup: WorkbenchGroup)(implicit system: Actor this } - def withTosHistoryForUser(samUser: SamUser, tosHistory: TermsOfServiceHistory): MockSamRoutesBuilder = { - mockTosServiceBuilder.withTosHistoryForUser(samUser, tosHistory) + def withTermsOfServiceHistoryForUser(samUser: SamUser, tosHistory: TermsOfServiceHistory): MockSamRoutesBuilder = { + mockTosServiceBuilder.withTermsOfServiceHistoryForUser(samUser, tosHistory) this } diff --git a/src/test/scala/org/broadinstitute/dsde/workbench/sam/api/TermsOfServiceRouteSpec.scala b/src/test/scala/org/broadinstitute/dsde/workbench/sam/api/TermsOfServiceRouteSpec.scala index 47405d8cc..9c031a380 100644 --- a/src/test/scala/org/broadinstitute/dsde/workbench/sam/api/TermsOfServiceRouteSpec.scala +++ b/src/test/scala/org/broadinstitute/dsde/workbench/sam/api/TermsOfServiceRouteSpec.scala @@ -164,7 +164,7 @@ class TermsOfServiceRouteSpec extends AnyFunSpec with Matchers with ScalatestRou val record2 = TermsOfServiceHistoryRecord(TosTable.REJECT, "0", Instant.now.minusSeconds(5)) val mockSamRoutesBuilder = new MockSamRoutesBuilder(allUsersGroup) .withEnabledUser(defaultUser) - .withTosHistoryForUser(defaultUser, TermsOfServiceHistory(List(record1, record2))) + .withTermsOfServiceHistoryForUser(defaultUser, TermsOfServiceHistory(List(record1, record2))) Get(s"/api/termsOfService/v1/user/${defaultUser.id}/history") ~> mockSamRoutesBuilder.build.route ~> check { withClue(s"${responseAs[String]} is not parsable as an instance of `TermsOfServiceHistoryRecord`.") { @@ -195,7 +195,7 @@ class TermsOfServiceRouteSpec extends AnyFunSpec with Matchers with ScalatestRou val record2 = TermsOfServiceHistoryRecord(TosTable.REJECT, "0", Instant.now.minusSeconds(5)) val mockSamRoutesBuilder = new MockSamRoutesBuilder(allUsersGroup) .withEnabledUser(defaultUser) - .withTosHistoryForUser(defaultUser, TermsOfServiceHistory(List(record1, record2))) + .withTermsOfServiceHistoryForUser(defaultUser, TermsOfServiceHistory(List(record1, record2))) Get(s"/api/termsOfService/v1/user/self/history") ~> mockSamRoutesBuilder.build.route ~> check { withClue(s"${responseAs[String]} is not parsable as an instance of `TermsOfServiceHistoryRecord`.") { diff --git a/src/test/scala/org/broadinstitute/dsde/workbench/sam/dataAccess/MockDirectoryDAO.scala b/src/test/scala/org/broadinstitute/dsde/workbench/sam/dataAccess/MockDirectoryDAO.scala index 72f6025cc..e32ca5ee2 100644 --- a/src/test/scala/org/broadinstitute/dsde/workbench/sam/dataAccess/MockDirectoryDAO.scala +++ b/src/test/scala/org/broadinstitute/dsde/workbench/sam/dataAccess/MockDirectoryDAO.scala @@ -330,14 +330,14 @@ class MockDirectoryDAO(val groups: mutable.Map[WorkbenchGroupIdentity, Workbench true } - override def getUserTos(userId: WorkbenchUserId, samRequestContext: SamRequestContext): IO[Option[SamUserTos]] = + override def getUserTermsOfService(userId: WorkbenchUserId, samRequestContext: SamRequestContext): IO[Option[SamUserTos]] = loadUser(userId, samRequestContext).map { case None => None case Some(_) => userTos.get(userId) } - override def getUserTosVersion(userId: WorkbenchUserId, tosVersion: Option[String], samRequestContext: SamRequestContext): IO[Option[SamUserTos]] = + override def getUserTermsOfServiceVersion(userId: WorkbenchUserId, tosVersion: Option[String], samRequestContext: SamRequestContext): IO[Option[SamUserTos]] = loadUser(userId, samRequestContext).map { case None => None case Some(_) => @@ -347,7 +347,7 @@ class MockDirectoryDAO(val groups: mutable.Map[WorkbenchGroupIdentity, Workbench } } - override def getUserTosHistory(userId: WorkbenchUserId, samRequestContext: SamRequestContext, limit: Integer): IO[List[SamUserTos]] = + override def getUserTermsOfServiceHistory(userId: WorkbenchUserId, samRequestContext: SamRequestContext, limit: Integer): IO[List[SamUserTos]] = loadUser(userId, samRequestContext).map { case None => List.empty case Some(_) => userTosHistory.getOrElse(userId, List.empty) diff --git a/src/test/scala/org/broadinstitute/dsde/workbench/sam/dataAccess/MockDirectoryDaoBuilder.scala b/src/test/scala/org/broadinstitute/dsde/workbench/sam/dataAccess/MockDirectoryDaoBuilder.scala index 9788c62f1..6a622e5a3 100644 --- a/src/test/scala/org/broadinstitute/dsde/workbench/sam/dataAccess/MockDirectoryDaoBuilder.scala +++ b/src/test/scala/org/broadinstitute/dsde/workbench/sam/dataAccess/MockDirectoryDaoBuilder.scala @@ -41,7 +41,7 @@ case class MockDirectoryDaoBuilder() extends IdiomaticMockito { mockedDirectoryDAO.setUserRegisteredAt(any[WorkbenchUserId], any[Instant], any[SamRequestContext]) returns IO.unit mockedDirectoryDAO.setUserAttributes(any[SamUserAttributes], any[SamRequestContext]) returns IO.unit mockedDirectoryDAO.getUserAttributes(any[WorkbenchUserId], any[SamRequestContext]) returns IO(None) - mockedDirectoryDAO.getUserTosVersion(any[WorkbenchUserId], any[Some[String]], any[SamRequestContext]) returns IO(None) + mockedDirectoryDAO.getUserTermsOfServiceVersion(any[WorkbenchUserId], any[Some[String]], any[SamRequestContext]) returns IO(None) def withHealthyDatabase: MockDirectoryDaoBuilder = { mockedDirectoryDAO.checkStatus(any[SamRequestContext]) returns IO(true) @@ -116,24 +116,24 @@ case class MockDirectoryDaoBuilder() extends IdiomaticMockito { def withAcceptedTermsOfServiceForUser(samUser: SamUser, tosVersion: String): MockDirectoryDaoBuilder = { makeUserExist(samUser) val samUserTos = SamUserTos(samUser.id, tosVersion, TosTable.ACCEPT, Instant.now) - mockedDirectoryDAO.getUserTos(eqTo(samUser.id), any[SamRequestContext]) returns IO(Option(samUserTos)) - mockedDirectoryDAO.getUserTosVersion(eqTo(samUser.id), eqTo(Some(tosVersion)), any[SamRequestContext]) returns IO(Option(samUserTos)) + mockedDirectoryDAO.getUserTermsOfService(eqTo(samUser.id), any[SamRequestContext]) returns IO(Option(samUserTos)) + mockedDirectoryDAO.getUserTermsOfServiceVersion(eqTo(samUser.id), eqTo(Some(tosVersion)), any[SamRequestContext]) returns IO(Option(samUserTos)) this } def withRejectedTermsOfServiceForUser(samUser: SamUser, tosVersion: String): MockDirectoryDaoBuilder = { makeUserExist(samUser) val samUserTos = SamUserTos(samUser.id, tosVersion, TosTable.REJECT, Instant.now) - mockedDirectoryDAO.getUserTos(eqTo(samUser.id), any[SamRequestContext]) returns IO(Option(samUserTos)) - mockedDirectoryDAO.getUserTosVersion(eqTo(samUser.id), eqTo(Some(tosVersion)), any[SamRequestContext]) returns IO(Option(samUserTos)) + mockedDirectoryDAO.getUserTermsOfService(eqTo(samUser.id), any[SamRequestContext]) returns IO(Option(samUserTos)) + mockedDirectoryDAO.getUserTermsOfServiceVersion(eqTo(samUser.id), eqTo(Some(tosVersion)), any[SamRequestContext]) returns IO(Option(samUserTos)) this } def withTermsOfServiceHistoryForUser(samUser: SamUser, tosHistory: List[SamUserTos]): MockDirectoryDaoBuilder = { makeUserExist(samUser) - mockedDirectoryDAO.getUserTos(eqTo(samUser.id), any[SamRequestContext]) returns IO(Option(tosHistory.head)) - mockedDirectoryDAO.getUserTosVersion(eqTo(samUser.id), any[Option[String]], any[SamRequestContext]) returns IO(Option(tosHistory.head)) - mockedDirectoryDAO.getUserTosHistory(eqTo(samUser.id), any[SamRequestContext], any[Integer]) returns IO(tosHistory) + mockedDirectoryDAO.getUserTermsOfService(eqTo(samUser.id), any[SamRequestContext]) returns IO(Option(tosHistory.head)) + mockedDirectoryDAO.getUserTermsOfServiceVersion(eqTo(samUser.id), any[Option[String]], any[SamRequestContext]) returns IO(Option(tosHistory.head)) + mockedDirectoryDAO.getUserTermsOfServiceHistory(eqTo(samUser.id), any[SamRequestContext], any[Integer]) returns IO(tosHistory) this } diff --git a/src/test/scala/org/broadinstitute/dsde/workbench/sam/dataAccess/PostgresDirectoryDAOSpec.scala b/src/test/scala/org/broadinstitute/dsde/workbench/sam/dataAccess/PostgresDirectoryDAOSpec.scala index 9b52f29e5..27624ef36 100644 --- a/src/test/scala/org/broadinstitute/dsde/workbench/sam/dataAccess/PostgresDirectoryDAOSpec.scala +++ b/src/test/scala/org/broadinstitute/dsde/workbench/sam/dataAccess/PostgresDirectoryDAOSpec.scala @@ -1601,7 +1601,7 @@ class PostgresDirectoryDAOSpec extends RetryableAnyFreeSpec with Matchers with B dao.acceptTermsOfService(defaultUser.id, tosConfig.version, samRequestContext).unsafeRunSync() shouldBe true // Assert - val userTos = dao.getUserTos(defaultUser.id, samRequestContext).unsafeRunSync() + val userTos = dao.getUserTermsOfService(defaultUser.id, samRequestContext).unsafeRunSync() userTos should not be empty userTos.get.createdAt should beAround(Instant.now()) userTos.get.action shouldBe TosTable.ACCEPT @@ -1615,7 +1615,7 @@ class PostgresDirectoryDAOSpec extends RetryableAnyFreeSpec with Matchers with B dao.acceptTermsOfService(defaultUser.id, "2", samRequestContext).unsafeRunSync() shouldBe true // Assert - val userTos = dao.getUserTos(defaultUser.id, samRequestContext).unsafeRunSync() + val userTos = dao.getUserTermsOfService(defaultUser.id, samRequestContext).unsafeRunSync() userTos should not be empty userTos.get.createdAt should beAround(Instant.now()) userTos.get.action shouldBe TosTable.ACCEPT @@ -1631,7 +1631,7 @@ class PostgresDirectoryDAOSpec extends RetryableAnyFreeSpec with Matchers with B dao.rejectTermsOfService(user.id, tosConfig.version, samRequestContext).unsafeRunSync() shouldBe true // Assert - val userTos = dao.getUserTos(user.id, samRequestContext).unsafeRunSync() + val userTos = dao.getUserTermsOfService(user.id, samRequestContext).unsafeRunSync() userTos should not be empty userTos.get.createdAt should beAround(Instant.now()) userTos.get.action shouldBe TosTable.REJECT @@ -1646,7 +1646,7 @@ class PostgresDirectoryDAOSpec extends RetryableAnyFreeSpec with Matchers with B dao.rejectTermsOfService(user.id, tosConfig.version, samRequestContext).unsafeRunSync() shouldBe true // Assert - val userTos = dao.getUserTos(user.id, samRequestContext).unsafeRunSync() + val userTos = dao.getUserTermsOfService(user.id, samRequestContext).unsafeRunSync() userTos should not be empty userTos.get.createdAt should beAround(Instant.now()) userTos.get.action shouldBe TosTable.REJECT @@ -1661,7 +1661,7 @@ class PostgresDirectoryDAOSpec extends RetryableAnyFreeSpec with Matchers with B dao.createUser(user, samRequestContext).unsafeRunSync() // Assert - val userTos = dao.getUserTos(user.id, samRequestContext).unsafeRunSync() + val userTos = dao.getUserTermsOfService(user.id, samRequestContext).unsafeRunSync() userTos should be(None) } } diff --git a/src/test/scala/org/broadinstitute/dsde/workbench/sam/service/MockTosServiceBuilder.scala b/src/test/scala/org/broadinstitute/dsde/workbench/sam/service/MockTosServiceBuilder.scala index 8d79602ea..6dda71e4f 100644 --- a/src/test/scala/org/broadinstitute/dsde/workbench/sam/service/MockTosServiceBuilder.scala +++ b/src/test/scala/org/broadinstitute/dsde/workbench/sam/service/MockTosServiceBuilder.scala @@ -30,7 +30,7 @@ case class MockTosServiceBuilder() extends MockitoSugar { this } - def withTosHistoryForUser(samUser: SamUser, tosHistory: TermsOfServiceHistory): MockTosServiceBuilder = { + def withTermsOfServiceHistoryForUser(samUser: SamUser, tosHistory: TermsOfServiceHistory): MockTosServiceBuilder = { lenient() .doReturn(IO.pure(tosHistory)) .when(tosService) @@ -47,7 +47,7 @@ case class MockTosServiceBuilder() extends MockitoSugar { lenient() .doAnswer((i: InvocationOnMock) => IO.pure(TermsOfServiceComplianceStatus(i.getArgument[SamUser](0).id, isAccepted, isAccepted))) .when(tosService) - .getTosComplianceStatus(any[SamUser], any[SamRequestContext]) + .getTermsOfServiceComplianceStatus(any[SamUser], any[SamRequestContext]) lenient() .doReturn(IO.raiseError(new WorkbenchExceptionWithErrorReport(ErrorReport(StatusCodes.NotFound, s"")(new ErrorReportSource("MockTosServiceBuilder"))))) @@ -67,7 +67,7 @@ case class MockTosServiceBuilder() extends MockitoSugar { lenient() .doReturn(IO.pure(TermsOfServiceComplianceStatus(samUser.id, isAccepted, isAccepted))) .when(tosService) - .getTosComplianceStatus(ArgumentMatchers.argThat(matchesUser), any[SamRequestContext]) + .getTermsOfServiceComplianceStatus(ArgumentMatchers.argThat(matchesUser), any[SamRequestContext]) val action = if (isAccepted) TosTable.ACCEPT else TosTable.REJECT val rightNow = Instant.now 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 0ffc28dc1..514fff9f9 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 @@ -84,28 +84,28 @@ class TosServiceSpec(_system: ActorSystem) "returns terms of service text when no query parameters are passed" in { val tosService = new TosService(NoExtensions, dirDAO, TestSupport.tosConfig) - val tosText = tosService.getTosText(Set.empty).unsafeRunSync() + val tosText = tosService.getTermsOfServiceText(Set.empty).unsafeRunSync() tosText shouldBe tosService.termsOfServiceText } "returns terms of service text by default" in { val tosService = new TosService(NoExtensions, dirDAO, TestSupport.tosConfig) - val tosText = tosService.getTosText(Set("termsOfService")).unsafeRunSync() + val tosText = tosService.getTermsOfServiceText(Set("termsOfService")).unsafeRunSync() tosText shouldBe tosService.termsOfServiceText } "returns privacy policy text" in { val tosService = new TosService(NoExtensions, dirDAO, TestSupport.tosConfig) - val tosText = tosService.getTosText(Set("privacyPolicy")).unsafeRunSync() + val tosText = tosService.getTermsOfServiceText(Set("privacyPolicy")).unsafeRunSync() tosText shouldBe tosService.privacyPolicyText } "returns privacy policy text and terms of service text" in { val tosService = new TosService(NoExtensions, dirDAO, TestSupport.tosConfig) - val tosText = tosService.getTosText(Set("privacyPolicy", "termsOfService")).unsafeRunSync() + val tosText = tosService.getTermsOfServiceText(Set("privacyPolicy", "termsOfService")).unsafeRunSync() tosText shouldBe s"${tosService.termsOfServiceText}\n\n${tosService.privacyPolicyText}" } @@ -139,11 +139,11 @@ class TosServiceSpec(_system: ActorSystem) val previousTosVersion = Option("1") val tosService = new TosService(NoExtensions, dirDAO, TestSupport.tosConfig.copy(version = tosVersion, previousVersion = previousTosVersion)) - when(dirDAO.getUserTos(serviceAccountUser.id, samRequestContext)).thenReturn(IO.pure(None)) + when(dirDAO.getUserTermsOfService(serviceAccountUser.id, samRequestContext)).thenReturn(IO.pure(None)) - when(dirDAO.getUserTosVersion(serviceAccountUser.id, previousTosVersion, samRequestContext)).thenReturn(IO.pure(None)) + when(dirDAO.getUserTermsOfServiceVersion(serviceAccountUser.id, previousTosVersion, samRequestContext)).thenReturn(IO.pure(None)) - val complianceStatus = tosService.getTosComplianceStatus(serviceAccountUser, samRequestContext).unsafeRunSync() + val complianceStatus = tosService.getTermsOfServiceComplianceStatus(serviceAccountUser, samRequestContext).unsafeRunSync() complianceStatus.permitsSystemUsage shouldBe true } @@ -152,11 +152,11 @@ class TosServiceSpec(_system: ActorSystem) val previousTosVersion = Option("1") val tosService = new TosService(NoExtensions, dirDAO, TestSupport.tosConfig.copy(version = tosVersion, previousVersion = previousTosVersion)) - when(dirDAO.getUserTos(uamiUser.id, samRequestContext)).thenReturn(IO.pure(None)) + when(dirDAO.getUserTermsOfService(uamiUser.id, samRequestContext)).thenReturn(IO.pure(None)) - when(dirDAO.getUserTosVersion(uamiUser.id, previousTosVersion, samRequestContext)).thenReturn(IO.pure(None)) + when(dirDAO.getUserTermsOfServiceVersion(uamiUser.id, previousTosVersion, samRequestContext)).thenReturn(IO.pure(None)) - val complianceStatus = tosService.getTosComplianceStatus(uamiUser, samRequestContext).unsafeRunSync() + val complianceStatus = tosService.getTermsOfServiceComplianceStatus(uamiUser, samRequestContext).unsafeRunSync() complianceStatus.permitsSystemUsage shouldBe true } @@ -232,13 +232,13 @@ class TosServiceSpec(_system: ActorSystem) ) ) - when(dirDAO.getUserTos(defaultUser.id, samRequestContext)) + when(dirDAO.getUserTermsOfService(defaultUser.id, samRequestContext)) .thenReturn(IO.pure(None)) - when(dirDAO.getUserTosVersion(defaultUser.id, previousTosVersion, samRequestContext)) + when(dirDAO.getUserTermsOfServiceVersion(defaultUser.id, previousTosVersion, samRequestContext)) .thenReturn(IO.pure(None)) - val complianceStatus = tosService.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() + val complianceStatus = tosService.getTermsOfServiceComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() complianceStatus.permitsSystemUsage shouldBe false } } @@ -264,13 +264,13 @@ class TosServiceSpec(_system: ActorSystem) withoutGracePeriod - { withoutRollingAcceptanceWindow - { cannotUseTheSystem in { - when(dirDAO.getUserTos(defaultUser.id, samRequestContext)) + when(dirDAO.getUserTermsOfService(defaultUser.id, samRequestContext)) .thenReturn(IO.pure(None)) - when(dirDAO.getUserTosVersion(defaultUser.id, previousVersionOpt, samRequestContext)) + when(dirDAO.getUserTermsOfServiceVersion(defaultUser.id, previousVersionOpt, samRequestContext)) .thenReturn(IO.pure(None)) // CASE 1 val complianceStatus = - tosServiceV2GracePeriodDisabledAcceptanceWindowDisabled.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() + tosServiceV2GracePeriodDisabledAcceptanceWindowDisabled.getTermsOfServiceComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() complianceStatus.permitsSystemUsage shouldBe false } } @@ -278,12 +278,12 @@ class TosServiceSpec(_system: ActorSystem) withGracePeriod - { withoutRollingAcceptanceWindow - { cannotUseTheSystem in { - when(dirDAO.getUserTos(defaultUser.id, samRequestContext)) + when(dirDAO.getUserTermsOfService(defaultUser.id, samRequestContext)) .thenReturn(IO.pure(None)) - when(dirDAO.getUserTosVersion(defaultUser.id, previousVersionOpt, samRequestContext)) + when(dirDAO.getUserTermsOfServiceVersion(defaultUser.id, previousVersionOpt, samRequestContext)) .thenReturn(IO.pure(None)) // CASE 4 - val complianceStatus = tosServiceV2GracePeriodEnabledAcceptanceWindowDisabled.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() + val complianceStatus = tosServiceV2GracePeriodEnabledAcceptanceWindowDisabled.getTermsOfServiceComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() complianceStatus.permitsSystemUsage shouldBe false } } @@ -291,12 +291,12 @@ class TosServiceSpec(_system: ActorSystem) withoutGracePeriod - { withRollingAcceptanceWindow - { cannotUseTheSystem in { - when(dirDAO.getUserTos(defaultUser.id, samRequestContext)) + when(dirDAO.getUserTermsOfService(defaultUser.id, samRequestContext)) .thenReturn(IO.pure(None)) - when(dirDAO.getUserTosVersion(defaultUser.id, previousVersionOpt, samRequestContext)) + when(dirDAO.getUserTermsOfServiceVersion(defaultUser.id, previousVersionOpt, samRequestContext)) .thenReturn(IO.pure(None)) // CASE 7 - val complianceStatus = tosServiceV2GracePeriodDisabledAcceptanceWindowEnabled.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() + val complianceStatus = tosServiceV2GracePeriodDisabledAcceptanceWindowEnabled.getTermsOfServiceComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() complianceStatus.permitsSystemUsage shouldBe false } } @@ -304,12 +304,12 @@ class TosServiceSpec(_system: ActorSystem) withGracePeriod - { withRollingAcceptanceWindow - { cannotUseTheSystem in { - when(dirDAO.getUserTos(defaultUser.id, samRequestContext)) + when(dirDAO.getUserTermsOfService(defaultUser.id, samRequestContext)) .thenReturn(IO.pure(None)) - when(dirDAO.getUserTosVersion(defaultUser.id, previousVersionOpt, samRequestContext)) + when(dirDAO.getUserTermsOfServiceVersion(defaultUser.id, previousVersionOpt, samRequestContext)) .thenReturn(IO.pure(None)) // CASE 10 - val complianceStatus = tosServiceV2GracePeriodEnabledAcceptanceWindowEnabled.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() + val complianceStatus = tosServiceV2GracePeriodEnabledAcceptanceWindowEnabled.getTermsOfServiceComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() complianceStatus.permitsSystemUsage shouldBe false } } @@ -319,13 +319,13 @@ class TosServiceSpec(_system: ActorSystem) withoutGracePeriod - { withoutRollingAcceptanceWindow - { cannotUseTheSystem in { - when(dirDAO.getUserTos(defaultUser.id, samRequestContext)) + when(dirDAO.getUserTermsOfService(defaultUser.id, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, previousVersion, TosTable.ACCEPT, Instant.now())))) - when(dirDAO.getUserTosVersion(defaultUser.id, previousVersionOpt, samRequestContext)) + when(dirDAO.getUserTermsOfServiceVersion(defaultUser.id, previousVersionOpt, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, previousVersion, TosTable.ACCEPT, Instant.now())))) // CASE 2 val complianceStatus = - tosServiceV2GracePeriodDisabledAcceptanceWindowDisabled.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() + tosServiceV2GracePeriodDisabledAcceptanceWindowDisabled.getTermsOfServiceComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() complianceStatus.permitsSystemUsage shouldBe false } } @@ -333,12 +333,12 @@ class TosServiceSpec(_system: ActorSystem) withGracePeriod - { withoutRollingAcceptanceWindow - { canUseTheSystem in { - when(dirDAO.getUserTos(defaultUser.id, samRequestContext)) + when(dirDAO.getUserTermsOfService(defaultUser.id, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, previousVersion, TosTable.ACCEPT, Instant.now())))) - when(dirDAO.getUserTosVersion(defaultUser.id, previousVersionOpt, samRequestContext)) + when(dirDAO.getUserTermsOfServiceVersion(defaultUser.id, previousVersionOpt, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, previousVersion, TosTable.ACCEPT, Instant.now())))) // CASE 5 - val complianceStatus = tosServiceV2GracePeriodEnabledAcceptanceWindowDisabled.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() + val complianceStatus = tosServiceV2GracePeriodEnabledAcceptanceWindowDisabled.getTermsOfServiceComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() complianceStatus.permitsSystemUsage shouldBe true } } @@ -346,12 +346,12 @@ class TosServiceSpec(_system: ActorSystem) withoutGracePeriod - { withRollingAcceptanceWindow - { canUseTheSystem in { - when(dirDAO.getUserTos(defaultUser.id, samRequestContext)) + when(dirDAO.getUserTermsOfService(defaultUser.id, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, previousVersion, TosTable.ACCEPT, Instant.now())))) - when(dirDAO.getUserTosVersion(defaultUser.id, previousVersionOpt, samRequestContext)) + when(dirDAO.getUserTermsOfServiceVersion(defaultUser.id, previousVersionOpt, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, previousVersion, TosTable.ACCEPT, Instant.now())))) // CASE 8 - val complianceStatus = tosServiceV2GracePeriodDisabledAcceptanceWindowEnabled.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() + val complianceStatus = tosServiceV2GracePeriodDisabledAcceptanceWindowEnabled.getTermsOfServiceComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() complianceStatus.permitsSystemUsage shouldBe true } } @@ -359,12 +359,12 @@ class TosServiceSpec(_system: ActorSystem) withGracePeriod - { withRollingAcceptanceWindow - { canUseTheSystem in { - when(dirDAO.getUserTos(defaultUser.id, samRequestContext)) + when(dirDAO.getUserTermsOfService(defaultUser.id, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, previousVersion, TosTable.ACCEPT, Instant.now())))) - when(dirDAO.getUserTosVersion(defaultUser.id, previousVersionOpt, samRequestContext)) + when(dirDAO.getUserTermsOfServiceVersion(defaultUser.id, previousVersionOpt, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, previousVersion, TosTable.ACCEPT, Instant.now())))) // CASE 11 - val complianceStatus = tosServiceV2GracePeriodEnabledAcceptanceWindowEnabled.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() + val complianceStatus = tosServiceV2GracePeriodEnabledAcceptanceWindowEnabled.getTermsOfServiceComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() complianceStatus.permitsSystemUsage shouldBe true } } @@ -374,13 +374,13 @@ class TosServiceSpec(_system: ActorSystem) withoutGracePeriod - { withoutRollingAcceptanceWindow - { canUseTheSystem in { - when(dirDAO.getUserTos(defaultUser.id, samRequestContext)) + when(dirDAO.getUserTermsOfService(defaultUser.id, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, tosVersion, TosTable.ACCEPT, Instant.now())))) - when(dirDAO.getUserTosVersion(defaultUser.id, previousVersionOpt, samRequestContext)) + when(dirDAO.getUserTermsOfServiceVersion(defaultUser.id, previousVersionOpt, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, previousVersion, TosTable.ACCEPT, Instant.now())))) // CASE 3 val complianceStatus = - tosServiceV2GracePeriodDisabledAcceptanceWindowDisabled.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() + tosServiceV2GracePeriodDisabledAcceptanceWindowDisabled.getTermsOfServiceComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() complianceStatus.permitsSystemUsage shouldBe true } } @@ -388,12 +388,12 @@ class TosServiceSpec(_system: ActorSystem) withGracePeriod - { withoutRollingAcceptanceWindow - { canUseTheSystem in { - when(dirDAO.getUserTos(defaultUser.id, samRequestContext)) + when(dirDAO.getUserTermsOfService(defaultUser.id, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, tosVersion, TosTable.ACCEPT, Instant.now())))) - when(dirDAO.getUserTosVersion(defaultUser.id, previousVersionOpt, samRequestContext)) + when(dirDAO.getUserTermsOfServiceVersion(defaultUser.id, previousVersionOpt, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, previousVersion, TosTable.ACCEPT, Instant.now())))) // CASE 6 - val complianceStatus = tosServiceV2GracePeriodEnabledAcceptanceWindowDisabled.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() + val complianceStatus = tosServiceV2GracePeriodEnabledAcceptanceWindowDisabled.getTermsOfServiceComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() complianceStatus.permitsSystemUsage shouldBe true } } @@ -401,12 +401,12 @@ class TosServiceSpec(_system: ActorSystem) withoutGracePeriod - { withRollingAcceptanceWindow - { canUseTheSystem in { - when(dirDAO.getUserTos(defaultUser.id, samRequestContext)) + when(dirDAO.getUserTermsOfService(defaultUser.id, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, tosVersion, TosTable.ACCEPT, Instant.now())))) - when(dirDAO.getUserTosVersion(defaultUser.id, previousVersionOpt, samRequestContext)) + when(dirDAO.getUserTermsOfServiceVersion(defaultUser.id, previousVersionOpt, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, previousVersion, TosTable.ACCEPT, Instant.now())))) // CASE 9 - val complianceStatus = tosServiceV2GracePeriodDisabledAcceptanceWindowEnabled.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() + val complianceStatus = tosServiceV2GracePeriodDisabledAcceptanceWindowEnabled.getTermsOfServiceComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() complianceStatus.permitsSystemUsage shouldBe true } } @@ -414,12 +414,12 @@ class TosServiceSpec(_system: ActorSystem) withGracePeriod - { withRollingAcceptanceWindow - { canUseTheSystem in { - when(dirDAO.getUserTos(defaultUser.id, samRequestContext)) + when(dirDAO.getUserTermsOfService(defaultUser.id, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, tosVersion, TosTable.ACCEPT, Instant.now())))) - when(dirDAO.getUserTosVersion(defaultUser.id, previousVersionOpt, samRequestContext)) + when(dirDAO.getUserTermsOfServiceVersion(defaultUser.id, previousVersionOpt, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, previousVersion, TosTable.ACCEPT, Instant.now())))) // CASE 12 - val complianceStatus = tosServiceV2GracePeriodEnabledAcceptanceWindowEnabled.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() + val complianceStatus = tosServiceV2GracePeriodEnabledAcceptanceWindowEnabled.getTermsOfServiceComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() complianceStatus.permitsSystemUsage shouldBe true } } @@ -430,13 +430,13 @@ class TosServiceSpec(_system: ActorSystem) withoutGracePeriod - { withoutRollingAcceptanceWindow - { cannotUseTheSystem in { - when(dirDAO.getUserTos(defaultUser.id, samRequestContext)) + when(dirDAO.getUserTermsOfService(defaultUser.id, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, tosVersion, TosTable.REJECT, Instant.now())))) - when(dirDAO.getUserTosVersion(defaultUser.id, previousVersionOpt, samRequestContext)) + when(dirDAO.getUserTermsOfServiceVersion(defaultUser.id, previousVersionOpt, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, previousVersion, TosTable.ACCEPT, Instant.now())))) val complianceStatus = - tosServiceV2GracePeriodDisabledAcceptanceWindowDisabled.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() + tosServiceV2GracePeriodDisabledAcceptanceWindowDisabled.getTermsOfServiceComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() complianceStatus.permitsSystemUsage shouldBe false } } @@ -444,12 +444,12 @@ class TosServiceSpec(_system: ActorSystem) withGracePeriod - { withoutRollingAcceptanceWindow - { cannotUseTheSystem in { - when(dirDAO.getUserTos(defaultUser.id, samRequestContext)) + when(dirDAO.getUserTermsOfService(defaultUser.id, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, tosVersion, TosTable.REJECT, Instant.now())))) - when(dirDAO.getUserTosVersion(defaultUser.id, previousVersionOpt, samRequestContext)) + when(dirDAO.getUserTermsOfServiceVersion(defaultUser.id, previousVersionOpt, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, previousVersion, TosTable.ACCEPT, Instant.now())))) - val complianceStatus = tosServiceV2GracePeriodEnabledAcceptanceWindowDisabled.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() + val complianceStatus = tosServiceV2GracePeriodEnabledAcceptanceWindowDisabled.getTermsOfServiceComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() complianceStatus.permitsSystemUsage shouldBe false } } @@ -457,12 +457,12 @@ class TosServiceSpec(_system: ActorSystem) withoutGracePeriod - { withRollingAcceptanceWindow - { canUseTheSystem in { - when(dirDAO.getUserTos(defaultUser.id, samRequestContext)) + when(dirDAO.getUserTermsOfService(defaultUser.id, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, tosVersion, TosTable.REJECT, Instant.now())))) - when(dirDAO.getUserTosVersion(defaultUser.id, previousVersionOpt, samRequestContext)) + when(dirDAO.getUserTermsOfServiceVersion(defaultUser.id, previousVersionOpt, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, previousVersion, TosTable.ACCEPT, Instant.now())))) - val complianceStatus = tosServiceV2GracePeriodDisabledAcceptanceWindowEnabled.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() + val complianceStatus = tosServiceV2GracePeriodDisabledAcceptanceWindowEnabled.getTermsOfServiceComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() complianceStatus.permitsSystemUsage shouldBe false } } @@ -470,12 +470,12 @@ class TosServiceSpec(_system: ActorSystem) withGracePeriod - { withRollingAcceptanceWindow - { cannotUseTheSystem in { - when(dirDAO.getUserTos(defaultUser.id, samRequestContext)) + when(dirDAO.getUserTermsOfService(defaultUser.id, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, tosVersion, TosTable.REJECT, Instant.now())))) - when(dirDAO.getUserTosVersion(defaultUser.id, previousVersionOpt, samRequestContext)) + when(dirDAO.getUserTermsOfServiceVersion(defaultUser.id, previousVersionOpt, samRequestContext)) .thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, previousVersion, TosTable.ACCEPT, Instant.now())))) - val complianceStatus = tosServiceV2GracePeriodEnabledAcceptanceWindowEnabled.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() + val complianceStatus = tosServiceV2GracePeriodEnabledAcceptanceWindowEnabled.getTermsOfServiceComplianceStatus(defaultUser, samRequestContext).unsafeRunSync() complianceStatus.permitsSystemUsage shouldBe false } } @@ -484,12 +484,12 @@ class TosServiceSpec(_system: ActorSystem) "when a service account is using the api" - { "let it use the api regardless of tos status" in { - when(dirDAO.getUserTos(serviceAccountUser.id, samRequestContext)) + when(dirDAO.getUserTermsOfService(serviceAccountUser.id, samRequestContext)) .thenReturn(IO.pure(None)) - when(dirDAO.getUserTosVersion(serviceAccountUser.id, previousVersionOpt, samRequestContext)) + when(dirDAO.getUserTermsOfServiceVersion(serviceAccountUser.id, previousVersionOpt, samRequestContext)) .thenReturn(IO.pure(None)) val complianceStatus = - tosServiceV2GracePeriodDisabledAcceptanceWindowDisabled.getTosComplianceStatus(serviceAccountUser, samRequestContext).unsafeRunSync() + tosServiceV2GracePeriodDisabledAcceptanceWindowDisabled.getTermsOfServiceComplianceStatus(serviceAccountUser, samRequestContext).unsafeRunSync() complianceStatus.permitsSystemUsage shouldBe true } } diff --git a/src/test/scala/org/broadinstitute/dsde/workbench/sam/service/UserServiceSpec.scala b/src/test/scala/org/broadinstitute/dsde/workbench/sam/service/UserServiceSpec.scala index 9d3b0896d..131f636d4 100644 --- a/src/test/scala/org/broadinstitute/dsde/workbench/sam/service/UserServiceSpec.scala +++ b/src/test/scala/org/broadinstitute/dsde/workbench/sam/service/UserServiceSpec.scala @@ -137,7 +137,7 @@ class OldUserServiceMockSpec(_system: ActorSystem) when(googleExtensions.onGroupUpdate(any[Seq[WorkbenchGroupIdentity]], any[SamRequestContext])).thenReturn(IO.unit) mockTosService = mock[TosService](RETURNS_SMART_NULLS) - when(mockTosService.getTosComplianceStatus(any[SamUser], any[SamRequestContext])) + when(mockTosService.getTermsOfServiceComplianceStatus(any[SamUser], any[SamRequestContext])) .thenAnswer((i: InvocationOnMock) => IO.pure(TermsOfServiceComplianceStatus(i.getArgument[SamUser](0).id, true, true))) service = Mockito.spy(new UserService(dirDAO, googleExtensions, Seq(blockedDomain), mockTosService)) @@ -168,7 +168,7 @@ class OldUserServiceMockSpec(_system: ActorSystem) } it should "return UserStatusDiagnostics.tosAccepted as false if user's TOS status is false" in { - when(mockTosService.getTosComplianceStatus(enabledUser, samRequestContext)) + when(mockTosService.getTermsOfServiceComplianceStatus(enabledUser, samRequestContext)) .thenReturn(IO.pure(TermsOfServiceComplianceStatus(enabledUser.id, false, false))) val status = service.getUserStatusDiagnostics(enabledUser.id, samRequestContext).unsafeRunSync() status.value.tosAccepted shouldBe false