From 63451d6486dc0dc04461ed339cd315e04562929c Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Mon, 23 Sep 2024 16:59:58 -0500 Subject: [PATCH] feat: enable tagging of charts and dashboards --- .../apps/superset/pythonpath/create_assets.py | 20 +++++++++++++------ .../pythonpath/superset_config_docker.py | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/tutoraspects/templates/aspects/apps/superset/pythonpath/create_assets.py b/tutoraspects/templates/aspects/apps/superset/pythonpath/create_assets.py index c3f025a33..0751de74b 100644 --- a/tutoraspects/templates/aspects/apps/superset/pythonpath/create_assets.py +++ b/tutoraspects/templates/aspects/apps/superset/pythonpath/create_assets.py @@ -19,7 +19,9 @@ from superset.models.slice import Slice from superset.connectors.sqla.models import SqlaTable from superset.models.embedded_dashboard import EmbeddedDashboard - +from superset.tags.models import TagType, get_tag +from superset.commands.utils import update_tags +from superset.tags.models import ObjectType from openedx.create_assets_utils import load_configs_from_directory from openedx.localization import get_translation from openedx.create_row_level_security import create_rls_filters @@ -130,7 +132,7 @@ def write_asset_to_file(asset, asset_name, folder, file_name, roles): # access the original dashboards. dashboard_roles = asset.pop("_roles", None) if dashboard_roles: - roles[asset["uuid"]] = [security_manager.find_role("Admin")] + roles[asset["uuid"]] = ([security_manager.find_role("Admin")], 'original') # Clean up old un-localized dashboard dashboard_slug = asset.get("slug") @@ -161,9 +163,9 @@ def generate_translated_asset(asset, asset_name, folder, language, roles): for role in dashboard_roles: translated_dashboard_roles.append(f"{role} - {language}") - roles[copy["uuid"]] = [ - security_manager.find_role(role) for role in translated_dashboard_roles - ] + roles[copy["uuid"]] = ([ + (security_manager.find_role(role)) for role in translated_dashboard_roles + ], language) generate_translated_dashboard_elements(copy, language) generate_translated_dashboard_filters(copy, language) @@ -251,11 +253,17 @@ def update_dashboard_roles(roles): """Update the roles of the dashboards""" owners = get_owners() - for dashboard_uuid, role_ids in roles.items(): + for dashboard_uuid, (role_ids, language) in roles.items(): dashboard = db.session.query(Dashboard).filter_by(uuid=dashboard_uuid).one() dashboard.roles = role_ids if owners: dashboard.owners = owners + tags = [get_tag(language, db.session, TagType.custom).id] + update_tags(ObjectType.dashboard, dashboard.id, dashboard.tags, tags) + + for slice in dashboard.slices: + update_tags(ObjectType.chart, slice.id, slice.tags, tags) + db.session.commit() def get_owners(): diff --git a/tutoraspects/templates/aspects/apps/superset/pythonpath/superset_config_docker.py b/tutoraspects/templates/aspects/apps/superset/pythonpath/superset_config_docker.py index 8adcc2ddd..7457bd162 100644 --- a/tutoraspects/templates/aspects/apps/superset/pythonpath/superset_config_docker.py +++ b/tutoraspects/templates/aspects/apps/superset/pythonpath/superset_config_docker.py @@ -91,7 +91,7 @@ "EMBEDDABLE_CHARTS": True, "EMBEDDED_SUPERSET": True, "ENABLE_TEMPLATE_PROCESSING": True, - "TAGGING_SYSTEM": False, + "TAGGING_SYSTEM": True, } # Add this custom template processor which returns the list of courses the current user can access