Received messages codecs are okay-ish (some properties are missing in UserPublic module).

master
Philippe Pittoli 2023-05-27 13:35:44 +02:00
parent d12278be30
commit f66aba1c41
1 changed files with 20 additions and 18 deletions

View File

@ -50,7 +50,6 @@ import App.IPC as IPC
-- Deletion can be triggered by either an admin or the user. -- Deletion can be triggered by either an admin or the user.
Possible answers: Possible answers:
- 11 type MatchingUsers = { users :: Array(UserPublic.UserPublic) }
-} -}
-- Basic message types. -- Basic message types.
@ -67,6 +66,7 @@ type PermissionSet = { user :: Int, service :: String, resource :: String
type PasswordRecoverySent = { user :: UserPublic.UserPublic } type PasswordRecoverySent = { user :: UserPublic.UserPublic }
type PasswordRecovered = { user :: UserPublic.UserPublic } type PasswordRecovered = { user :: UserPublic.UserPublic }
type Contacts = { user :: Int, email :: Maybe Email.Email, phone :: Maybe Phone.Phone } type Contacts = { user :: Int, email :: Maybe Email.Email, phone :: Maybe Phone.Phone }
type MatchingUsers = { users :: Array UserPublic.UserPublic }
type Password = String type Password = String
type GetToken = { login :: String, password :: String } type GetToken = { login :: String, password :: String }
@ -91,8 +91,8 @@ 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.JsonCodec UsersList
-- codecGotUsersList = CA.object "UsersList" (CAR.record { users: TODO }) codecGotUsersList = CA.object "UsersList" (CAR.record { users: CA.array UserPublic.codec })
codecGotPermissionCheck :: CA.JsonCodec PermissionCheck codecGotPermissionCheck :: CA.JsonCodec PermissionCheck
codecGotPermissionCheck = CA.object "PermissionCheck" (CAR.record { user: CA.int codecGotPermissionCheck = CA.object "PermissionCheck" (CAR.record { user: CA.int
, service: CA.string , service: CA.string
@ -107,6 +107,8 @@ 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
, phone: CAR.optional Phone.codec }) , phone: CAR.optional Phone.codec })
codecGotMatchingUsers ∷ CA.JsonCodec MatchingUsers
codecGotMatchingUsers = CA.object "MatchingUsers" (CAR.record { users: CA.array UserPublic.codec })
-- All possible requests. -- All possible requests.
data RequestMessage data RequestMessage
@ -131,19 +133,19 @@ 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
| GotContacts Contacts -- 12 | GotContacts Contacts -- 12
encode ∷ RequestMessage -> Tuple UInt String encode ∷ RequestMessage -> Tuple UInt String
encode m = case m of encode m = case m of
@ -180,12 +182,12 @@ 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) } 6 -> error_management codecGotUsersList GotUsersList
7 -> error_management codecGotPermissionCheck GotPermissionCheck 7 -> error_management codecGotPermissionCheck GotPermissionCheck
8 -> error_management codecGotPermissionSet GotPermissionSet 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) } 11 -> error_management codecGotMatchingUsers GotMatchingUsers
12 -> error_management codecGotContacts GotContacts 12 -> error_management codecGotContacts GotContacts
_ -> Left UnknownNumber _ -> Left UnknownNumber
where where