com.gu.permissions.CacheFormat.scala Maven / Gradle / Ivy
package com.gu.permissions
import play.api.libs.json._
case class PermissionDefinition(name: String, app: String)
object PermissionDefinition {
implicit val reads: Reads[PermissionDefinition] =
Json.reads[PermissionDefinition]
// IntelliJ says we can roll this up into a Single Abstract Method but we can't because if we do compiling fails on
// Scala 2.11 sigh...
implicit val writes: Writes[PermissionDefinition] =
new Writes[PermissionDefinition] {
override def writes(p: PermissionDefinition): JsValue = {
JsObject(
Seq(
"name" -> JsString(p.name),
"app" -> JsString(p.app),
// For compatibility with older clients. All permissions now default to false
"defaultValue" -> JsBoolean(false)
)
)
}
}
}
case class UserSetting(
userId: String,
active: Boolean,
isCasualNotOnShift: Boolean = false
)
object UserSetting {
implicit val format: Format[UserSetting] =
Json.using[Json.WithDefaultValues].format[UserSetting]
}
case class PermissionWithUsers(
permission: PermissionDefinition,
overrides: List[UserSetting]
)
object PermissionWithUsers {
implicit val format: Format[PermissionWithUsers] =
Json.format[PermissionWithUsers]
}