Skip to content

Commit

Permalink
feat: enable tagging of charts and dashboards
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Sep 30, 2024
1 parent 27bf133 commit 63451d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 63451d6

Please sign in to comment.