From d12278be30058488090201486a506731dc42dae4 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Sat, 27 May 2023 13:24:52 +0200 Subject: [PATCH] New decoded messages: permissions! --- src/App/Messages/AuthenticationDaemon.purs | 42 ++++++++++++++-------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/App/Messages/AuthenticationDaemon.purs b/src/App/Messages/AuthenticationDaemon.purs index 265b522..73aa96c 100644 --- a/src/App/Messages/AuthenticationDaemon.purs +++ b/src/App/Messages/AuthenticationDaemon.purs @@ -57,9 +57,6 @@ import App.IPC as IPC -- TODO: note to myself: messages seem chaotic. Could be simpler. Should be simpler. type Error = { reason :: Maybe 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 UserAdded = { user :: UserPublic.UserPublic } type UserEdited = { uid :: Int } @@ -67,6 +64,9 @@ type UserValidated = { user :: UserPublic.UserPublic } type UsersList = { users :: Array UserPublic.UserPublic } type PermissionCheck = { 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 GetToken = { login :: String, password :: String } @@ -91,6 +91,18 @@ codecGotUserValidated ∷ CA.JsonCodec UserValidated codecGotUserValidated = CA.object "UserValidated" (CAR.record { user: UserPublic.codec }) codecGotPasswordRecovered ∷ CA.JsonCodec PasswordRecovered 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.object "Contacts" (CAR.record { user: CA.int , email: CAR.optional Email.codec @@ -119,15 +131,15 @@ data RequestMessage -- All possible answers from the authentication daemon (authd). data AnswerMessage - = GotError Error -- 0 - | GotToken Token -- 1 - | GotUser User -- 2 - | GotUserAdded UserAdded -- 3 - | GotUserEdited UserEdited -- 4 - | GotUserValidated UserValidated -- 5 + = GotError Error -- 0 + | GotToken Token -- 1 + | GotUser User -- 2 + | GotUserAdded UserAdded -- 3 + | GotUserEdited UserEdited -- 4 + | GotUserValidated UserValidated -- 5 -- | GotUsersList UsersList -- 6 - -- | GotPermissionCheck PermissionCheck -- 7 - -- | GotPermissionSet PermissionSet -- 8 + | GotPermissionCheck PermissionCheck -- 7 + | GotPermissionSet PermissionSet -- 8 | GotPasswordRecoverySent PasswordRecoverySent -- 9 | GotPasswordRecovered PasswordRecovered -- 10 -- | GotMatchingUsers MatchingUsers -- 11 @@ -168,14 +180,14 @@ decode number string 3 -> error_management codecGotUserAdded GotUserAdded 4 -> error_management codecGotUserEdited GotUserEdited 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 10 -> error_management codecGotPasswordRecovered GotPasswordRecovered + -- 11 type MatchingUsers = { users :: Array(UserPublic.UserPublic) } 12 -> error_management codecGotContacts GotContacts _ -> 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 -- Signature is required since the compiler's guess is wrong. error_management :: forall a. CA.JsonCodec a -> (a -> AnswerMessage) -> Either DecodeError AnswerMessage