31 lines
675 B
Plaintext
31 lines
675 B
Plaintext
module App.PermissionLevel where
|
|
|
|
import Data.Codec.Argonaut as CA
|
|
import Data.Maybe (Maybe(..))
|
|
|
|
data PermissionLevel
|
|
= None
|
|
| Read
|
|
| Edit
|
|
| Admin
|
|
|
|
-- | Codec for just encoding a single value of type `PermissionLevel`
|
|
codec :: CA.JsonCodec PermissionLevel
|
|
codec =
|
|
CA.prismaticCodec "PermissionLevel" from to CA.string
|
|
where
|
|
from :: String -> Maybe PermissionLevel
|
|
from = case _ of
|
|
"none" -> Just None
|
|
"read" -> Just Read
|
|
"edit" -> Just Edit
|
|
"admin" -> Just Admin
|
|
_ -> Nothing
|
|
|
|
to :: PermissionLevel -> String
|
|
to = case _ of
|
|
None -> "none"
|
|
Read -> "read"
|
|
Edit -> "edit"
|
|
Admin -> "admin"
|