feat: Implement widget-feature assignment management in admin dashboard
- Added new API endpoints for listing and updating widget-feature assignments, allowing for custom feature requirements. - Introduced a new admin page for managing widget-feature assignments, enhancing the admin interface. - Updated navigation to include a link to the new widget-feature assignments page. - Refactored widget access logic to support AND-based feature requirements for widgets. - Bumped app_dashboard version to 1.11.0 to reflect these changes and improvements.
This commit is contained in:
1 parent
365ce49c6a
commit
24daeeb83c
10 files changed
+498
-13
No files matched your search
@@ -9,6 +9,7 @@ import copy
|
||||
from typing import Any
|
||||
|
||||
from widget_catalog import WIDGET_CATALOG
|
||||
from widget_feature_requirements_db import get_widget_required_feature_ids
|
||||
|
||||
|
||||
def _check_feature_access(profile_id: str, feature_id: str, conn) -> dict:
|
||||
@@ -21,13 +22,15 @@ _WIDGET_ENTRY_BY_ID: dict[str, dict[str, Any]] = {e["id"]: e for e in WIDGET_CAT
|
||||
|
||||
|
||||
def widget_id_allowed(widget_id: str, profile_id: str, conn) -> bool:
|
||||
entry = _WIDGET_ENTRY_BY_ID.get(widget_id)
|
||||
if entry is None:
|
||||
if _WIDGET_ENTRY_BY_ID.get(widget_id) is None:
|
||||
return False
|
||||
fid = entry.get("requires_feature")
|
||||
if not fid:
|
||||
fids = get_widget_required_feature_ids(widget_id, conn)
|
||||
if not fids:
|
||||
return True
|
||||
return bool(_check_feature_access(profile_id, fid, conn)["allowed"])
|
||||
for fid in fids:
|
||||
if not _check_feature_access(profile_id, fid, conn)["allowed"]:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def _public_row(entry: dict[str, Any], *, allowed: bool) -> dict[str, Any]:
|
||||
@@ -43,10 +46,7 @@ def widgets_catalog_for_profile(profile_id: str, conn) -> list[dict[str, Any]]:
|
||||
"""Zeilen für GET /api/app/widgets/catalog (ohne internes requires_feature-Feld)."""
|
||||
out: list[dict[str, Any]] = []
|
||||
for e in WIDGET_CATALOG:
|
||||
fid = e.get("requires_feature")
|
||||
allowed = True
|
||||
if fid:
|
||||
allowed = bool(_check_feature_access(profile_id, fid, conn)["allowed"])
|
||||
allowed = widget_id_allowed(e["id"], profile_id, conn)
|
||||
out.append(_public_row(e, allowed=allowed))
|
||||
return out
|
||||
|
||||
|
||||
Reference in new issue
Block a user