Skip to content

Commit

Permalink
myndla-api: Add arenaAccepted flag
Browse files Browse the repository at this point in the history
This is currently just a dumb boolean field that a user can set that the
frontend can use to determine whether or not it should link to arena.
  • Loading branch information
jnatten committed Jan 21, 2025
1 parent cbcbeb6 commit 7af794a
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,17 @@ object MyNDLAUserDTO {
implicit def decoder: Decoder[MyNDLAUserDTO] = deriveDecoder
}

// format: off
case class UpdatedMyNDLAUserDTO(
@description("Favorite subjects of the user") favoriteSubjects: Option[Seq[String]],
@description("Whether arena should explicitly be enabled for the user") arenaEnabled: Option[Boolean],
@description("Whether users name should be shared with folder or not") shareName: Option[Boolean],
@description("Which arena groups the user should be in, only modifiable by admins") arenaGroups: Option[List[ArenaGroup]]
@description("Favorite subjects of the user")
favoriteSubjects: Option[Seq[String]],
@description("Whether arena should explicitly be enabled for the user")
arenaEnabled: Option[Boolean],
@description("Whether users name should be shared with folder or not")
shareName: Option[Boolean],
@description("Which arena groups the user should be in, only modifiable by admins")
arenaGroups: Option[List[ArenaGroup]],
@description("Whether the user has accepted the use of arena")
arenaAccept: Option[Boolean]
)

object UpdatedMyNDLAUserDTO {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ case class MyNDLAUser(
displayName: String,
email: String,
arenaEnabled: Boolean,
arenaAccepted: Boolean,
arenaGroups: List[ArenaGroup],
shareName: Boolean
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ case class MyNDLAUserDocument(
displayName: String,
email: String,
arenaEnabled: Boolean,
arenaAccepted: Boolean,
arenaGroups: List[ArenaGroup],
shareName: Boolean
) {
Expand All @@ -38,6 +39,7 @@ case class MyNDLAUserDocument(
displayName = displayName,
email = email,
arenaEnabled = arenaEnabled,
arenaAccepted = arenaAccepted,
shareName = shareName,
arenaGroups = arenaGroups
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ trait FolderConverterService {
domainUserData.arenaEnabled || arenaEnabledUsers.map(_.toLowerCase).contains(domainUserData.email.toLowerCase)
}

val arenaAccepted = updatedUser.arenaAccept match {
case Some(true) if arenaEnabled => true
case Some(false) => false
case _ => domainUserData.arenaAccepted
}

val arenaGroups =
if (updaterUser.exists(_.isAdmin)) updatedUser.arenaGroups.getOrElse(domainUserData.arenaGroups)
else domainUserData.arenaGroups
Expand All @@ -260,7 +266,8 @@ trait FolderConverterService {
arenaEnabled = arenaEnabled,
shareName = shareName,
displayName = domainUserData.displayName,
arenaGroups = arenaGroups
arenaGroups = arenaGroups,
arenaAccepted = arenaAccepted
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ trait ImportService {
email = "[email protected]",
arenaEnabled = true,
arenaGroups = List(ArenaGroup.ADMIN),
shareName = true
shareName = true,
arenaAccepted = true
)
userRepository.insertUser("ndla_admin", toInsert)(session)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ trait UserService {
favoriteSubjects = Some(newFavorites),
arenaEnabled = None,
shareName = Some(shareName),
arenaGroups = None
arenaGroups = None,
arenaAccept = None
)
updated <- userService.updateFeideUserDataAuthenticated(updatedFeideUser, feideId, feideAccessToken)(session)
} yield updated
Expand Down Expand Up @@ -240,7 +241,8 @@ trait UserService {
arenaEnabled = arenaEnabledUsers.map(_.toLowerCase).contains(feideExtendedUserData.email.toLowerCase),
arenaGroups = getInitialIsArenaGroups(feideId),
shareName = false,
displayName = feideExtendedUserData.displayName
displayName = feideExtendedUserData.displayName,
arenaAccepted = false
)
inserted <- userRepository.insertUser(feideId, newUser)(session)
} yield inserted
Expand Down Expand Up @@ -271,7 +273,8 @@ trait UserService {
userData.arenaEnabled || arenaEnabledUsers.map(_.toLowerCase).contains(feideUser.email.toLowerCase),
shareName = userData.shareName,
displayName = feideUser.displayName,
arenaGroups = userData.arenaGroups
arenaGroups = userData.arenaGroups,
arenaAccepted = userData.arenaAccepted
)
userRepository.updateUser(feideId, updatedMyNDLAUser)(session)
}
Expand Down
3 changes: 2 additions & 1 deletion myndla-api/src/test/scala/no/ndla/myndlaapi/TestData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ object TestData {
arenaEnabled = false,
displayName = "",
shareName = false,
arenaGroups = List.empty
arenaGroups = List.empty,
arenaAccepted = false
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class ArenaControllerTest extends UnitTestSuite with TestEnvironment with TapirC
email = "[email protected]",
arenaEnabled = true,
arenaGroups = List.empty,
shareName = false
shareName = false,
arenaAccepted = true
)

test("That feide token parsing works if token present") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class FolderControllerTest extends UnitTestSuite with TestEnvironment with Tapir
email = "[email protected]",
arenaEnabled = true,
arenaGroups = List.empty,
shareName = false
shareName = false,
arenaAccepted = true
)

test("That resources fetching works and doesnt interfere with folder/:id") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ class ArenaTest
email = "[email protected]",
arenaEnabled = true,
arenaGroups = List.empty,
shareName = false
shareName = false,
arenaAccepted = true
)

val testAdmin: MyNDLAUser = MyNDLAUser(
Expand All @@ -141,7 +142,8 @@ class ArenaTest
email = "[email protected]",
arenaEnabled = true,
arenaGroups = List(ArenaGroup.ADMIN),
shareName = false
shareName = false,
arenaAccepted = true
)

def createCategory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class ArenaRepositoryTest
email = "[email protected]",
arenaEnabled = true,
arenaGroups = List(),
shareName = true
shareName = true,
arenaAccepted = true
)
val feideId = "feideId1"

Expand Down Expand Up @@ -112,7 +113,8 @@ class ArenaRepositoryTest
email = "[email protected]",
arenaEnabled = true,
arenaGroups = List(),
shareName = true
shareName = true,
arenaAccepted = true
)
val feideId = "feideId1"

Expand Down Expand Up @@ -176,7 +178,8 @@ class ArenaRepositoryTest
email = "[email protected]",
arenaEnabled = true,
arenaGroups = List(),
shareName = true
shareName = true,
arenaAccepted = true
)
val feideId = "feideId1"
val feideId2 = "feideId2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ class FolderConverterServiceTest extends UnitTestSuite with TestEnvironment {
arenaEnabled = false,
displayName = "Feide",
shareName = false,
arenaGroups = List.empty
arenaGroups = List.empty,
arenaAccepted = true
)
val expectedUserData =
MyNDLAUserDTO(
Expand Down Expand Up @@ -472,23 +473,32 @@ class FolderConverterServiceTest extends UnitTestSuite with TestEnvironment {
arenaEnabled = false,
displayName = "Feide",
shareName = false,
arenaGroups = List.empty
arenaGroups = List.empty,
arenaAccepted = true
)
val updatedUserData1 =
UpdatedMyNDLAUserDTO(favoriteSubjects = None, arenaEnabled = None, shareName = None, arenaGroups = None)
UpdatedMyNDLAUserDTO(
favoriteSubjects = None,
arenaEnabled = None,
shareName = None,
arenaGroups = None,
arenaAccept = None
)
val updatedUserData2 =
UpdatedMyNDLAUserDTO(
favoriteSubjects = Some(Seq.empty),
arenaEnabled = None,
shareName = None,
arenaGroups = None
arenaGroups = None,
arenaAccept = None
)
val updatedUserData3 =
UpdatedMyNDLAUserDTO(
favoriteSubjects = Some(Seq("x", "y", "z")),
arenaEnabled = None,
shareName = None,
arenaGroups = None
arenaGroups = None,
arenaAccept = None
)

val expectedUserData1 = MyNDLAUser(
Expand All @@ -511,7 +521,8 @@ class FolderConverterServiceTest extends UnitTestSuite with TestEnvironment {
arenaEnabled = false,
displayName = "Feide",
shareName = false,
arenaGroups = List.empty
arenaGroups = List.empty,
arenaAccepted = true
)
val expectedUserData2 = MyNDLAUser(
id = 42,
Expand All @@ -533,7 +544,8 @@ class FolderConverterServiceTest extends UnitTestSuite with TestEnvironment {
arenaEnabled = false,
displayName = "Feide",
shareName = false,
arenaGroups = List.empty
arenaGroups = List.empty,
arenaAccepted = true
)
val expectedUserData3 = MyNDLAUser(
id = 42,
Expand All @@ -555,7 +567,8 @@ class FolderConverterServiceTest extends UnitTestSuite with TestEnvironment {
arenaEnabled = false,
displayName = "Feide",
shareName = false,
arenaGroups = List.empty
arenaGroups = List.empty,
arenaAccepted = true
)

service.mergeUserData(domainUserData, updatedUserData1, None, None, List.empty) should be(expectedUserData1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ class FolderReadServiceTest extends UnitTestSuite with TestEnvironment {
arenaEnabled = false,
displayName = "Feide",
shareName = true,
arenaGroups = List.empty
arenaGroups = List.empty,
arenaAccepted = true
)

val folderUUID = UUID.randomUUID()
Expand Down Expand Up @@ -530,7 +531,8 @@ class FolderReadServiceTest extends UnitTestSuite with TestEnvironment {
email = "[email protected]",
arenaEnabled = true,
arenaGroups = List.empty,
shareName = false
shareName = false,
arenaAccepted = true
)
)
)
Expand All @@ -552,7 +554,8 @@ class FolderReadServiceTest extends UnitTestSuite with TestEnvironment {
email = "[email protected]",
arenaEnabled = true,
arenaGroups = List.empty,
shareName = false
shareName = false,
arenaAccepted = true
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ class UserServiceTest extends UnitTestSuite with TestEnvironment {
arenaEnabled = false,
displayName = "Feide",
shareName = false,
arenaGroups = List.empty
arenaGroups = List.empty,
arenaAccepted = true
)
val updatedUserData =
UpdatedMyNDLAUserDTO(
favoriteSubjects = Some(Seq("r", "e")),
arenaEnabled = None,
shareName = Some(true),
arenaGroups = None
arenaGroups = None,
arenaAccept = None
)
val userAfterMerge = MyNDLAUser(
id = 42,
Expand All @@ -84,7 +86,8 @@ class UserServiceTest extends UnitTestSuite with TestEnvironment {
arenaEnabled = false,
displayName = "Feide",
shareName = true,
arenaGroups = List.empty
arenaGroups = List.empty,
arenaAccepted = true
)
val expected = MyNDLAUserDTO(
id = 42,
Expand Down Expand Up @@ -124,7 +127,8 @@ class UserServiceTest extends UnitTestSuite with TestEnvironment {
favoriteSubjects = Some(Seq("r", "e")),
arenaEnabled = None,
shareName = None,
arenaGroups = None
arenaGroups = None,
arenaAccept = None
)

doReturn(Success(()))
Expand Down Expand Up @@ -181,7 +185,8 @@ class UserServiceTest extends UnitTestSuite with TestEnvironment {
arenaEnabled = false,
displayName = "Feide",
shareName = false,
arenaGroups = List.empty
arenaGroups = List.empty,
arenaAccepted = true
)
val apiUserData = MyNDLAUserDTO(
id = 42,
Expand Down Expand Up @@ -255,7 +260,8 @@ class UserServiceTest extends UnitTestSuite with TestEnvironment {
arenaEnabled = false,
displayName = "Feide",
shareName = false,
arenaGroups = List.empty
arenaGroups = List.empty,
arenaAccepted = true
)
val apiUserData = MyNDLAUserDTO(
id = 42,
Expand Down Expand Up @@ -325,7 +331,8 @@ class UserServiceTest extends UnitTestSuite with TestEnvironment {
arenaEnabled = false,
displayName = "Feide",
shareName = false,
arenaGroups = List.empty
arenaGroups = List.empty,
arenaAccepted = true
)
val updatedFeideUser = FeideExtendedUserInfo(
displayName = "name",
Expand Down

0 comments on commit 7af794a

Please sign in to comment.