-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
197 additions
and
130 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
...myndlaapi/model/domain/FolderStatus.scala → ...on/model/domain/myndla/FolderStatus.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
common/src/main/scala/no/ndla/common/model/domain/myndla/MyNDLAUser.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Part of NDLA common | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
*/ | ||
|
||
package no.ndla.common.model.domain.myndla | ||
|
||
import com.scalatsi.TypescriptType.{TSLiteralString, TSUnion} | ||
import com.scalatsi.{TSNamedType, TSType} | ||
import enumeratum.* | ||
import io.circe.{Decoder, Encoder} | ||
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} | ||
import no.ndla.common.model.NDLADate | ||
|
||
case class MyNDLAGroup(id: String, displayName: String, isPrimarySchool: Boolean, parentId: Option[String]) | ||
object MyNDLAGroup { | ||
implicit val encoder: Encoder[MyNDLAGroup] = deriveEncoder | ||
implicit val decoder: Decoder[MyNDLAGroup] = deriveDecoder | ||
} | ||
|
||
case class MyNDLAUserDocument( | ||
favoriteSubjects: Seq[String], | ||
userRole: UserRole.Value, | ||
lastUpdated: NDLADate, | ||
organization: String, | ||
groups: Seq[MyNDLAGroup], | ||
username: String, | ||
displayName: String, | ||
email: String, | ||
arenaEnabled: Boolean, | ||
arenaGroups: List[ArenaGroup], | ||
shareName: Boolean | ||
) { | ||
def toFullUser(id: Long, feideId: String): MyNDLAUser = { | ||
MyNDLAUser( | ||
id = id, | ||
feideId = feideId, | ||
favoriteSubjects = favoriteSubjects, | ||
userRole = userRole, | ||
lastUpdated = lastUpdated, | ||
organization = organization, | ||
groups = groups, | ||
username = username, | ||
displayName = displayName, | ||
email = email, | ||
arenaEnabled = arenaEnabled, | ||
shareName = shareName, | ||
arenaGroups = arenaGroups | ||
) | ||
} | ||
} | ||
|
||
object MyNDLAUserDocument { | ||
implicit val encoder: Encoder[MyNDLAUserDocument] = deriveEncoder | ||
implicit val decoder: Decoder[MyNDLAUserDocument] = deriveDecoder | ||
} | ||
|
||
sealed trait ArenaGroup extends EnumEntry | ||
object ArenaGroup extends Enum[ArenaGroup] with CirceEnum[ArenaGroup] { | ||
case object ADMIN extends ArenaGroup | ||
override def values: IndexedSeq[ArenaGroup] = findValues | ||
|
||
implicit val enumTsType: TSNamedType[ArenaGroup] = | ||
TSType.alias[ArenaGroup]("ArenaGroup", TSUnion(values.map(e => TSLiteralString(e.entryName)))) | ||
} | ||
|
||
case class MyNDLAUser( | ||
id: Long, | ||
feideId: String, | ||
favoriteSubjects: Seq[String], | ||
userRole: UserRole.Value, | ||
lastUpdated: NDLADate, | ||
organization: String, | ||
groups: Seq[MyNDLAGroup], | ||
username: String, | ||
displayName: String, | ||
email: String, | ||
arenaEnabled: Boolean, | ||
arenaGroups: List[ArenaGroup], | ||
shareName: Boolean | ||
) { | ||
// Keeping FEIDE and our data in sync | ||
def wasUpdatedLast24h: Boolean = NDLADate.now().isBefore(lastUpdated.minusSeconds(10)) | ||
|
||
def isStudent: Boolean = userRole == UserRole.STUDENT | ||
def isTeacher: Boolean = userRole == UserRole.EMPLOYEE | ||
def isAdmin: Boolean = arenaGroups.contains(ArenaGroup.ADMIN) | ||
} |
5 changes: 2 additions & 3 deletions
5
...dla/myndlaapi/model/domain/UserRole.scala → ...common/model/domain/myndla/UserRole.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.