refactor(web-app-dashboard): hide a tile through services.dashboard.enabled instead of display

services.dashboard.enabled already says whether a role takes part in the dashboard: roles_with_service lists only roles with enabled and shared as tile-reachability targets, the CSP filter adds the dashboard to frame-ancestors only when it is set, and docker_cards uses it as the card's iframe flag. A separate display key duplicated that switch and left a role with enabled false still rendering a card. docker_cards now skips the card when services.dashboard.enabled is false (a role without a dashboard binding keeps its card, and a value that is not a boolean fails loudly), so display, its validator exception and its roles_with_service filter go again; base.md documents enabled as the per-host switch.

An inventory hides a tile with applications.<role>.services.dashboard.enabled: false, which also drops the dashboard framing of that role. Unit tests cover false, true, a missing binding, a rendered string and a non-boolean; forcing the helper to always show the card fails four of them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 5.5 committed 2026-10-29 19:00:46 +01:00
1 parent ae7f2bbcb2
commit c855efc30a
10 files changed
+48 -123

No files matched your search

@@ -105,33 +105,6 @@ class TestCompareApplicationKeys(unittest.TestCase):
defaults = {"web-app-cst-demo": {"services": {"port": 8080}}}
self.assertEqual(compare_application_keys(apps, defaults, "src"), [])
def test_dashboard_display_is_legal_where_dashboard_is_declared(self):
apps = {"app1": {"services": {"dashboard": {"display": False}}}}
defaults = {"app1": {"services": {"dashboard": {"enabled": False}}}}
self.assertEqual(compare_application_keys(apps, defaults, "src"), [])
def test_dashboard_display_is_legal_where_a_variant_declares_dashboard(self):
apps = {"app1": {"services": {"dashboard": {"display": False}}}}
defaults = {"app1": {"services": {}}}
variants = {"app1": [{"services": {"dashboard": {"enabled": True}}}]}
self.assertEqual(compare_application_keys(apps, defaults, "src", variants), [])
def test_dashboard_display_without_a_dashboard_binding_is_flagged(self):
apps = {"app1": {"services": {"dashboard": {"display": False}}}}
defaults = {"app1": {"services": {"port": 8080}}}
result = compare_application_keys(apps, defaults, "src")
self.assertEqual(
sorted(err.rsplit(": ", 1)[1] for err in result),
["services.dashboard", "services.dashboard.display"],
)
def test_other_undeclared_dashboard_keys_stay_flagged(self):
apps = {"app1": {"services": {"dashboard": {"dispaly": False}}}}
defaults = {"app1": {"services": {"dashboard": {"enabled": False}}}}
result = compare_application_keys(apps, defaults, "src")
self.assertEqual(len(result), 1)
self.assertIn("services.dashboard.dispaly", result[0])
def test_declaration_keys_on_an_in_tree_role_are_flagged(self):
apps = {"app1": {"custom": True, "source": {"url": "https://x/y.git"}}}
defaults = {"app1": {"services": {}}}
@@ -382,40 +382,34 @@ logo:
fake_variables["group_names"] = ["portfolio", "other"]
return fake_variables
def test_display_false_skips_the_card(self):
def test_enabled_false_skips_the_card(self):
fake_variables = self._base_fake_variables()
fake_variables["applications"]["portfolio"]["services"]["dashboard"][
"display"
"enabled"
] = False
result = self._run_lookup(LookupModule(), fake_variables)
self.assertEqual(result, [[]])
def test_absent_display_shows_the_card(self):
def test_a_role_without_a_dashboard_binding_shows_the_card(self):
fake_variables = self._base_fake_variables()
self.assertNotIn(
"display",
fake_variables["applications"]["portfolio"]["services"]["dashboard"],
)
fake_variables["applications"]["portfolio"]["services"] = {}
result = self._run_lookup(LookupModule(), fake_variables)
self.assertEqual([c["title"] for c in result[0]], ["Portfolio Application"])
def test_display_true_shows_the_card(self):
def test_enabled_true_shows_the_card(self):
fake_variables = self._base_fake_variables()
fake_variables["applications"]["portfolio"]["services"]["dashboard"][
"display"
] = True
result = self._run_lookup(LookupModule(), fake_variables)
self.assertEqual([c["title"] for c in result[0]], ["Portfolio Application"])
def test_display_false_hides_only_its_own_card(self):
def test_enabled_false_hides_only_its_own_card(self):
fake_variables = self._two_role_variables()
fake_variables["applications"]["other"]["services"]["dashboard"]["display"] = (
fake_variables["applications"]["other"]["services"]["dashboard"]["enabled"] = (
False
)
@@ -423,7 +417,7 @@ logo:
self.assertEqual([c["title"] for c in result[0]], ["Portfolio Application"])
def test_both_cards_render_without_display(self):
def test_both_cards_render_when_both_are_enabled(self):
fake_variables = self._two_role_variables()
result = self._run_lookup(LookupModule(), fake_variables)
@@ -444,11 +438,11 @@ logo:
self.assertEqual([c["title"] for c in result[0]], ["Portfolio Application"])
def test_non_bool_display_fails_loudly(self):
def test_non_boolean_enabled_fails_loudly(self):
fake_variables = self._base_fake_variables()
fake_variables["applications"]["portfolio"]["services"]["dashboard"][
"display"
] = "false"
"enabled"
] = "maybe"
with self.assertRaisesRegex(AnsibleError, "portfolio"):
self._run_lookup(LookupModule(), fake_variables)
@@ -613,37 +613,6 @@ class RolesWithServiceLookupTests(unittest.TestCase):
("matrix.example.com", "https://web-app-chat.example.com"),
)
def test_dashboard_display_false_drops_the_tile_target(self):
applications = {
"web-app-hidden": {
"services": {
"dashboard": {"enabled": True, "shared": True, "display": False}
},
"domains": {"canonical": ["hidden.example.com"]},
},
"web-app-shown": {
"services": {"dashboard": {"enabled": True, "shared": True}},
"domains": {"canonical": ["shown.example.com"]},
},
}
result = self._run(["dashboard"], applications)[0]
self.assertEqual([r["id"] for r in result], ["web-app-shown"])
def test_dashboard_display_true_keeps_the_tile_target(self):
applications = self._card_target_role("dashboard", display=True)
result = self._run(["dashboard"], applications)[0]
self.assertEqual([r["id"] for r in result], ["web-app-chat"])
def test_dashboard_non_bool_display_fails_loudly(self):
applications = self._card_target_role("dashboard", display="false")
with self.assertRaisesRegex(AnsibleError, "web-app-chat"):
self._run(["dashboard"], applications)
def test_other_services_ignore_a_display_key(self):
applications = self._card_target_role("prometheus", display=False)
result = self._run(["prometheus"], applications)[0]
self.assertEqual([r["id"] for r in result], ["web-app-chat"])
if __name__ == "__main__":
unittest.main()
@@ -44,20 +44,23 @@ class TestCardTargetKey(unittest.TestCase):
class TestCardIsDisplayed(unittest.TestCase):
def test_a_binding_without_the_key_is_displayed(self):
self.assertTrue(card_is_displayed("web-app-foo", {"enabled": True}))
self.assertTrue(card_is_displayed("web-app-foo", {"shared": True}))
def test_a_missing_binding_is_displayed(self):
self.assertTrue(card_is_displayed("web-app-foo", None))
def test_display_false_hides_the_card(self):
self.assertFalse(card_is_displayed("web-app-foo", {"display": False}))
def test_enabled_false_hides_the_card(self):
self.assertFalse(card_is_displayed("web-app-foo", {"enabled": False}))
def test_display_true_shows_the_card(self):
self.assertTrue(card_is_displayed("web-app-foo", {"display": True}))
def test_enabled_true_shows_the_card(self):
self.assertTrue(card_is_displayed("web-app-foo", {"enabled": True}))
def test_a_string_flag_fails_loudly(self):
def test_a_rendered_string_flag_is_read_as_a_boolean(self):
self.assertFalse(card_is_displayed("web-app-foo", {"enabled": "False"}))
def test_a_non_boolean_flag_fails_loudly(self):
with self.assertRaisesRegex(AnsibleError, "web-app-foo"):
card_is_displayed("web-app-foo", {"display": "false"})
card_is_displayed("web-app-foo", {"enabled": "maybe"})
if __name__ == "__main__":