Skip to content

Let only weblog Admins change the files a custom theme uses - #388

Open
snoopdave wants to merge 1 commit into
masterfrom
media-theme-files-admin-only
Open

snoopdave wants to merge 1 commit into
masterfrom
media-theme-files-admin-only

Conversation

@snoopdave

Copy link
Copy Markdown
Contributor

Master twin of #387: a custom theme keeps its scripts, stylesheets and images in the media library, where they are served as part of the weblog's design, and Authors could replace, move or delete them like their own uploads.

  • Replacing, moving or deleting a theme file (a media file with an original path), or deleting a folder that holds one, now needs Admin on the weblog, in the media pages and through AtomPub.
  • New ThemeMediaFileChangeTest. Full suite on JDK 25 (release 21): 935 tests, 0 failures.
  • CHANGES.md entry under 7.0.0 behaviour changes.

A custom theme keeps its scripts, stylesheets and images in the media
library, where they are served as part of the weblog's design. Replacing,
moving or deleting one now needs Admin on the weblog, in the media pages
and through AtomPub. Other media files are unchanged.
@snoopdave
snoopdave requested a review from mraible November 24, 2026 22:52

@mraible mraible left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things before this merges, and some smaller ones:

  1. Uploads migrated from the old uploads directory are treated as theme files. ThemeMediaFiles.isThemeFile treats any file with a non-blank originalPath as a theme file. JPAMediaFileManagerImpl.upgradeUploadsDir sets originalPath (/<dir>/<name>) on every legacy upload it migrates. On a weblog upgraded that way, an Author can no longer delete, move or replace their own old photos, and is told the weblog's theme uses them. That contradicts the CHANGES entry ("Authors still manage their own media files"). Files left over from a custom theme after the weblog switches to a shared theme are locked the same way. Marking theme files explicitly, for example when the theme import creates them, or checking against the current custom theme's resources, would avoid guessing from originalPath.

  2. The original-path field isn't covered when mediafile.originalPathEdit.enabled=true. It's off by default, but when it's on, MediaFileEdit.save() checks only for a replacement upload or a directory change. The setOriginalPath(bean.getOriginalPath()) call after it runs for anyone who can edit the file. An Author can clear the path on a theme file, which releases it so they can delete or replace it. Or they can set a theme path on their own upload, which then serves in its place, or makes getSingleResult throw NonUniqueResultException for that path. Treating a change to originalPath as a protected change (needing weblog ADMIN) would close it.

Smaller:

  • Renaming isn't guarded. The name is the path Atom putMedia and deleteEntry find the file by, so an Author's rename breaks an admin's Atom tooling for that theme file.
  • mayChange(weblog, user, null) returns true. Atom deleteEntry passes getMediaFileByPath's result without a null check, so a missing path NPEs in removeMediaFile instead of returning 404. putMedia doesn't null-check the weblog either. These predate this PR.
  • There are no tests for the Atom putMedia/deleteEntry checks or the deleteFolder loop in MediaFileView.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants