diff --git a/myndla-api/src/main/scala/no/ndla/myndlaapi/MyNDLAAuthHelpers.scala b/myndla-api/src/main/scala/no/ndla/myndlaapi/MyNDLAAuthHelpers.scala index 60988b538..9597ea409 100644 --- a/myndla-api/src/main/scala/no/ndla/myndlaapi/MyNDLAAuthHelpers.scala +++ b/myndla-api/src/main/scala/no/ndla/myndlaapi/MyNDLAAuthHelpers.scala @@ -18,12 +18,13 @@ import sttp.tapir.* import sttp.tapir.server.PartialServerEndpoint trait MyNDLAAuthHelpers { - this: UserService with TapirErrorHandling => + this: UserService & TapirErrorHandling => object MyNDLAAuthHelpers { implicit class authlessEndpointFeideExtension[A, I, E, O, R](self: Endpoint[Unit, I, AllErrors, O, R]) { - type MaybeFeideToken = Option[FeideAccessToken] - type PartialFeideEndpoint[F[_]] = PartialServerEndpoint[MaybeFeideToken, MyNDLAUser, I, AllErrors, O, R, F] + private type MaybeFeideToken = Option[FeideAccessToken] + private type PartialFeideEndpoint[F[_]] = + PartialServerEndpoint[MaybeFeideToken, MyNDLAUser, I, AllErrors, O, R, F] def requireMyNDLAUser[F[_]]( requireArena: Boolean = false, requireArenaAdmin: Boolean = false @@ -37,7 +38,7 @@ trait MyNDLAAuthHelpers { case Left(err) => Left(err) } } else if (requireArena) userService.getArenaEnabledUser(maybeToken).handleErrorsOrOk - else userService.getMyNdlaUserDataDomain(maybeToken, List.empty).handleErrorsOrOk + else userService.getMyNdlaUserDataDomain(maybeToken).handleErrorsOrOk } val securityLogic = (m: MonadError[F]) => (a: Option[FeideAccessToken]) => m.unit(authFunc(a)) PartialServerEndpoint(newEndpoint, securityLogic) diff --git a/myndla-api/src/main/scala/no/ndla/myndlaapi/service/ArenaReadService.scala b/myndla-api/src/main/scala/no/ndla/myndlaapi/service/ArenaReadService.scala index 0d0b0256b..7d4fb228d 100644 --- a/myndla-api/src/main/scala/no/ndla/myndlaapi/service/ArenaReadService.scala +++ b/myndla-api/src/main/scala/no/ndla/myndlaapi/service/ArenaReadService.scala @@ -593,7 +593,7 @@ trait ArenaReadService { for { feideToken <- feideApiClient.getFeideAccessTokenOrFail(feideAccessToken) feideId <- feideApiClient.getFeideID(feideAccessToken) - user <- userService.getOrCreateMyNDLAUserIfNotExist(feideId, feideAccessToken, List.empty)(session) + user <- userService.getOrCreateMyNDLAUserIfNotExist(feideId, feideAccessToken)(session) nodebbUserId <- nodebb.getUserId(feideToken) _ <- arenaRepository.disconnectPostsByUser(user.id)(session) _ <- arenaRepository.disconnectTopicsByUser(user.id)(session) diff --git a/myndla-api/src/main/scala/no/ndla/myndlaapi/service/FolderConverterService.scala b/myndla-api/src/main/scala/no/ndla/myndlaapi/service/FolderConverterService.scala index 8a8bf4fd6..7419a4550 100644 --- a/myndla-api/src/main/scala/no/ndla/myndlaapi/service/FolderConverterService.scala +++ b/myndla-api/src/main/scala/no/ndla/myndlaapi/service/FolderConverterService.scala @@ -180,7 +180,7 @@ trait FolderConverterService { } def toApiUserData( - domainUserData: DomainMyNDLAUser, + domainUserData: DomainMyNDLAUser ): model.api.myndla.MyNDLAUserDTO = { model.api.myndla.MyNDLAUserDTO( id = domainUserData.id, diff --git a/myndla-api/src/main/scala/no/ndla/myndlaapi/service/FolderReadService.scala b/myndla-api/src/main/scala/no/ndla/myndlaapi/service/FolderReadService.scala index b7f795ebc..f715a0fcf 100644 --- a/myndla-api/src/main/scala/no/ndla/myndlaapi/service/FolderReadService.scala +++ b/myndla-api/src/main/scala/no/ndla/myndlaapi/service/FolderReadService.scala @@ -271,12 +271,10 @@ trait FolderReadService { feideAccessToken: Option[FeideAccessToken] ): Try[MyNDLAUserDTO] = for { - users <- configService.getMyNDLAEnabledUsers user <- userRepository.rollbackOnFailure(session => - userService.getOrCreateMyNDLAUserIfNotExist(feideId, feideAccessToken, users)(session) + userService.getOrCreateMyNDLAUserIfNotExist(feideId, feideAccessToken)(session) ) - orgs <- configService.getMyNDLAEnabledOrgs - } yield folderConverterService.toApiUserData(user, orgs) + } yield folderConverterService.toApiUserData(user) def getStats: Option[api.StatsDTO] = { implicit val session: DBSession = folderRepository.getSession(true) diff --git a/myndla-api/src/main/scala/no/ndla/myndlaapi/service/FolderWriteService.scala b/myndla-api/src/main/scala/no/ndla/myndlaapi/service/FolderWriteService.scala index 3b4d0615b..46f7dd03b 100644 --- a/myndla-api/src/main/scala/no/ndla/myndlaapi/service/FolderWriteService.scala +++ b/myndla-api/src/main/scala/no/ndla/myndlaapi/service/FolderWriteService.scala @@ -60,7 +60,7 @@ trait FolderWriteService { private def getMyNDLAUser(feideId: FeideID, feideAccessToken: Option[FeideAccessToken]): Try[MyNDLAUser] = { userRepository.rollbackOnFailure(session => - userService.getOrCreateMyNDLAUserIfNotExist(feideId, feideAccessToken, List.empty)(session) + userService.getOrCreateMyNDLAUserIfNotExist(feideId, feideAccessToken)(session) ) } diff --git a/myndla-api/src/main/scala/no/ndla/myndlaapi/service/UserService.scala b/myndla-api/src/main/scala/no/ndla/myndlaapi/service/UserService.scala index 5112b8510..db5d6a7d6 100644 --- a/myndla-api/src/main/scala/no/ndla/myndlaapi/service/UserService.scala +++ b/myndla-api/src/main/scala/no/ndla/myndlaapi/service/UserService.scala @@ -57,7 +57,7 @@ trait UserService { } def getMyNdlaUserDataDomain( - feideAccessToken: Option[FeideAccessToken], + feideAccessToken: Option[FeideAccessToken] ): Try[MyNDLAUser] = { for { feideId <- feideApiClient.getFeideID(feideAccessToken) @@ -70,7 +70,8 @@ trait UserService { def getArenaEnabledUser(feideAccessToken: Option[FeideAccessToken]): Try[MyNDLAUser] = { for { userData <- getMyNdlaUserDataDomain(feideAccessToken) - user <- if (userData.arenaEnabled) Success(userData) else Failure(AccessDeniedException("User is not arena enabled")) + user <- + if (userData.arenaEnabled) Success(userData) else Failure(AccessDeniedException("User is not arena enabled")) } yield user } @@ -83,7 +84,7 @@ trait UserService { def getOrCreateMyNDLAUserIfNotExist( feideId: FeideID, - feideAccessToken: Option[FeideAccessToken], + feideAccessToken: Option[FeideAccessToken] )(implicit session: DBSession): Try[MyNDLAUser] = { userRepository.reserveFeideIdIfNotExists(feideId)(session).flatMap { case false => createMyNDLAUser(feideId, feideAccessToken)(session) @@ -148,7 +149,7 @@ trait UserService { updaterMyNdla: Option[MyNDLAUser] )(session: DBSession = AutoSession): Try[myndla.MyNDLAUserDTO] = { for { - existing <- userService.getUserById(userId)(session) + existing <- userService.getUserById(userId)(session) converted <- folderConverterService.mergeUserData( existing, updatedUser, @@ -191,7 +192,7 @@ trait UserService { private def createMyNDLAUser( feideId: FeideID, - feideAccessToken: Option[FeideAccessToken], + feideAccessToken: Option[FeideAccessToken] )(implicit session: DBSession ): Try[MyNDLAUser] = { @@ -220,14 +221,14 @@ trait UserService { private def fetchDataAndUpdateMyNDLAUser( feideId: FeideID, feideAccessToken: Option[FeideAccessToken], - userData: MyNDLAUser, + userData: MyNDLAUser )(implicit session: DBSession ): Try[MyNDLAUser] = { val feideUser = feideApiClient.getFeideExtendedUser(feideAccessToken).? val organization = feideApiClient.getOrganization(feideAccessToken).? val feideGroups = feideApiClient.getFeideGroups(feideAccessToken).? - val userRole = if (feideUser.isTeacher) UserRole.EMPLOYEE else UserRole.STUDENT + val userRole = if (feideUser.isTeacher) UserRole.EMPLOYEE else UserRole.STUDENT val updatedMyNDLAUser = MyNDLAUser( id = userData.id, feideId = userData.feideId, diff --git a/myndla-api/src/test/scala/no/ndla/myndlaapi/service/FolderConverterServiceTest.scala b/myndla-api/src/test/scala/no/ndla/myndlaapi/service/FolderConverterServiceTest.scala index cc3d155bd..9a2f50b82 100644 --- a/myndla-api/src/test/scala/no/ndla/myndlaapi/service/FolderConverterServiceTest.scala +++ b/myndla-api/src/test/scala/no/ndla/myndlaapi/service/FolderConverterServiceTest.scala @@ -448,7 +448,7 @@ class FolderConverterServiceTest extends UnitTestSuite with TestEnvironment { arenaGroups = List.empty ) - service.toApiUserData(domainUserData, List.empty) should be(expectedUserData) + service.toApiUserData(domainUserData) should be(expectedUserData) } test("That mergeUserData works correctly") { @@ -563,13 +563,13 @@ class FolderConverterServiceTest extends UnitTestSuite with TestEnvironment { arenaAccepted = true ) - service.mergeUserData(domainUserData, updatedUserData1, None, None, List.empty, List.empty, None).get should be( + service.mergeUserData(domainUserData, updatedUserData1, None, None, None).get should be( expectedUserData1 ) - service.mergeUserData(domainUserData, updatedUserData2, None, None, List.empty, List.empty, None).get should be( + service.mergeUserData(domainUserData, updatedUserData2, None, None, None).get should be( expectedUserData2 ) - service.mergeUserData(domainUserData, updatedUserData3, None, None, List.empty, List.empty, None).get should be( + service.mergeUserData(domainUserData, updatedUserData3, None, None, None).get should be( expectedUserData3 ) } diff --git a/myndla-api/src/test/scala/no/ndla/myndlaapi/service/FolderWriteServiceTest.scala b/myndla-api/src/test/scala/no/ndla/myndlaapi/service/FolderWriteServiceTest.scala index 0938ffd6a..81f25300c 100644 --- a/myndla-api/src/test/scala/no/ndla/myndlaapi/service/FolderWriteServiceTest.scala +++ b/myndla-api/src/test/scala/no/ndla/myndlaapi/service/FolderWriteServiceTest.scala @@ -58,7 +58,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { when(folderRepository.foldersWithFeideAndParentID(any, any)(any)).thenReturn(Success(List.empty)) when(feideApiClient.getFeideID(any)).thenReturn(Success(wrongFeideId)) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) when(folderRepository.folderResourceConnectionCount(any)(any)).thenReturn(Success(0)) when(folderRepository.folderWithId(eqTo(id))(any)).thenReturn(Success(folderWithChildren)) @@ -96,7 +96,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { }) when(folderRepository.foldersWithFeideAndParentID(any, any)(any)).thenReturn(Success(List.empty)) when(feideApiClient.getFeideID(any)).thenReturn(Success(correctFeideId)) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) when(folderRepository.folderResourceConnectionCount(any)(any[DBSession])).thenReturn(Success(1)) when(folderRepository.folderWithId(eqTo(mainFolderId))(any)).thenReturn(Success(folder)) when(folderReadService.getSingleFolderWithContent(eqTo(folder.id), any, eqTo(true))(any)) @@ -146,7 +146,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { }) when(folderRepository.foldersWithFeideAndParentID(any, any)(any)).thenReturn(Success(List.empty)) when(feideApiClient.getFeideID(any)).thenReturn(Success(correctFeideId)) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) when(folderRepository.folderResourceConnectionCount(eqTo(resourceId))(any)).thenReturn(Success(5)) when(folderRepository.folderWithId(eqTo(mainFolderId))(any)).thenReturn(Success(folder)) when(folderReadService.getSingleFolderWithContent(eqTo(folder.id), any, eqTo(true))(any)) @@ -181,7 +181,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { val folderResource = FolderResource(folderId = folder.id, resourceId = resource.id, rank = 1, clock.now()) when(feideApiClient.getFeideID(any)).thenReturn(Success(correctFeideId)) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) when(folderRepository.folderWithId(eqTo(folderId))(any)).thenReturn(Success(folder)) when(folderRepository.resourceWithId(eqTo(resourceId))(any)).thenReturn(Success(resource)) when(folderRepository.folderResourceConnectionCount(eqTo(resourceId))(any)).thenReturn(Success(2)) @@ -214,7 +214,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { val folderResource = FolderResource(folderId = folder.id, resourceId = resource.id, rank = 1, clock.now()) when(feideApiClient.getFeideID(any)).thenReturn(Success(correctFeideId)) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) when(folderRepository.folderWithId(eqTo(folderId))(any)).thenReturn(Success(folder)) when(folderRepository.resourceWithId(eqTo(resourceId))(any)).thenReturn(Success(resource)) when(folderRepository.folderResourceConnectionCount(eqTo(resourceId))(any)).thenReturn(Success(1)) @@ -246,7 +246,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { val folder = emptyDomainFolder.copy(id = folderId, feideId = "asd") when(feideApiClient.getFeideID(any)).thenReturn(Success(correctFeideId)) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) when(folderRepository.folderWithId(eqTo(folderId))(any)).thenReturn(Success(folder)) val res = service.deleteConnection(folderId, resourceId, None) @@ -268,7 +268,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { val resource = emptyDomainResource.copy(id = resourceId, feideId = "asd") when(feideApiClient.getFeideID(any)).thenReturn(Success(correctFeideId)) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) when(folderRepository.folderWithId(eqTo(folderId))(any)).thenReturn(Success(folder)) when(folderRepository.resourceWithId(eqTo(resourceId))(any)).thenReturn(Success(resource)) @@ -441,7 +441,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { ) when(feideApiClient.getFeideID(any)).thenReturn(Success("FEIDEF")) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) when(folderRepository.folderWithId(eqTo(folder1Id))(any[DBSession])).thenReturn(Success(folder1)) when(folderReadService.getSingleFolderWithContent(eqTo(folder1Id), eqTo(true), eqTo(true))(any[DBSession])) .thenReturn(Success(folder1)) @@ -502,7 +502,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { val newFolder = NewFolderDTO(name = "asd", parentId = Some(parentId.toString), status = None, description = None) when(feideApiClient.getFeideID(any)).thenReturn(Success(feideId)) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) doReturn(Success(parentId)) .when(folderConverterService) .toUUIDValidated(eqTo(Some(parentId.toString)), eqTo("parentId")) @@ -560,7 +560,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { val belowLimit: Long = MaxFolderDepth - 2 when(feideApiClient.getFeideID(any)).thenReturn(Success(feideId)) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) doReturn(Success(parentId)) .when(folderConverterService) .toUUIDValidated(eqTo(Some(parentId.toString)), eqTo("parentId")) @@ -619,7 +619,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { val belowLimit = MaxFolderDepth - 2 when(feideApiClient.getFeideID(any)).thenReturn(Success(feideId)) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) doReturn(Success(parentId)) .when(folderConverterService) .toUUIDValidated(eqTo(Some(parentId.toString)), eqTo("parentId")) @@ -681,7 +681,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { val belowLimit = MaxFolderDepth - 2 when(feideApiClient.getFeideID(any)).thenReturn(Success(feideId)) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) doReturn(Success(parentId)) .when(folderConverterService) .toUUIDValidated(eqTo(Some(parentId.toString)), eqTo("parentId")) @@ -760,7 +760,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { val belowLimit = MaxFolderDepth - 2 when(feideApiClient.getFeideID(any)).thenReturn(Success(feideId)) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) doReturn(Success(parentId)) .when(folderConverterService) .toUUIDValidated(eqTo(Some(parentId.toString)), eqTo("parentId")) @@ -830,7 +830,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { func(mock[DBSession]) }) when(feideApiClient.getFeideID(any)).thenReturn(Success(feideId)) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) when(folderRepository.setFolderRank(any, any, any)(any)).thenReturn(Success(())) when(folderRepository.setResourceConnectionRank(any, any, any)(any)).thenReturn(Success(())) when(folderRepository.folderWithFeideId(eqTo(parent.id), any)(any)).thenReturn(Success(parent)) @@ -931,7 +931,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { ) { val myNDLAUser = emptyMyNDLAUser.copy(userRole = UserRole.EMPLOYEE) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(myNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(myNDLAUser)) when(configService.isWriteRestricted).thenReturn(Success(true)) val result = service.canWriteDuringMyNDLAWriteRestrictionsOrAccessDenied("spiller ing", Some("en rolle")) @@ -943,7 +943,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { ) { val myNDLAUser = emptyMyNDLAUser.copy(userRole = UserRole.STUDENT) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(myNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(myNDLAUser)) when(configService.isMyNDLAWriteRestricted).thenReturn(Success(true)) val result = service.canWriteDuringMyNDLAWriteRestrictionsOrAccessDenied("spiller ing", Some("en rolle")) @@ -955,7 +955,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { ) { val myNDLAUser = emptyMyNDLAUser.copy(userRole = UserRole.STUDENT) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(myNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(myNDLAUser)) when(configService.isMyNDLAWriteRestricted).thenReturn(Success(false)) val result = service.canWriteDuringMyNDLAWriteRestrictionsOrAccessDenied("spiller ing", Some("en rolle")) @@ -964,7 +964,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { test("that isOperationAllowedOrAccessDenied denies access if user is student and wants to share a folder") { val myNDLAUser = emptyMyNDLAUser.copy(userRole = UserRole.STUDENT) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(myNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(myNDLAUser)) val updatedFolder = api.UpdatedFolderDTO(name = None, status = Some("shared"), description = None) val Failure(result) = service.isOperationAllowedOrAccessDenied("feideid", Some("accesstoken"), updatedFolder) @@ -975,7 +975,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { "that isOperationAllowedOrAccessDenied denies access if user is student and wants to update a folder during exam" ) { val myNDLAUser = emptyMyNDLAUser.copy(userRole = UserRole.STUDENT) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(myNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(myNDLAUser)) when(configService.isMyNDLAWriteRestricted).thenReturn(Success(true)) val updatedFolder = api.UpdatedFolderDTO(name = Some("asd"), status = None, description = None) @@ -985,7 +985,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { test("that isOperationAllowedOrAccessDenied allows student to update a folder outside of the examination time") { val myNDLAUser = emptyMyNDLAUser.copy(userRole = UserRole.STUDENT) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(myNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(myNDLAUser)) when(configService.isMyNDLAWriteRestricted).thenReturn(Success(false)) val updatedFolder = api.UpdatedFolderDTO(name = Some("asd"), status = None, description = None) @@ -997,7 +997,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { "that isOperationAllowedOrAccessDenied allows teacher to cut the cake and eat it too" ) { val myNDLAUser = emptyMyNDLAUser.copy(userRole = UserRole.EMPLOYEE) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(myNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(myNDLAUser)) when(configService.isMyNDLAWriteRestricted).thenReturn(Success(true)) val folderWithUpdatedName = api.UpdatedFolderDTO(name = Some("asd"), status = None, description = None) @@ -1016,7 +1016,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { val myNDLAUser = emptyMyNDLAUser.copy(userRole = UserRole.EMPLOYEE) val folder = emptyDomainFolder.copy(id = folderId, status = FolderStatus.SHARED) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(myNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(myNDLAUser)) when(configService.isMyNDLAWriteRestricted).thenReturn(Success(true)) when(feideApiClient.getFeideID(any)).thenReturn(Success(feideId)) when(folderRepository.createFolderUserConnection(any, any, any)(any)) @@ -1036,7 +1036,7 @@ class FolderWriteServiceTest extends UnitTestSuite with TestEnvironment { val myNDLAUser = emptyMyNDLAUser.copy(userRole = UserRole.EMPLOYEE) val folder = emptyDomainFolder.copy(id = folderId, feideId = feideId, status = FolderStatus.SHARED) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(myNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(myNDLAUser)) when(configService.isMyNDLAWriteRestricted).thenReturn(Success(true)) when(feideApiClient.getFeideID(any)).thenReturn(Success(feideId)) when(folderRepository.getFoldersAndSubfoldersIds(any)(any)).thenReturn(Success(List(folderId, folderIdChild))) diff --git a/myndla-api/src/test/scala/no/ndla/myndlaapi/service/UserServiceTest.scala b/myndla-api/src/test/scala/no/ndla/myndlaapi/service/UserServiceTest.scala index f632f2067..f49fd31c5 100644 --- a/myndla-api/src/test/scala/no/ndla/myndlaapi/service/UserServiceTest.scala +++ b/myndla-api/src/test/scala/no/ndla/myndlaapi/service/UserServiceTest.scala @@ -105,7 +105,7 @@ class UserServiceTest extends UnitTestSuite with TestEnvironment { .when(folderWriteService) .canWriteDuringMyNDLAWriteRestrictionsOrAccessDenied("feide", Some("feide")) when(feideApiClient.getFeideID(any)).thenReturn(Success(feideId)) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) when(configService.getMyNDLAEnabledOrgs).thenReturn(Success(List.empty)) when(configService.getMyNDLAEnabledUsers).thenReturn(Success(List.empty)) when(userRepository.userWithFeideId(eqTo(feideId))(any)).thenReturn(Success(Some(userBefore))) @@ -131,7 +131,7 @@ class UserServiceTest extends UnitTestSuite with TestEnvironment { .when(folderWriteService) .canWriteDuringMyNDLAWriteRestrictionsOrAccessDenied("feide", Some("feide")) when(feideApiClient.getFeideID(any)).thenReturn(Success(feideId)) - when(userService.getOrCreateMyNDLAUserIfNotExist(any, any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) + when(userService.getOrCreateMyNDLAUserIfNotExist(any, any)(any)).thenReturn(Success(emptyMyNDLAUser)) when(userRepository.userWithFeideId(eqTo(feideId))(any)).thenReturn(Success(None)) service.updateMyNDLAUserData(updatedUserData, Some(feideId)) should be(