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

"Move to Trash" button doesn't respect 'delete_post' capability #14828

Closed
danielbachhuber opened this issue Apr 4, 2019 · 3 comments
Closed
Assignees
Labels
Backwards Compatibility Issues or PRs that impact backwards compatability [Feature] Document Settings Document settings experience REST API Interaction Related to REST API [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@danielbachhuber
Copy link
Member

danielbachhuber commented Apr 4, 2019

Describe the bug

When a user cannot delete a post (as defined by the delete_post meta capability), the "Move to Trash" button still displays. My expectation is that the "Move to Trash" button wouldn't display.

To reproduce

  1. Add the following code snippet to a mu-plugin:
add_filter(
	'map_meta_cap',
	function( $caps, $cap, $user_id, $args ) {
		if ( 'delete_post' === $cap ) {
			$caps = [ 'do_not_allow' ];
		}
		return $caps;
	},
	10,
	4
);
  1. Active the Classic Editor plugin and view an existing post. The 'Move to Trash' link isn't present:

image

  1. Deactivate the Classic Editor plugin and open the same post in the Block Editor. The 'Move to Trash' link is present, even though the REST API errors when you attempt to trash the post:

image

Suggested fix

Similar to the work done for #6361, we'll need to create some new wp:action-delete JSON Hyper Schema targetSchema response data for posts.

After this, the PostTrash component in @wordpress/editor will need to be updated to respect the presence of the wp:action-delete metadata.

@danielbachhuber danielbachhuber added [Type] Bug An existing feature does not function as intended [Feature] Document Settings Document settings experience Backwards Compatibility Issues or PRs that impact backwards compatability REST API Interaction Related to REST API labels Apr 4, 2019
@talldan
Copy link
Contributor

talldan commented Apr 5, 2019

@danielbachhuber, PR #12378 landed a canUser selector, which checks the allows header for specific REST resources:
https://github.com/WordPress/gutenberg/pull/12378/files#diff-2160e838a834521e1936ebd1908bd2b7R162

Could it be an option (bad pun) to use that when solving this issue?

I did a brief bit of testing in my console and it looks like canUser mostly works, but when calling it as a contributor and attempting to check if I had the ability to DELETE another user's post, a 403 (Forbidden) was returned by the endpoint and the selector returns undefined. That would have to be fixed.

@danielbachhuber
Copy link
Member Author

Could it be an option (bad pun) to use that when solving this issue?

Yep, I think that could work too, and would be preferred. Good suggestion!

@aduth aduth self-assigned this Apr 23, 2019
@mtias mtias added the [Status] In Progress Tracking issues with work in progress label Aug 30, 2020
@talldan
Copy link
Contributor

talldan commented Jul 21, 2021

Resolved in #23174

@talldan talldan closed this as completed Jul 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backwards Compatibility Issues or PRs that impact backwards compatability [Feature] Document Settings Document settings experience REST API Interaction Related to REST API [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants