fix(posts): per-platform media validation instead of shared list - #11
Merged
Merged
Conversation
ContentTypeCompatibleWithMedia::entriesForUpdate() now resolves each platform entry's own effective media list (request media if resubmitted, else PostPlatform::scopedMediaItems(), else the post's full stored media) instead of validating every platform against one shared list. errorsFor() consumes each entry's own media accordingly. Wires A1's scopedMediaItems() helper into validation for the first time. A content_type that requires media whose scoped selection resolves to none still correctly fails, deliberately not softened. Web UpdatePostRequest now runs the check via an after() validator (like the API request already did) instead of a field-level Rule bound to a single shared $data['media'], closing the same "publish without resubmitting content_type" gap the API path already covers. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
6 tasks
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.
Summary
ContentTypeCompatibleWithMedia::entriesForUpdate()now resolves each platform entry's own effective media list instead of validating every platform against one shared list. Wires PR #9's (A1)PostPlatform::scopedMediaItems()into validation for the first time.Resolution order per entry:
scopedMediaItems()(pivot-scoped selection; falls back internally to the post's full media when the pivot has no rows for that platform, today's universal case, so no behavior change there).PostPlatformrow could be resolved for the entry at all (defensive).errorsFor()consumes each entry's ownmediakey instead of a second shared$mediaparameter.Randfall handled deliberately: a
content_typethat requires media (e.g.facebook_story) whose scoped media resolves to an empty list still correctly fails with the "requires media" error. This is the correct behavior, not a bug to soften, and is covered by a dedicated test.Call sites updated to match:
app/Http/Requests/App/Post/UpdatePostRequest.php: replaced the old field-levelRule::when(..., [new ContentTypeCompatibleWithMedia])(bound to one shared$data['media']) with anafter()validator usingentriesForUpdate()/errorsFor(), mirroring what the public API request already did. This also closes the same "schedule/publish without resubmitting content_type" gap the API path already covered, which the field-level rule never handled for the web app.app/Http/Requests/Api/Post/UpdatePostRequest.php: passesrequestMediaintoentriesForUpdate()instead of pre-resolving a shared media array.app/Mcp/Tools/Post/UpdatePostTool.php: drops the now-removed seconderrorsFor()argument.assertStoredPostCompatible()(used byPublishPostTool): same, drops the second argument.Also fixes a lazy-loading bug surfaced while wiring this in:
PostPlatform::scopedMediaItems()reads$this->post->mediaItems, which throws underModel::shouldBeStrict()(tests/local) unless the inversepostrelation is pre-set. Added a privatepostPlatformsFor()helper that sets it on every fetchedPostPlatformbeforescopedMediaItems()can be called.Test plan
tests/Unit/Rules/ContentTypeCompatibleWithMediaTest.php: 48 passed, including 6 new tests covering all three fallback stages, the empty-media randfall, two platforms validating independently against different effective media, andassertStoredPostCompatible().tests/Feature/UpdatePostRequestTest.php(web): 26 passed.PostApiPlatformMetaTest,PostMediaApiTest,PostApiTest,PostMediaExistsValidationTest,PostToolTest,PostPlatformMetaToolTest,PostPublishToolTest,PublishPostTest): 194 passed.vendor/bin/pint --dirty --format agent: passed, no changes needed.🤖 Generated with Claude Code