Repository navigation
fix(media): let upload_files users run fetch-wordpress-media - #4008
Merged
Merged
Conversation
fetch-wordpress-media required can_manage() while upload-media allows any upload_media (core upload_files) holder, so team uploaders hit rest_ability_cannot_execute when listing media. Allow upload_media and scope non-operators to attachments they can read_post, matching what core /wp/v2/media exposes. Closes #4005
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4005
Problem
datamachine/fetch-wordpress-mediarequiredPermissionHelper::can_manage(), butupload-mediaallows anyone withPermissionHelper::can( 'upload_media' )(coreupload_files). Team users (extra_chill_team) could import into the Media Library but gotrest_ability_cannot_executewhen listing it.Fix
checkPermission()now returnscan_manage() || can( 'upload_media' ).executeskips attachments that failPermissionHelper::can_wp_capability( 'read_post', $attachment_id ). For aninheritattachment, core maps that check to the parent post's status and author. So uploaders can't see media attached to other users' drafts or private posts, which matches what/wp/v2/mediashows them. Operators are unchanged.Tests
New
tests/fetch-wordpress-media-permission-smoke.php(php tests/fetch-wordpress-media-permission-smoke.php): 9 checks pass. It fails on the pre-fix code.upload_filesnon-manager: allowed. Sees media whose parent is published or is their own private post. Doesn't see media on another user's draft.manage_flowsoperator: allowed, see all media.Related (not changed)
Other fetch abilities still gate on
can_manage()alone: QueryWordPressPosts, GetWordPressPost, FetchRss, FetchFiles, FetchWordPressApi. None has a matching non-manager write path the way media hasupload-media, so they're left alone.Note: the item payload still includes the server
file_path(needed by the pipeline engine), and/wp/v2/mediadoesn't expose that.AI-authored (Extra Chill Bot). Fixed directly outside Homeboy Cook with operator authorization because the Lab runner was capacity-blocked.