Code style + (admin) remove users.

This commit is contained in:
Philippe Pittoli 2024-03-17 02:09:16 +01:00
parent 5690b0271f
commit fdc6e0ec62
2 changed files with 29 additions and 20 deletions

View File

@ -404,6 +404,15 @@ handleAction = case _ of
AdminInterface.AskState -> do
state <- H.get
H.tell _admini unit (AdminInterface.ProvideState state.store_AuthenticationDaemonAdmin_state)
AdminInterface.DeleteUserAccount uid -> do
handleAction $ Log $ SystemLog "Remove user account. 😿"
{- User id is provided this time, it's (probably) NOT self termination. -}
dns_message <- H.liftEffect $ DNSManager.serialize $ DNSManager.MkDeleteUser { user_id: Just uid }
auth_message <- H.liftEffect $ AuthD.serialize $ AuthD.MkDeleteUser { user: Just uid }
H.tell _ws_dns unit (WS.ToSend dns_message)
H.tell _ws_auth unit (WS.ToSend auth_message)
ZoneInterfaceEvent ev -> case ev of
ZoneInterface.MessageToSend message -> H.tell _ws_dns unit (WS.ToSend message)

View File

@ -46,6 +46,7 @@ data Output
| Log LogMessage
| AskState
| StoreState State
| DeleteUserAccount Int
data Query a
= MessageReceived AuthD.AnswerMessage a
@ -120,17 +121,17 @@ initialState _ = { addUserForm: { login: "", admin: false, email: "", pass: "
render :: forall m. State -> H.ComponentHTML Action () m
render { addUserForm, searchUserForm, matching_users, current_tab, wsUp }
= HH.div_
[ fancy_tab_bar
, case current_tab of
Home -> Bulma.section_small [Bulma.h3 "Select an action"]
Search -> Bulma.columns_
[ Bulma.column (C.is 3) [Bulma.article (Bulma.p "Search users") render_searchuser_form]
, Bulma.column_ [ Bulma.h3 "Result", show_found_users ]
]
Add -> Bulma.columns_
[ Bulma.column (C.is 5) [Bulma.article (Bulma.p "Add a new user") render_adduser_form] ]
]
= Bulma.section_small
[ fancy_tab_bar
, case current_tab of
Home -> Bulma.h3 "Select an action"
Search -> Bulma.columns_
[ Bulma.column (C.is 3) [Bulma.article (Bulma.p "Search users") render_searchuser_form]
, Bulma.column_ [ Bulma.h3 "Result", show_found_users ]
]
Add -> Bulma.columns_
[ Bulma.column (C.is 5) [Bulma.article (Bulma.p "Add a new user") render_adduser_form] ]
]
where
fancy_tab_bar =
Bulma.fancy_tabs
@ -141,8 +142,8 @@ render { addUserForm, searchUserForm, matching_users, current_tab, wsUp }
is_tab_active tab = current_tab == tab
show_found_users = Bulma.box [ HH.ul_ $ map user_card matching_users ]
user_card user = HH.li_ [ Bulma.btn user.login (ShowUser user.uid)
, Bulma.alert_btn "remove" (RemoveUser user.uid)
user_card user = HH.li_ [ Bulma.btn_delete (RemoveUser user.uid)
, Bulma.btn_ (C.is_small) user.login (ShowUser user.uid)
]
up x = HandleAddUserInput <<< x
active = (if wsUp then (HP.enabled true) else (HP.disabled true))
@ -193,11 +194,11 @@ handleAction = case _ of
HandleAddUserInput adduserinp -> do
{ addUserForm } <- H.get
case adduserinp of
ADDUSER_INP_login v -> H.modify_ _ { addUserForm { login = v } }
ADDUSER_INP_email v -> H.modify_ _ { addUserForm { email = v } }
ADDUSER_toggle_admin -> H.modify_ _ { addUserForm { admin = not addUserForm.admin } }
ADDUSER_INP_pass v -> H.modify_ _ { addUserForm { pass = v } }
SEARCHUSER_INP_regex v -> H.modify_ _ { searchUserForm { regex = v } }
ADDUSER_INP_login v -> H.modify_ _ { addUserForm { login = v } }
ADDUSER_INP_email v -> H.modify_ _ { addUserForm { email = v } }
ADDUSER_toggle_admin -> H.modify_ _ { addUserForm { admin = not addUserForm.admin } }
ADDUSER_INP_pass v -> H.modify_ _ { addUserForm { pass = v } }
SEARCHUSER_INP_regex v -> H.modify_ _ { searchUserForm { regex = v } }
PreventSubmit ev -> H.liftEffect $ Event.preventDefault ev
@ -206,8 +207,7 @@ handleAction = case _ of
RemoveUser uid -> do
H.raise $ Log $ SystemLog $ "Remove user " <> show uid
ab <- H.liftEffect $ AuthD.serialize $ AuthD.MkDeleteUser { user: Just uid }
H.raise $ MessageToSend ab
H.raise $ DeleteUserAccount uid
AddUserAttempt -> do
{ addUserForm } <- H.get