Skip to content

Commit

Permalink
fix: Fix slug repeating language and change tab name
Browse files Browse the repository at this point in the history
  • Loading branch information
bmtcril committed Apr 17, 2024
1 parent 3927b31 commit f13f365
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion platform_plugin_aspects/extensions/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def run_filter(
section_data = {
"fragment": frag,
"section_key": BLOCK_CATEGORY,
"section_display_name": _("Analytics"),
"section_display_name": _("Reports"),
"course_id": str(context.get("course_id")),
"superset_guest_token_url": str(context.get("superset_guest_token_url")),
"superset_url": str(context.get("superset_url")),
Expand Down
2 changes: 1 addition & 1 deletion platform_plugin_aspects/static/html/superset.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h2>{{display_name}}</h2>
{% endif %}

<script type="text/javascript">
window.superset_dashboards = {{superset_dashboards | safe }};
window.superset_dashboards = {{superset_dashboards_json | safe }};
window.superset_url = "{{superset_url}}";
window.superset_guest_token_url = "{{superset_guest_token_url}}";
</script>
Expand Down
32 changes: 24 additions & 8 deletions platform_plugin_aspects/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from __future__ import annotations

import copy
import json
import logging
import os
import uuid
Expand Down Expand Up @@ -49,12 +51,15 @@ def generate_superset_context(
course_id = context["course_id"]
superset_config = settings.SUPERSET_CONFIG

# We're modifying this, keep a local copy
rtn_dashboards = copy.deepcopy(dashboards)

if language:
for dashboard in dashboards:
for dashboard in rtn_dashboards:
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 All @@ -69,7 +74,8 @@ def generate_superset_context(

context.update(
{
"superset_dashboards": dashboards,
"superset_dashboards": rtn_dashboards,
"superset_dashboards_json": json.dumps(rtn_dashboards),
"superset_url": superset_url,
"superset_guest_token_url": guest_token_url,
}
Expand Down Expand Up @@ -104,11 +110,21 @@ 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)}
)

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 @@ -245,10 +261,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 f13f365

Please sign in to comment.