Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST API: Add action-delete flag to declare delete_post capability for post objects #335

Closed
wants to merge 2 commits into from

Conversation

ocean90
Copy link
Member

@ocean90 ocean90 commented Jun 14, 2020

Trac ticket: https://core.trac.wordpress.org/ticket/50388


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@@ -1981,10 +1981,14 @@ protected function get_available_actions( $post, $request ) {

$post_type = get_post_type_object( $post->post_type );

if ( 'attachment' !== $this->post_type && current_user_can( $post_type->cap->publish_posts ) ) {
if ( 'attachment' !== $this->post_type && current_user_can( 'publish_post', $post->ID ) ) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Since this is an action for the specific post we should use the meta cap and pass the post ID to the check. By default this just falls back to publish_posts.

Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines +2475 to +2479
'properties' => array(
'delete' => array(
'type' => 'boolean',
),
),
Copy link
Member Author

Choose a reason for hiding this comment

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

This probably needs to be something else?

Copy link
Member

Choose a reason for hiding this comment

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

The idea of the targetSchema is so that a developer can programmatically determine that changing the resource such that it would successfully validate against the targetSchema would require a specific set of capabilities beyond PUT being available in the Allow header. The developer can then verify that the resource includes this link in the response.

Since a post is deleted by making a DELETE request instead of a PUT, the targetSchema can't actually be used and the link relation solely communicates the semantics.

So we could drop the targetSchema entirely.

@ocean90
Copy link
Member Author

ocean90 commented Jun 28, 2020

Superseded by WordPress/gutenberg#23174.

@ocean90 ocean90 closed this Jun 28, 2020
@ocean90 ocean90 deleted the add/rest-api-delete-action branch June 28, 2020 10:40
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