From 49adaba0aa1c147bd9a21e720ebd5d445c96a236 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Tue, 28 Oct 2025 19:18:13 +0100 Subject: [PATCH] Enable domain reset (to remove a delegation). --- src/App/Container.purs | 3 +++ src/App/Page/Zone.purs | 33 +++++++++++++++++++++++++++++---- src/App/Templates/Modal.purs | 33 ++++++++++++++++++++++++++++----- src/App/Type/RRModal.purs | 1 + 4 files changed, 61 insertions(+), 9 deletions(-) diff --git a/src/App/Container.purs b/src/App/Container.purs index 1a67141..622fe44 100644 --- a/src/App/Container.purs +++ b/src/App/Container.purs @@ -601,6 +601,9 @@ act_on_page_event page_event = case page_event of PageZone.AskSaveDelegation domain nameserver1 nameserver2 -> do message <- H.liftEffect $ DNSManager.serialize $ DNSManager.MkDelegateDomain { domain, nameserver1, nameserver2 } H.tell _ws_dns unit (WS.ToSend message) + PageZone.AskResetDelegation domain -> do + message <- H.liftEffect $ DNSManager.serialize $ DNSManager.MkResetDelegation { domain } + H.tell _ws_dns unit (WS.ToSend message) PageZone.AskAddRR domain rr -> do message <- H.liftEffect $ DNSManager.serialize $ DNSManager.MkAddRR { domain, rr } H.tell _ws_dns unit (WS.ToSend message) diff --git a/src/App/Page/Zone.purs b/src/App/Page/Zone.purs index 1c93fa6..563c3e5 100644 --- a/src/App/Page/Zone.purs +++ b/src/App/Page/Zone.purs @@ -66,6 +66,7 @@ data Output | AskDeleteRR String Int | AskSaveRR String RR.ResourceRecord | AskSaveDelegation String String String + | AskResetDelegation String | AskAddRR String RR.ResourceRecord | AskGetZone String @@ -109,6 +110,9 @@ data Action -- | Update Delegation modal. | UpdateDelegationModal Delegation + -- | Reset Delegation modal. + | DisplayResetDelegationModal + -- | Create modal (a form) for a resource record to update. | CreateUpdateRRModal RR.RRId @@ -133,6 +137,9 @@ data Action -- | Save the delegation. | SaveDelegation + -- | Reset the delegation. + | ResetDelegation + -- | Validate a new resource record before adding it. | ValidateRR RR.AcceptedRRTypes @@ -255,12 +262,16 @@ render state = Modal.delegation_modal state._domain state._delegation_form UpdateDelegationForm ValidateDelegation CancelModal + reset_delegation_modal + = Modal.reset_delegation_modal state._domain ResetDelegation CancelModal + render_zone = case state.rr_modal of - RemoveRRModal rr_id -> Modal.modal_rr_delete rr_id RemoveRR CancelModal - NewRRModal _ -> call_to_current_rr_modal - UpdateRRModal -> call_to_current_rr_modal - DelegationModal -> delegation_modal + RemoveRRModal rr_id -> Modal.modal_rr_delete rr_id RemoveRR CancelModal + NewRRModal _ -> call_to_current_rr_modal + UpdateRRModal -> call_to_current_rr_modal + DelegationModal -> delegation_modal + ResetDelegationModal -> reset_delegation_modal NoModal -> HH.div_ $ [ Web.level [ Web.btn_ [C.is_large, C.is_info] "Back to the domain list" ReturnToDomainList , Web.h1 state._domain @@ -277,6 +288,9 @@ render state , Web.level [ Web.btn "Edit the name servers" (UpdateDelegationModal delegation) ] [] + , Web.level [ + Web.btn "Reset this domain, forget about delegation" DisplayResetDelegationModal + ] [] ] render_zone_records _ = [ Table.resource_records (sorted state._resources) CreateUpdateRRModal DeleteRRModal NewToken @@ -346,6 +360,10 @@ handleAction = case _ of UpdateDelegationModal delegation -> do H.modify_ _ { rr_modal = DelegationModal, _delegation_form = Delegation.mkUpdateDelegationForm delegation } + -- | Delegation modal presents a simple form with two entries (chosen nameservers). + DisplayResetDelegationModal -> do + H.modify_ _ { rr_modal = ResetDelegationModal } + -- | Initialize the Zone component: ask for the domain zone to `dnsmanagerd`. Initialize -> do { _domain } <- H.get @@ -483,6 +501,13 @@ handleAction = case _ of H.raise $ AskSaveDelegation state._domain df.nameserver1 df.nameserver2 H.modify_ _ { rr_modal = NoModal } + -- | Save the delegation of the domain. + ResetDelegation -> do + state <- H.get + H.raise $ Log $ SystemLog $ "Reset the delegation for domain '" <> state._domain <> "'" + H.raise $ AskResetDelegation state._domain + H.modify_ _ { rr_modal = NoModal } + NewToken rr_id -> do { _domain } <- H.get H.raise $ Log $ SystemLog $ "Ask a token for rrid " <> show rr_id diff --git a/src/App/Templates/Modal.purs b/src/App/Templates/Modal.purs index 51a6d61..efb69ac 100644 --- a/src/App/Templates/Modal.purs +++ b/src/App/Templates/Modal.purs @@ -47,6 +47,28 @@ modal_rr_delete rr_id action_remove_rr action_cancel_modal = Web.modal "Deleting zip_nullable :: forall a. Array a -> Array String -> Array (Tuple a String) zip_nullable txt raw = A.zip txt ([""] <> raw) +type ActionResetDelegation :: forall i. i -> i +type ActionResetDelegation i = i +reset_delegation_modal :: forall w i. Domain -> ActionResetDelegation i -> ActionCancelModal i -> HH.HTML w i +reset_delegation_modal selected_domain action_reset_delegation action_cancel_modal = + Web.modal modal_title modal_content modal_foot + where + modal_title = "Reset delegation for " <> selected_domain + modal_content :: Array (HH.HTML w i) + modal_content = + [ HH.div [HP.classes [C.notification, C.is_warning]] + [ Web.p "⚠️​ You are about to remove delegation for this domain." + , Web.p """ + The domain will be reset to the default values from a template, you'll be able to modify the domain as a new domain. + """ + ] + ] + modal_foot :: Array (HH.HTML w i) + modal_foot = + [ Web.info_btn "Reset this domain" action_reset_delegation + , Web.cancel_button action_cancel_modal + ] + type ActionValidate :: forall i. i -> i type ActionValidate i = i type ActionUpdateDelegationForm i = (Delegation.Field -> i) @@ -398,9 +420,10 @@ current_rr_modal selected_domain form rr_modal template content foot_ = Web.modal title content foot where title = case rr_modal of - NoModal -> "Error: no modal should be displayed" - DelegationModal -> "Error: the delegation modal should be displayed" - NewRRModal t_ -> "New " <> show t_ <> " resource record" - UpdateRRModal -> "Update " <> form._rr.rrtype <> " Resource Record" - RemoveRRModal rr_id -> "Error: should display removal modal instead (for resource record " <> show rr_id <> ")" + NoModal -> "Error: no modal should be displayed" + DelegationModal -> "Error: the delegation modal should be displayed" + ResetDelegationModal -> "Error: the reset delegation modal should be displayed" + NewRRModal t_ -> "New " <> show t_ <> " resource record" + UpdateRRModal -> "Update " <> form._rr.rrtype <> " Resource Record" + RemoveRRModal rr_id -> "Error: should display removal modal instead (for resource record " <> show rr_id <> ")" foot = foot_ <> [Web.cancel_button action_cancel_modal] diff --git a/src/App/Type/RRModal.purs b/src/App/Type/RRModal.purs index b639b24..6e79e7b 100644 --- a/src/App/Type/RRModal.purs +++ b/src/App/Type/RRModal.purs @@ -14,3 +14,4 @@ data RRModal | UpdateRRModal | RemoveRRModal RR.RRId | DelegationModal + | ResetDelegationModal