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 Nov 25, 2024
1 parent 2e6e066 commit 8097d12
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
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.delete_assets import delete_assets
from openedx.create_assets_utils import load_configs_from_directory
from openedx.localization import get_translation
Expand Down Expand Up @@ -143,7 +146,7 @@ def write_asset_to_file(asset, asset_name, folder, file_name, roles, translated_
# 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 @@ -178,9 +181,9 @@ def generate_translated_asset(asset, asset_name, folder, language, roles, transl
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 @@ -268,11 +271,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 8097d12

Please sign in to comment.