Only show the admin page if you are admin.

display
Philippe Pittoli 2024-03-26 21:16:00 +01:00
parent d4d183034f
commit e6d6a2bb20
3 changed files with 14 additions and 6 deletions

View File

@ -50,7 +50,7 @@ import Prelude (Unit, bind, discard, unit, ($), (=<<), (<>), show, pure)
import Bulma as Bulma import Bulma as Bulma
import Data.Array as A import Data.Array as A
import Data.Maybe (Maybe(..), maybe) import Data.Maybe (Maybe(..), maybe, fromMaybe)
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
import Halogen as H import Halogen as H
@ -717,8 +717,9 @@ handleAction = case _ of
m@(DNSManager.MkAcceptedDomains _) -> do m@(DNSManager.MkAcceptedDomains _) -> do
handleAction $ Log $ SuccessLog $ "Received the list of accepted domains!" handleAction $ Log $ SuccessLog $ "Received the list of accepted domains!"
handleAction $ DispatchDNSMessage m handleAction $ DispatchDNSMessage m
m@(DNSManager.MkLogged _) -> do m@(DNSManager.MkLogged message) -> do
handleAction $ Log $ SuccessLog $ "Authenticated to dnsmanagerd!" handleAction $ Log $ SuccessLog $ "Authenticated to dnsmanagerd!"
H.tell _nav unit $ NavigationInterface.ToggleAdmin (fromMaybe false message.admin)
handleAction $ DispatchDNSMessage m handleAction $ DispatchDNSMessage m
m@(DNSManager.MkDomainAdded response) -> do m@(DNSManager.MkDomainAdded response) -> do
handleAction $ Log $ SuccessLog $ "Domain added: " <> response.domain handleAction $ Log $ SuccessLog $ "Domain added: " <> response.domain

View File

@ -208,10 +208,12 @@ codecAcceptedDomains ∷ CA.JsonCodec AcceptedDomains
codecAcceptedDomains = CA.object "AcceptedDomains" (CAR.record { domains: CA.array CA.string }) codecAcceptedDomains = CA.object "AcceptedDomains" (CAR.record { domains: CA.array CA.string })
{- 16 -} {- 16 -}
type Logged = { accepted_domains :: Array String, my_domains :: Array String } type Logged = { accepted_domains :: Array String, my_domains :: Array String, admin :: Maybe Boolean }
codecLogged ∷ CA.JsonCodec Logged codecLogged ∷ CA.JsonCodec Logged
codecLogged = CA.object "Logged" (CAR.record { accepted_domains: CA.array CA.string codecLogged = CA.object "Logged" (CAR.record { accepted_domains: CA.array CA.string
, my_domains: CA.array CA.string }) , my_domains: CA.array CA.string
, admin: CAR.optional CA.boolean
})
{- 17 -} {- 17 -}
type DomainAdded = { domain :: String } type DomainAdded = { domain :: String }

View File

@ -31,7 +31,9 @@ data Output
| Disconnection | Disconnection
-- | The component needs to know when the user is logged or not. -- | The component needs to know when the user is logged or not.
data Query a = ToggleLogged Boolean a data Query a
= ToggleLogged Boolean a
| ToggleAdmin Boolean a
type Slot = H.Slot Query Output type Slot = H.Slot Query Output
@ -66,7 +68,7 @@ component =
} }
initialState :: Input -> State initialState :: Input -> State
initialState _ = { logged: false, active: false, admin: true } initialState _ = { logged: false, active: false, admin: false }
handleAction :: forall m. MonadAff m => Action -> H.HalogenM State Action () Output m Unit handleAction :: forall m. MonadAff m => Action -> H.HalogenM State Action () Output m Unit
handleAction = case _ of handleAction = case _ of
@ -82,6 +84,9 @@ handleQuery = case _ of
ToggleLogged islogged a -> do ToggleLogged islogged a -> do
H.modify_ _ { logged = islogged } H.modify_ _ { logged = islogged }
pure (Just a) pure (Just a)
ToggleAdmin isadmin a -> do
H.modify_ _ { admin = isadmin }
pure (Just a)
-- | The navigation bar is a complex component to render. -- | The navigation bar is a complex component to render.