Skip to content

Commit

Permalink
fix: Request permissions for localized dashboards
Browse files Browse the repository at this point in the history
  • Loading branch information
bmtcril committed Apr 17, 2024
1 parent d8d840b commit aab39ee
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions platform_plugin_aspects/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand Down Expand Up @@ -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],
}

Expand Down Expand Up @@ -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))

0 comments on commit aab39ee

Please sign in to comment.