New decoded messages: permissions!

master
Philippe Pittoli 2023-05-27 13:24:52 +02:00
parent 20b3a5aeb2
commit d12278be30
1 changed files with 27 additions and 15 deletions

View File

@ -57,9 +57,6 @@ import App.IPC as IPC
-- TODO: note to myself: messages seem chaotic. Could be simpler. Should be simpler. -- TODO: note to myself: messages seem chaotic. Could be simpler. Should be simpler.
type Error = { reason :: Maybe String } type Error = { reason :: Maybe String }
type Token = { uid :: Int, token :: String } type Token = { uid :: Int, token :: String }
type PasswordRecoverySent = { user :: UserPublic.UserPublic }
type PasswordRecovered = { user :: UserPublic.UserPublic }
type Contacts = { user :: Int, email :: Maybe Email.Email, phone :: Maybe Phone.Phone }
type User = { user :: UserPublic.UserPublic } type User = { user :: UserPublic.UserPublic }
type UserAdded = { user :: UserPublic.UserPublic } type UserAdded = { user :: UserPublic.UserPublic }
type UserEdited = { uid :: Int } type UserEdited = { uid :: Int }
@ -67,6 +64,9 @@ type UserValidated = { user :: UserPublic.UserPublic }
type UsersList = { users :: Array UserPublic.UserPublic } type UsersList = { users :: Array UserPublic.UserPublic }
type PermissionCheck = { user :: Int, service :: String, resource :: String, permission :: PermissionLevel.PermissionLevel } type PermissionCheck = { user :: Int, service :: String, resource :: String, permission :: PermissionLevel.PermissionLevel }
type PermissionSet = { user :: Int, service :: String, resource :: String, permission :: PermissionLevel.PermissionLevel } type PermissionSet = { user :: Int, service :: String, resource :: String, permission :: PermissionLevel.PermissionLevel }
type PasswordRecoverySent = { user :: UserPublic.UserPublic }
type PasswordRecovered = { user :: UserPublic.UserPublic }
type Contacts = { user :: Int, email :: Maybe Email.Email, phone :: Maybe Phone.Phone }
type Password = String type Password = String
type GetToken = { login :: String, password :: String } type GetToken = { login :: String, password :: String }
@ -91,6 +91,18 @@ codecGotUserValidated ∷ CA.JsonCodec UserValidated
codecGotUserValidated = CA.object "UserValidated" (CAR.record { user: UserPublic.codec }) codecGotUserValidated = CA.object "UserValidated" (CAR.record { user: UserPublic.codec })
codecGotPasswordRecovered ∷ CA.JsonCodec PasswordRecovered codecGotPasswordRecovered ∷ CA.JsonCodec PasswordRecovered
codecGotPasswordRecovered = CA.object "PasswordRecovered" (CAR.record { user: UserPublic.codec }) codecGotPasswordRecovered = CA.object "PasswordRecovered" (CAR.record { user: UserPublic.codec })
-- codecGotUsersList ∷ CA.JsonCodec UsersList
-- codecGotUsersList = CA.object "UsersList" (CAR.record { users: TODO })
codecGotPermissionCheck :: CA.JsonCodec PermissionCheck
codecGotPermissionCheck = CA.object "PermissionCheck" (CAR.record { user: CA.int
, service: CA.string
, resource: CA.string
, permission: PermissionLevel.codec })
codecGotPermissionSet :: CA.JsonCodec PermissionSet
codecGotPermissionSet = CA.object "PermissionSet" (CAR.record { user: CA.int
, service: CA.string
, resource: CA.string
, permission: PermissionLevel.codec })
codecGotContacts ∷ CA.JsonCodec Contacts codecGotContacts ∷ CA.JsonCodec Contacts
codecGotContacts = CA.object "Contacts" (CAR.record { user: CA.int codecGotContacts = CA.object "Contacts" (CAR.record { user: CA.int
, email: CAR.optional Email.codec , email: CAR.optional Email.codec
@ -119,15 +131,15 @@ data RequestMessage
-- All possible answers from the authentication daemon (authd). -- All possible answers from the authentication daemon (authd).
data AnswerMessage data AnswerMessage
= GotError Error -- 0 = GotError Error -- 0
| GotToken Token -- 1 | GotToken Token -- 1
| GotUser User -- 2 | GotUser User -- 2
| GotUserAdded UserAdded -- 3 | GotUserAdded UserAdded -- 3
| GotUserEdited UserEdited -- 4 | GotUserEdited UserEdited -- 4
| GotUserValidated UserValidated -- 5 | GotUserValidated UserValidated -- 5
-- | GotUsersList UsersList -- 6 -- | GotUsersList UsersList -- 6
-- | GotPermissionCheck PermissionCheck -- 7 | GotPermissionCheck PermissionCheck -- 7
-- | GotPermissionSet PermissionSet -- 8 | GotPermissionSet PermissionSet -- 8
| GotPasswordRecoverySent PasswordRecoverySent -- 9 | GotPasswordRecoverySent PasswordRecoverySent -- 9
| GotPasswordRecovered PasswordRecovered -- 10 | GotPasswordRecovered PasswordRecovered -- 10
-- | GotMatchingUsers MatchingUsers -- 11 -- | GotMatchingUsers MatchingUsers -- 11
@ -168,14 +180,14 @@ decode number string
3 -> error_management codecGotUserAdded GotUserAdded 3 -> error_management codecGotUserAdded GotUserAdded
4 -> error_management codecGotUserEdited GotUserEdited 4 -> error_management codecGotUserEdited GotUserEdited
5 -> error_management codecGotUserValidated GotUserValidated 5 -> error_management codecGotUserValidated GotUserValidated
-- 6 type UsersList = { users :: Array(UserPublic.UserPublic) }
7 -> error_management codecGotPermissionCheck GotPermissionCheck
8 -> error_management codecGotPermissionSet GotPermissionSet
9 -> error_management codecGotPasswordRecoverySent GotPasswordRecoverySent 9 -> error_management codecGotPasswordRecoverySent GotPasswordRecoverySent
10 -> error_management codecGotPasswordRecovered GotPasswordRecovered 10 -> error_management codecGotPasswordRecovered GotPasswordRecovered
-- 11 type MatchingUsers = { users :: Array(UserPublic.UserPublic) }
12 -> error_management codecGotContacts GotContacts 12 -> error_management codecGotContacts GotContacts
_ -> Left UnknownNumber _ -> Left UnknownNumber
-- 6 type UsersList = { users :: Array(UserPublic.UserPublic) }
-- 7 type PermissionCheck = { user :: Int, service :: String, resource :: String, permission :: PermissionLevel.PermissionLevel }
-- 8 type PermissionSet = { user :: Int, service :: String, resource :: String, permission :: PermissionLevel.PermissionLevel }
-- 11 type MatchingUsers = { users :: Array(UserPublic.UserPublic) }
where where
-- Signature is required since the compiler's guess is wrong. -- Signature is required since the compiler's guess is wrong.
error_management :: forall a. CA.JsonCodec a -> (a -> AnswerMessage) -> Either DecodeError AnswerMessage error_management :: forall a. CA.JsonCodec a -> (a -> AnswerMessage) -> Either DecodeError AnswerMessage