codeant-ai-for-open-source[bot] commented on code in PR #44362:
URL: https://github.com/apache/superset/pull/44362#discussion_r4080913253
##########
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:
**Suggestion:** `created_by_fk` fallback treats an empty editor list as
never initialized, so removing every editor lets the original creator regain
overwrite access.
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Sometimes` ยท ๐ท๏ธ `Security`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=86d5fb585351459fad0906e3ae120757&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=86d5fb585351459fad0906e3ae120757&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/commands/theme/import_themes.py
**Line:** 74:76
**Comment:**
*Security: `created_by_fk` fallback treats an empty editor list as
never initialized, so removing every editor lets the original creator regain
overwrite access.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44362&comment_hash=a10412ae98956e90464bd400ec7d5dc71543d090499e0714e47908eb37f015ac&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44362&comment_hash=a10412ae98956e90464bd400ec7d5dc71543d090499e0714e47908eb37f015ac&reaction=dislike'>๐</a>
--
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]