From 62e1056a3581ae10f15d0dc9eb818a95d09f10d8 Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Fri, 5 Apr 2024 16:09:40 -0500 Subject: [PATCH 1/2] fix: allow to embed translated dashboards (cherry picked from commit 40ad3796578e8f74f72788fcdd98d6ce4f0f45b5) --- tutoraspects/patches/openedx-common-settings | 1 + .../apps/superset/pythonpath/create_assets.py | 42 ++++++++++++------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/tutoraspects/patches/openedx-common-settings b/tutoraspects/patches/openedx-common-settings index 4ce683d21..64e849461 100644 --- a/tutoraspects/patches/openedx-common-settings +++ b/tutoraspects/patches/openedx-common-settings @@ -15,6 +15,7 @@ EVENT_SINK_CLICKHOUSE_PII_MODELS = {{ EVENT_SINK_PII_MODELS }} ASPECTS_INSTRUCTOR_DASHBOARDS = {{ ASPECTS_INSTRUCTOR_DASHBOARDS }} SUPERSET_EXTRA_FILTERS_FORMAT = {{ ASPECTS_SUPERSET_EXTRA_FILTERS_FORMAT }} +SUPERSET_DASHBOARD_LOCALES = {{ SUPERSET_DASHBOARD_LOCALES }} {% if ASPECTS_ENABLE_INSTRUCTOR_DASHBOARD_PLUGIN %} try: not OPEN_EDX_FILTERS_CONFIG diff --git a/tutoraspects/templates/aspects/apps/superset/pythonpath/create_assets.py b/tutoraspects/templates/aspects/apps/superset/pythonpath/create_assets.py index d82e8c6d3..613701235 100644 --- a/tutoraspects/templates/aspects/apps/superset/pythonpath/create_assets.py +++ b/tutoraspects/templates/aspects/apps/superset/pythonpath/create_assets.py @@ -29,6 +29,7 @@ } DASHBOARD_LOCALES = {{SUPERSET_DASHBOARD_LOCALES}} +EMBEDDABLE_DASHBOARDS = {{SUPERSET_EMBEDDABLE_DASHBOARDS}} for folder in ASSET_FOLDER_MAPPING.values(): os.makedirs(f"{BASE_DIR}/{folder}", exist_ok=True) @@ -266,21 +267,32 @@ def update_dashboard_roles(roles): def update_embeddable_uuids(): """Update the uuids of the embeddable dashboards""" - for dashboard_slug, embeddable_uuid in {{SUPERSET_EMBEDDABLE_DASHBOARDS}}.items(): - dashboard = db.session.query(Dashboard).filter_by(slug=dashboard_slug).first() - if dashboard is None: - print(f"WARNING: Dashboard {dashboard_slug} not found") - continue - - embedded_dashboard = db.session.query(EmbeddedDashboard).filter_by(dashboard_id=dashboard.id).first() - if embedded_dashboard is None: - embedded_dashboard = EmbeddedDashboard() - embedded_dashboard.dashboard_id = dashboard.id - embedded_dashboard.uuid = embeddable_uuid - - db.session.add(embedded_dashboard) - db.session.commit() - + for dashboard_slug, embeddable_uuid in EMBEDDABLE_DASHBOARDS.items(): + create_embeddable_dashboard_by_slug(dashboard_slug, embeddable_uuid) + + for locale in DASHBOARD_LOCALES: + for dashboard_slug, embeddable_uuid in EMBEDDABLE_DASHBOARDS.items(): + slug = f"{dashboard_slug}-{locale}" + current_uuid = get_uuid5(embeddable_uuid, locale) + create_embeddable_dashboard_by_slug(slug, current_uuid) + + +def create_embeddable_dashboard_by_slug(dashboard_slug, embeddable_uuid): + """Create an embeddable dashboard by slug""" + print(f"Creating embeddable dashboard {dashboard_slug}, {embeddable_uuid}") + dashboard = db.session.query(Dashboard).filter_by(slug=dashboard_slug).first() + if dashboard is None: + print(f"WARNING: Dashboard {dashboard_slug} not found") + return + + embedded_dashboard = db.session.query(EmbeddedDashboard).filter_by(dashboard_id=dashboard.id).first() + if embedded_dashboard is None: + embedded_dashboard = EmbeddedDashboard() + embedded_dashboard.dashboard_id = dashboard.id + embedded_dashboard.uuid = embeddable_uuid + + db.session.add(embedded_dashboard) + db.session.commit() if __name__ == "__main__": main() From 2dfa72d4942ba4d12975876767d2ad1f5f0d9341 Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Tue, 9 Apr 2024 11:30:16 -0500 Subject: [PATCH 2/2] chore: upgrade platform-plugin-aspects to v0.6.0 --- .../patches/openedx-dev-dockerfile-post-python-requirements | 2 +- .../patches/openedx-dockerfile-post-python-requirements | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tutoraspects/patches/openedx-dev-dockerfile-post-python-requirements b/tutoraspects/patches/openedx-dev-dockerfile-post-python-requirements index f272b1dcb..27c5557eb 100644 --- a/tutoraspects/patches/openedx-dev-dockerfile-post-python-requirements +++ b/tutoraspects/patches/openedx-dev-dockerfile-post-python-requirements @@ -1,4 +1,4 @@ RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \ - pip install "platform-plugin-aspects==v0.5.0" + pip install "platform-plugin-aspects==v0.6.0" RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \ pip install "edx-event-routing-backends==v9.0.0" diff --git a/tutoraspects/patches/openedx-dockerfile-post-python-requirements b/tutoraspects/patches/openedx-dockerfile-post-python-requirements index f272b1dcb..27c5557eb 100644 --- a/tutoraspects/patches/openedx-dockerfile-post-python-requirements +++ b/tutoraspects/patches/openedx-dockerfile-post-python-requirements @@ -1,4 +1,4 @@ RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \ - pip install "platform-plugin-aspects==v0.5.0" + pip install "platform-plugin-aspects==v0.6.0" RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \ pip install "edx-event-routing-backends==v9.0.0"