From aab39ee01be42517ac401ca82c2db423ce077bcc Mon Sep 17 00:00:00 2001 From: Brian Mesick Date: Wed, 17 Apr 2024 09:16:15 -0400 Subject: [PATCH] fix: Request permissions for localized dashboards --- platform_plugin_aspects/utils.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/platform_plugin_aspects/utils.py b/platform_plugin_aspects/utils.py index 0c84919..3f8caec 100644 --- a/platform_plugin_aspects/utils.py +++ b/platform_plugin_aspects/utils.py @@ -59,7 +59,7 @@ def generate_superset_context( if not dashboard.get("allow_translations"): continue dashboard["slug"] = f"{dashboard['slug']}-{language}" - dashboard["uuid"] = str(get_uuid5(dashboard["uuid"], language)) + dashboard["uuid"] = get_localized_uuid(dashboard["uuid"], language) superset_url = _fix_service_url(superset_config.get("service_url")) @@ -110,11 +110,23 @@ def generate_guest_token(user, course, dashboards, filters) -> str: formatted_filters = [filter.format(course=course, user=user) for filter in filters] + resources = [] + + # Get permissions for all localized versions of the dashboards + for dashboard in dashboards: + resources.append({"type": "dashboard", "id": dashboard["uuid"]}) + + if dashboard.get("allow_translations"): + for locale in settings.SUPERSET_DASHBOARD_LOCALES: + resources.append( + {"type": "dashboard", "id": get_localized_uuid(dashboard["uuid"], locale)} + ) + + print(resources) + data = { "user": _superset_user_data(user), - "resources": [ - {"type": "dashboard", "id": dashboard["uuid"]} for dashboard in dashboards - ], + "resources": resources, "rls": [{"clause": filter} for filter in formatted_filters], } @@ -251,10 +263,10 @@ def get_ccx_courses(course_id): return [] -def get_uuid5(base_uuid, language): +def get_localized_uuid(base_uuid, language): """ Generate an idempotent uuid. """ base_uuid = uuid.UUID(base_uuid) base_namespace = uuid.uuid5(base_uuid, "superset") - return uuid.uuid5(base_namespace, language) + return str(uuid.uuid5(base_namespace, language))