Allow empty names for root domain RR, like usually SPF and MX.

This commit is contained in:
Philippe Pittoli 2024-03-01 01:37:09 +01:00
parent 82bf6b57b4
commit e21ff35835

View File

@ -40,7 +40,7 @@ import CSSClasses as C
import App.AcceptedRRTypes (AcceptedRRTypes(..))
import App.ResourceRecord (ResourceRecord, emptyRR
, show_qualifier, show_mechanism_type, show_mechanism, to_mechanism
, show_qualifier, show_qualifier_char, show_mechanism_type, show_mechanism, to_mechanism
, mechanism_types, qualifier_types, modifier_types)
import App.ResourceRecord (Mechanism, Modifier, Qualifier) as RR
@ -313,7 +313,7 @@ render state
, Bulma.input_with_side_text ("domain" <> state._currentRR.rrtype) "Name" "www"
(updateForm Field_Domain)
state._currentRR.name
("." <> state._domain)
display_domain_side
, Bulma.box_input ("ttl" <> state._currentRR.rrtype) "TTL" "600"
(updateForm Field_TTL)
(show state._currentRR.ttl)
@ -329,7 +329,7 @@ render state
, Bulma.input_with_side_text "domainMX" "Name" "www"
(updateForm Field_Domain)
state._currentRR.name
("." <> state._domain)
display_domain_side
, Bulma.box_input ("ttlMX") "TTL" "600"
(updateForm Field_TTL)
(show state._currentRR.ttl)
@ -349,7 +349,7 @@ render state
, Bulma.input_with_side_text "domainSRV" "Name" "www"
(updateForm Field_Domain)
state._currentRR.name
("." <> state._domain)
display_domain_side
, Bulma.box_input ("ttlSRV") "TTL" "600"
(updateForm Field_TTL)
(show state._currentRR.ttl)
@ -381,7 +381,7 @@ render state
, Bulma.input_with_side_text "domainSPF" "Name" "www"
(updateForm Field_Domain)
state._currentRR.name
("." <> state._domain)
display_domain_side
, Bulma.box_input "ttlSPF" "TTL" "600"
(updateForm Field_TTL)
(show state._currentRR.ttl)
@ -416,6 +416,7 @@ render state
]
]
display_domain_side = (if state._currentRR.name == (state._domain <> ".") then "" else "." <> state._domain)
should_be_disabled = (if true then (HP.enabled true) else (HP.disabled true))
foot_content x = [ case state.rr_modal of
NewRRModal _ -> Bulma.btn_add (ValidateRR x)
@ -485,6 +486,9 @@ handleAction = case _ of
-- | Perform validation. In case the record is valid, it is added to the zone then the modal is closed.
-- | Else, the different errors are added to the state.
ValidateRR t -> do
-- In case the `name` part of the resource record is empty, consider the name to be the domain itself.
H.modify_ \s -> s { _currentRR = replace_name s._domain s._currentRR }
state <- H.get
case Validation.validation state._currentRR of
Left actual_errors -> do
@ -514,6 +518,9 @@ handleAction = case _ of
-- | Validate any local RR with the new `_resources` and `_local_errors`.
ValidateLocal -> do
-- In case the `name` part of the resource record is empty, consider the name to be the domain itself.
H.modify_ \s -> s { _currentRR = replace_name s._domain s._currentRR }
state <- H.get
case Validation.validation state._currentRR of
Left actual_errors -> do
@ -565,6 +572,11 @@ handleAction = case _ of
[] -> Nothing
v -> Just v
H.modify_ _ { _currentRR { mechanisms = new_value }}
where
-- In case the `name` part of the resource record is empty replace it with the domain name.
replace_name domain rr = case rr.name of
"" -> rr { name = domain <> "." }
_ -> rr
handleQuery :: forall a m. MonadAff m => Query a -> H.HalogenM State Action () Output m (Maybe a)
handleQuery = case _ of
@ -739,7 +751,7 @@ render_resources records
, HH.td_ [ Bulma.p $ maybe "spf1 (default)" id rr.v ]
, HH.td_ [ Bulma.p $ maybe "" (A.fold <<< A.intersperse " " <<< map show_mechanism) rr.mechanisms ]
, HH.td_ [ Bulma.p $ maybe "" (\ _ -> "TODO: modifiers") rr.modifiers ]
, HH.td_ [ Bulma.p $ maybe "qualifier" (\ _ -> "qualifier") rr.q ]
, HH.td_ [ Bulma.p $ maybe "" show_qualifier_char rr.q ]
, if rr.readonly
then HH.td_ [ Bulma.btn_readonly ]
else HH.td_ [ Bulma.btn_modify (CreateUpdateRRModal rr.rrid) ]