feat: Update widget catalog and enhance dashboard layout features
- Added new "Dashboard-Lab-Widgets" entry to the documentation for better guidance on widget configuration. - Updated the app_dashboard version to 1.8.0 to reflect the introduction of widget catalog features and layout entitlements. - Enhanced widget catalog entries to include optional feature requirements for better visibility and access control. - Improved the DashboardLabPage to manage widget visibility based on feature entitlements, ensuring a more tailored user experience.
This commit is contained in:
1 parent
bc91396885
commit
9bc0cf70da
8 files changed
+242
-32
No files matched your search
@@ -0,0 +1,57 @@
|
||||
from dashboard_layout_schema import DashboardLayoutPayload
|
||||
from dashboard_widget_entitlements import apply_entitlements_to_layout_dict, widget_id_allowed
|
||||
|
||||
|
||||
def test_apply_entitlements_disables_widget_without_access(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
"dashboard_widget_entitlements.widget_id_allowed",
|
||||
lambda wid, pid, conn: wid != "nutrition_detail_charts",
|
||||
)
|
||||
raw = {
|
||||
"version": 1,
|
||||
"widgets": [
|
||||
{"id": "welcome", "enabled": True},
|
||||
{"id": "nutrition_detail_charts", "enabled": True},
|
||||
],
|
||||
}
|
||||
out = apply_entitlements_to_layout_dict(raw, "p", None)
|
||||
assert {w["id"]: w["enabled"] for w in out["widgets"]} == {
|
||||
"welcome": True,
|
||||
"nutrition_detail_charts": False,
|
||||
}
|
||||
|
||||
|
||||
def test_apply_entitlements_leaves_welcome_on_when_all_blocked(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
"dashboard_widget_entitlements.widget_id_allowed",
|
||||
lambda wid, pid, conn: False,
|
||||
)
|
||||
raw = {
|
||||
"version": 1,
|
||||
"widgets": [
|
||||
{"id": "welcome", "enabled": False},
|
||||
{"id": "nutrition_detail_charts", "enabled": False},
|
||||
],
|
||||
}
|
||||
out = apply_entitlements_to_layout_dict(raw, "p", None)
|
||||
assert any(w["id"] == "welcome" and w["enabled"] for w in out["widgets"])
|
||||
|
||||
|
||||
def test_widget_id_allowed_false_for_unknown_id():
|
||||
assert widget_id_allowed("not-a-widget", "p", None) is False
|
||||
|
||||
|
||||
def test_full_default_layout_still_validates_after_entitlements(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
"dashboard_widget_entitlements.widget_id_allowed",
|
||||
lambda wid, pid, conn: wid != "ai_pipeline_insight",
|
||||
)
|
||||
from dashboard_layout_schema import default_layout_dict
|
||||
|
||||
d = default_layout_dict()
|
||||
d["widgets"] = [{**x, "enabled": x["id"] == "ai_pipeline_insight"} for x in d["widgets"]]
|
||||
adj = apply_entitlements_to_layout_dict(d, "p", None)
|
||||
p2 = DashboardLayoutPayload.model_validate(adj)
|
||||
ai = next(w for w in p2.widgets if w.id == "ai_pipeline_insight")
|
||||
assert ai.enabled is False
|
||||
assert any(w.enabled for w in p2.widgets)
|
||||
@@ -1,7 +1,8 @@
|
||||
"""Widget-Katalog: Konsistenz (IDs, Default-Layout, Katalog-Response)."""
|
||||
|
||||
from dashboard_layout_schema import default_layout_dict
|
||||
from widget_catalog import ALLOWED_WIDGET_IDS, DEFAULT_LAB_WIDGET_IDS, WIDGET_CATALOG, catalog_response
|
||||
from dashboard_widget_entitlements import widgets_catalog_payload
|
||||
from widget_catalog import ALLOWED_WIDGET_IDS, DEFAULT_LAB_WIDGET_IDS, WIDGET_CATALOG
|
||||
|
||||
|
||||
def test_catalog_ids_unique_and_match_allowed():
|
||||
@@ -20,8 +21,27 @@ def test_default_layout_follows_catalog_order():
|
||||
assert any(w["enabled"] for w in d["widgets"])
|
||||
|
||||
|
||||
def test_catalog_response_shape():
|
||||
r = catalog_response()
|
||||
def test_catalog_payload_shape(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
"dashboard_widget_entitlements._check_feature_access",
|
||||
lambda *args, **kwargs: {"allowed": True},
|
||||
)
|
||||
r = widgets_catalog_payload("test-profile", None)
|
||||
assert r["catalog_version"] == 1
|
||||
assert len(r["widgets"]) == len(WIDGET_CATALOG)
|
||||
assert {w["id"] for w in r["widgets"]} == ALLOWED_WIDGET_IDS
|
||||
for w in r["widgets"]:
|
||||
assert set(w.keys()) == {"id", "title", "description", "allowed"}
|
||||
assert w["allowed"] is True
|
||||
|
||||
|
||||
def test_catalog_marks_disallowed_when_feature_blocks(monkeypatch):
|
||||
def _check(_pid, feature_id, conn=None):
|
||||
return {"allowed": feature_id != "nutrition_entries"}
|
||||
|
||||
monkeypatch.setattr("dashboard_widget_entitlements._check_feature_access", _check)
|
||||
r = widgets_catalog_payload("p", None)
|
||||
by_id = {w["id"]: w for w in r["widgets"]}
|
||||
assert by_id["welcome"]["allowed"] is True
|
||||
assert by_id["nutrition_detail_charts"]["allowed"] is False
|
||||
assert by_id["body_overview"]["allowed"] is True
|
||||
Reference in new issue
Block a user