A few more request messages.

master
Philippe Pittoli 2023-06-01 02:19:18 +02:00
parent 0b09cefa57
commit 39bc79d05c
1 changed files with 41 additions and 22 deletions

View File

@ -26,14 +26,13 @@ import Data.Bifunctor (lmap)
import App.IPC as IPC
{- TODO:
For a few messages, user can be designated by a string (login) or a number (its UID).
This was simplified by using the login for each.
Maybe this could be changed in the future to match the actual possibilities of the API.
Possible requests:
- 9 type CheckPermission = { shared_key :: Maybe String, token :: Maybe String, user :: Int | String, service :: String, resource :: String }
- 10 type SetPermission = { shared_key :: String, user :: Int | String, service :: String, resource :: String, permission :: PermissionLevel.PermissionLevel }
- 14 type EditProfile = { token :: String, new_profile :: Hash(String, JSON::Any) }
- 15 type EditProfileContent = { token :: Maybe String, shared_key :: Maybe String, user :: Int | String | Nil, new_profile :: Hash(String, JSON::Any) }
- 16 type EditContacts = { token :: String, email :: Maybe Email.Email, phone :: Maybe Phone.Phone }
- 17 type Delete = { shared_key :: Maybe String, login :: Maybe String, password :: Maybe String, user :: String | Int }
-- Deletion can be triggered by either an admin or the user.
-}
@ -66,9 +65,13 @@ type GetUserByCredentials = { login :: String, password :: String }
type Register = { login :: String, password :: String, email :: Maybe Email.Email, phone :: Maybe Phone.Phone } -- profile :: Maybe Hash(String, JSON::Any)
type UpdatePassword = { login :: String, old_password :: String, new_password :: String }
type ListUsers = { token :: Maybe String, key :: Maybe String }
type CheckPermission = { shared_key :: Maybe String, token :: Maybe String, user :: String, service :: String, resource :: String }
type SetPermission = { shared_key :: String, user :: String, service :: String, resource :: String, permission :: PermissionLevel.PermissionLevel }
type PasswordRecovery = { user :: String, password_renew_key :: String, new_password :: String }
type AskPasswordRecovery = { user :: String, email :: Email.Email }
type SearchUser = { user :: String }
type EditContacts = { token :: String, email :: Maybe Email.Email, phone :: Maybe Phone.Phone }
type Delete = { shared_key :: Maybe String, login :: Maybe String, password :: Maybe String, user :: String }
type GetContacts = { token :: String }
-- Related JSON codecs.
@ -99,12 +102,28 @@ codecUpdatePassword = CA.object "UpdatePassword" (CAR.record { login: CA.string
, new_password: CA.string })
codecListUsers ∷ CA.JsonCodec ListUsers
codecListUsers = CA.object "ListUsers" (CAR.record { token: CAR.optional CA.string, key: CAR.optional CA.string })
codecCheckPermission ∷ CA.JsonCodec CheckPermission
codecCheckPermission = CA.object "CheckPermission" (CAR.record { shared_key: CAR.optional CA.string
, token: CAR.optional CA.string
, user: CA.string
, service: CA.string
, resource: CA.string })
codecSetPermission ∷ CA.JsonCodec SetPermission
codecSetPermission = CA.object "SetPermission" (CAR.record { shared_key: CA.string
, user: CA.string
, service: CA.string
, resource: CA.string
, permission: PermissionLevel.codec })
codecPasswordRecovery ∷ CA.JsonCodec PasswordRecovery
codecPasswordRecovery = CA.object "PasswordRecovery" (CAR.record { user: CA.string, password_renew_key: CA.string, new_password: CA.string })
codecAskPasswordRecovery ∷ CA.JsonCodec AskPasswordRecovery
codecAskPasswordRecovery = CA.object "AskPasswordRecovery" (CAR.record { user: CA.string, email: Email.codec })
codecSearchUser ∷ CA.JsonCodec SearchUser
codecSearchUser = CA.object "SearchUser" (CAR.record { user: CA.string })
codecEditContacts ∷ CA.JsonCodec EditContacts
codecEditContacts = CA.object "EditContacts" (CAR.record { token: CA.string, email: CAR.optional Email.codec, phone: CAR.optional Phone.codec })
codecDelete ∷ CA.JsonCodec Delete
codecDelete = CA.object "Delete" (CAR.record { shared_key: CAR.optional CA.string, login: CAR.optional CA.string, password: CAR.optional CA.string, user: CA.string })
codecGetContacts ∷ CA.JsonCodec GetContacts
codecGetContacts = CA.object "GetContacts" (CAR.record { token: CA.string })
@ -154,15 +173,15 @@ data RequestMessage
| MkRegister Register -- 6
| MkUpdatePassword UpdatePassword -- 7
| MkListUsers ListUsers -- 8
--| MkCheckPermission CheckPermission -- 9
--| MkSetPermission SetPermission -- 10
| MkCheckPermission CheckPermission -- 9
| MkSetPermission SetPermission -- 10
| MkPasswordRecovery PasswordRecovery -- 11
| MkAskPasswordRecovery AskPasswordRecovery -- 12
| MkSearchUser SearchUser -- 13
--| MkEditProfile EditProfile -- 14
--| MkEditProfileContent EditProfileContent -- 15
--| MkEditContacts EditContacts -- 16
--| MkDelete Delete -- 17
| MkEditContacts EditContacts -- 16
| MkDelete Delete -- 17
| MkGetContacts GetContacts -- 18
-- All possible answers from the authentication daemon (authd).
@ -194,15 +213,15 @@ encode m = case m of
(MkRegister request) -> get_tuple 6 codecRegister request
(MkUpdatePassword request) -> get_tuple 7 codecUpdatePassword request
(MkListUsers request) -> get_tuple 8 codecListUsers request
-- 9 MkCheckPermission
-- 10 MkSetPermission
(MkCheckPermission request) -> get_tuple 9 codecCheckPermission request
(MkSetPermission request) -> get_tuple 10 codecSetPermission request
(MkPasswordRecovery request) -> get_tuple 11 codecPasswordRecovery request
(MkAskPasswordRecovery request) -> get_tuple 12 codecAskPasswordRecovery request
(MkSearchUser request) -> get_tuple 13 codecSearchUser request
-- 14 MkEditProfile
-- 15 MkEditProfileContent
-- 16 MkEditContacts
-- 17 MkDelete
(MkEditContacts request) -> get_tuple 16 codecEditContacts request
(MkDelete request) -> get_tuple 17 codecDelete request
(MkGetContacts request) -> get_tuple 18 codecGetContacts request
where
get_tuple :: forall a. Int -> CA.JsonCodec a -> a -> Tuple UInt String