sadpandajoe commented on code in PR #44362:
URL: https://github.com/apache/superset/pull/44362#discussion_r4075991771


##########
superset/commands/theme/import_themes.py:
##########
@@ -46,6 +46,52 @@ def _set_importer_as_theme_editor(theme: "Theme", user: Any 
| None) -> None:
         theme.editors.append(subject)
 
 
+def _authorize_theme_overwrite(existing: "Theme", user: Any | None) -> None:
+    """Raise unless the current user may overwrite an existing theme."""
+    from superset import security_manager
+
+    if existing.is_system:
+        raise ThemeImportError("Cannot overwrite a system theme via import")
+    # The active system-default/dark theme slot may be overwritten by
+    # admins only; a non-admin overwriting it would change the theme
+    # rendered for every user, including the login page and other admins.
+    if (
+        existing.is_system_default or existing.is_system_dark
+    ) and not security_manager.is_admin():
+        raise ThemeImportError(
+            "Cannot overwrite the active system-default/dark theme via import"
+        )
+    # Overwriting an existing theme requires editorship (admins bypass).
+    # The one-time migration that introduced per-theme editors backfilled
+    # `editors` from each theme's creator, but any theme created by a path
+    # that bypasses `CreateThemeCommand` (or predates that backfill running)
+    # can still have a creator who isn't in `editors`. Fall back to
+    # `created_by_fk` so that creator isn't locked out of their own theme --
+    # but only when `editors` is still empty. Once it's populated (whether
+    # by the backfill or an admin's own edit), an empty result from
+    # `is_editor()` is a deliberate revocation, not an unbackfilled gap, and
+    # this fallback must not un-revoke it.
+    is_original_creator = (
+        user is not None and existing.created_by_fk == user.id and not 
existing.editors

Review Comment:
   An empty `editors` list is not proof that this theme missed the backfill: 
the migration defines it as admin-only. If an admin removes the creator as the 
sole editor, that creator can overwrite the theme and is added back here. Could 
this distinguish an unbackfilled legacy theme from an explicit zero-editor 
revocation, and cover that case?



##########
superset/migrations/versions/2026-09-16_00-01_00fab727cd0a_add_theme_editors_theme_id_index.py:
##########
@@ -0,0 +1,47 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""add theme_editors.theme_id index
+
+Revision ID: 00fab727cd0a
+Revises: 60f94cd6cd11
+Create Date: 2026-09-16 00:01:00.000000
+
+"""
+
+from superset.migrations.shared.utils import create_index, drop_index
+
+# revision identifiers, used by Alembic.
+revision = "00fab727cd0a"
+down_revision = "60f94cd6cd11"

Review Comment:
   Current `master` already has revision `93d1b4a76c02`, which also descends 
from `60f94cd6cd11`. This migration therefore creates a second Alembic head 
when merged, so upgrades and migration checks will fail. Could this be rebased 
on the current migration head?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to