diff --git a/core/src/Datarekisteri/Core/Types.hs b/core/src/Datarekisteri/Core/Types.hs index 885e4e8..685cedd 100644 --- a/core/src/Datarekisteri/Core/Types.hs +++ b/core/src/Datarekisteri/Core/Types.hs @@ -99,7 +99,18 @@ instance FromJSON Scope where parseJSON = scalarFromJSON <=< parseJSON data Permission = None | ReadOnly | ReadWrite - deriving (Show, Eq, Ord, Read) + deriving (Show, Eq, Ord, Read, Generic) + +instance DecodeScalar Permission where + decodeScalar (String s) = maybe (Left $ "invalid Permission: \"" <> s <> "\"") Right $ readMaybe (toString s) + decodeScalar _ = Left "Invalid type for Permission, should be string" + +instance EncodeScalar Permission where + encodeScalar = String . show + +instance GQLType Permission where type KIND Permission = SCALAR +instance ToJSON Permission where toJSON = scalarToJSON +instance FromJSON Permission where parseJSON = scalarFromJSON <=< parseJSON readPermission :: Text -> Maybe (Map Scope Permission) readPermission = rightToMaybe . readEither . toString