Skip to content

Commit b02bddb

Browse files
committed
fix(themes): add importer as editor when importing a new theme
Mirror CreateThemeCommand and the dashboard/chart/dataset importers so a non-admin who imports a new theme can still edit/delete it (the new editorship checks require editorship, which import previously never set).
1 parent 00d5d7e commit b02bddb

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

superset/commands/theme/import_themes.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,17 @@ def import_theme(config: dict[str, Any], overwrite: bool = False) -> "Theme | No
7070
if theme.id is None:
7171
db.session.flush()
7272

73-
# Add current user as owner if creating new theme
73+
# Add current user as owner + editor when creating a new theme, mirroring
74+
# CreateThemeCommand and the dashboard/chart/dataset importers, so the
75+
# importer can maintain (edit/delete) the theme they just created.
7476
if not existing and user:
77+
from superset.subjects.utils import get_user_subject
78+
7579
theme.changed_by = user
7680
theme.created_by = user
81+
subj = get_user_subject(user.id)
82+
if subj and subj not in theme.editors:
83+
theme.editors.append(subj)
7784

7885
return theme
7986

tests/integration_tests/themes/api_tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,11 @@ def test_import_theme(self):
459459
theme = db.session.query(Theme).filter_by(uuid=theme_config["uuid"]).one()
460460
assert theme.theme_name == "imported_theme"
461461

462+
# The importer is added as an editor so they can maintain the new theme
463+
# (mirrors CreateThemeCommand and the dashboard/chart/dataset importers).
464+
admin = self.get_user(ADMIN_USERNAME)
465+
assert any(editor.user_id == admin.id for editor in theme.editors)
466+
462467
# Cleanup
463468
db.session.delete(theme)
464469
db.session.commit()

0 commit comments

Comments
 (0)