2023-05-27 12:26:03 +02:00
|
|
|
module App.PermissionLevel where
|
|
|
|
|
|
|
|
import Data.Codec.Argonaut as CA
|
2023-05-31 00:22:38 +02:00
|
|
|
import Data.Maybe (Maybe(..))
|
2023-05-27 12:26:03 +02:00
|
|
|
|
|
|
|
data PermissionLevel
|
|
|
|
= None
|
|
|
|
| Read
|
|
|
|
| Edit
|
|
|
|
| Admin
|
|
|
|
|
2023-05-31 00:22:38 +02:00
|
|
|
-- | Codec for just encoding a single value of type `PermissionLevel`
|
|
|
|
codec :: CA.JsonCodec PermissionLevel
|
2023-05-27 12:26:03 +02:00
|
|
|
codec =
|
2023-05-31 00:22:38 +02:00
|
|
|
CA.prismaticCodec "PermissionLevel" from to CA.string
|
2023-05-27 12:26:03 +02:00
|
|
|
where
|
2023-05-31 00:22:38 +02:00
|
|
|
from :: String -> Maybe PermissionLevel
|
|
|
|
from = case _ of
|
|
|
|
"none" -> Just None
|
|
|
|
"read" -> Just Read
|
|
|
|
"edit" -> Just Edit
|
|
|
|
"admin" -> Just Admin
|
|
|
|
_ -> Nothing
|
2023-05-27 12:26:03 +02:00
|
|
|
|
2023-05-31 00:22:38 +02:00
|
|
|
to :: PermissionLevel -> String
|
|
|
|
to = case _ of
|
|
|
|
None -> "none"
|
|
|
|
Read -> "read"
|
|
|
|
Edit -> "edit"
|
|
|
|
Admin -> "admin"
|