-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Editor: Display trash button only if user has delete capability #15131
Conversation
There appear to be some legitimate failures in the end-to-end suite, specifically for the template tests, in encountering a 404 error from one of its requests.
I'll plan to take a look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the tests have caught a problem related to the postType, see the comment below.
@talldan could you check to see if the issue is present here, and if so, elaborate on the instructions to reproduce it?
It looks like this only happens for drafts. My steps were:
- Create a draft as an admin and take note of the post id
- Login as a contributor and open up the editor
- In the console run
wp.data.select( 'core' ).canUser( 'delete', 'posts', postId );
using the postId from step 1. - Observe that the request returns a 403.
8
is a draft and 6
is published.
In real world usage this isn't much of an issue, a contributor can't load up one of these posts in the editor and the selector still returns a falsey.
return { | ||
isNew: isEditedPostNew(), | ||
postId: getCurrentPostId(), | ||
canUserTrash: !! postId && canUser( 'delete', 'posts', postId ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the postType be hard-coded here? I'm seeing a 404 from the request that the resolver makes when trying to edit a reusable block. That might also be the cause of the test failures.
IIRC, the rest_base
from the postType
is the value that should be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the postType be hard-coded here? I'm seeing a 404 from the request that the resolver makes when trying to edit a reusable block. That might also be the cause of the test failures.
IIRC, the
rest_base
from thepostType
is the value that should be used.
Yep, I think you're correct on both accounts (shouldn't be hard-coded, should leverage rest_base
).
I forget why I had never circled back here. Apologies for allowing your review to linger without response @talldan. I don't know if you recall what you were expecting, but are you thinking the problem is in how (a) a network error is logged (might be out of our control and default Chrome behavior) and (b) the selector returns |
Looking at the implementation, the conditional rendering probably doesn't need to happen in |
@aduth Struggling to remember all the details about this one, sorry! I supposed that the |
I think gutenberg/packages/core-data/src/resolvers.js Lines 159 to 173 in 56ff721
But I'd want to confirm:
|
This has been resolved by #23174 |
Fixes #14828
This pull request seeks to resolve an issue where the "Move to Trash" button is shown even if the user does not have the correct capabilities to be able to trash the post.
Implementation notes:
I followed the suggested implementation from @talldan at #14828 (comment) . I could not encounter the same issued described from the comment there with respect to a 403 (Forbidden) response. @talldan could you check to see if the issue is present here, and if so, elaborate on the instructions to reproduce it?
Testing Instructions:
Repeat Steps to Reproduce from #14828, verifying that the Move to Trash button is only shown when the user has capabilities to delete the post.