Decode comment create responses with view context - #1563
Open
crazytonyli wants to merge 3 commits into
Open
Conversation
WordPress core returns a view-context response to users without the moderate_comments capability, but the comments Create endpoint decodes its response as CommentWithEditContext. The edit-only fields (such as content.raw) are missing from the view-context body, so deserialization fails even though the comment is created on the server.
WordPress core picks the create-response context by capability: users with moderate_comments get an edit-context body, everyone else gets a view-context body, and the request's ?context= parameter is overridden server-side. Decoding the response as CommentWithEditContext therefore failed for any non-moderator (e.g. a subscriber replying to a comment), reporting an error even though the comment was created. Switch the Create endpoint's output to CommentWithViewContext, which parses for every role because edit-context JSON is a superset of view-context JSON. Callers that need edit-only fields (author_email, author_ip, author_user_agent, content.raw) can retrieve the comment with edit context using the returned ID. This is a breaking change for consumers reading edit-only fields off the create result.
Collaborator
XCFramework BuildThis PR's XCFramework is available for testing. Add to your .package(url: "https://github.com/automattic/wordpress-rs", branch: "pr-build/1563")Built from 49fa758 |
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.
Description
The creating comment endpoint returns different responses based on the user role. That means, at the moment, when a subscriber calls this library to create comment, the library fails to parse the result.
This PR changes the endpoint implementation from returning edit context to view context, to avoid parsing errors. If the client need a edit context, they'll need to make another call to fetch it.
/cc @nbradbury This change is likely to have an impact on the Android app.
Changelog
CHANGELOG.mdunder## [Unreleased], using the Keep a Changelog categories (Added,Changed,Deprecated,Removed,Fixed,Security). Prefix breaking changes with**BREAKING:**.