Skip to content

Decode comment create responses with view context - #1563

Open
crazytonyli wants to merge 3 commits into
trunkfrom
bugfix/create-comment-endpoint-context
Open

Decode comment create responses with view context#1563
crazytonyli wants to merge 3 commits into
trunkfrom
bugfix/create-comment-endpoint-context

Conversation

@crazytonyli

Copy link
Copy Markdown
Contributor

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

  • I've added an entry to CHANGELOG.md under ## [Unreleased], using the Keep a Changelog categories (Added, Changed, Deprecated, Removed, Fixed, Security). Prefix breaking changes with **BREAKING:**.

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.
@wpmobilebot

Copy link
Copy Markdown
Collaborator

XCFramework Build

This PR's XCFramework is available for testing. Add to your Package.swift:

.package(url: "https://github.com/automattic/wordpress-rs", branch: "pr-build/1563")

Built from 49fa758

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