Skip to content
This repository has been archived by the owner on Sep 24, 2018. It is now read-only.

Use proper status code when failing to get comments of private post #1867

Merged
merged 2 commits into from
Dec 15, 2015

Conversation

danielbachhuber
Copy link
Member

No description provided.

@danielbachhuber danielbachhuber added this to the 2.0 Beta 10 milestone Dec 15, 2015
@danielbachhuber
Copy link
Member Author

@WP-API/amigos #reviewmerge

@@ -354,7 +354,7 @@ public function get_items_permissions_check( $request ) {
$post = get_post( (int) $request['post'] );

if ( $post && ! $this->check_read_post_permission( $post ) ) {
return new WP_Error( 'rest_cannot_read_post', __( 'Sorry, you cannot read the post for this comment.' ) );
return new WP_Error( 'rest_cannot_read_post', __( 'Sorry, you cannot read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) );
Copy link
Member

Choose a reason for hiding this comment

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

@danielbachhuber Would a 403 status code be more accurate here? Even if a user was logged-in they may not have permission to read private posts.

Copy link
Member Author

Choose a reason for hiding this comment

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

rest_authorization_required_code() returns 401 when the user is logged out, and 403 when the user is logged in?

Copy link
Member

Choose a reason for hiding this comment

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

401 is basically "if you are not logged in, login and retry, then we'll tell you if you can access this" so I think we are good.

danielbachhuber added a commit that referenced this pull request Dec 15, 2015
Use proper status code when failing to get comments of private post
@danielbachhuber danielbachhuber merged commit 9cfa514 into develop Dec 15, 2015
@danielbachhuber danielbachhuber deleted the fix-comment-get-private-post branch December 15, 2015 17:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants