-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Core Data: Introduce entity-aware permission selector #63292
Conversation
Size Change: +349 B (+0.02%) Total Size: 1.76 MB
ℹ️ View Unchanged
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
} ); | ||
} catch ( error ) { | ||
// Do nothing if our OPTIONS request comes back with an API error (4xx or | ||
// 5xx). The previously determined isAllowed value will remain in the store. |
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 don't think this is right. It should indicate that the user has no permissions for the record I believe.
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 found this comment in the original PR: https://github.com/WordPress/gutenberg/pull/12378/files#r243442316. This is similar to what we do in other resolvers - not touching the store when the request fails.
Could this functionality be integrated into There's also a request that |
Avoiding yet another public selector deprecation is probably preferable. We can change // new
canUser( 'update', { 'postType', 'wp_block', 5 } );
// legacy
canUser( 'update, 'blocks', 5 );
I'll try to leave a comment in the discussion, but I don't see it as a blocker for this PR, more like something we can support in the future. |
I would be cautious about objects in selector arguments, there might be impacts on memoization of selectors and things like that. Personally I don't like that pattern much other than for well defined objects like "query". |
Then maybe we can invent some syntax like @Mamaduka says about the user capabilities:
My idea is to keep some space for the possibility that we use canUser( 'activate_plugins', 'on:this:site' ) How would we specify the "object", instead of the |
While I generally agree, how likely is it that we would have to memoize a selector that returns |
Good point, maybe not :). I was just raising it for consideration.
So yeah, if the object argument addresses all the needs without downsides, that's fine by me too. |
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.
Thanks for working on this one!
Haven't had a chance to review the code, but using "permission" seems off to me. In the WordPress core, users can have a role and each role determines their capabilities. With that in mind, I prefer capability to permission. To me, permission indicates file/folder permissions on the server, rather than having access to read data or perform certain types of updates. An with that in mind, I'd expect this new API to be consistent with the terms and tech slang that WordPress has already established.
The alternative PR is ready for review - #63322. |
It was superseded by #63322. |
What?
Resolves #43751.
PR introduces a new entity-aware user permission selector for the
core-data
store. I've also replaced the usage ofcanUserEditEntityRecord
in the code base.Why?
canUser
- only supports resources in thewp/v2
namespace. Additionally, you must know the final REST API path. Typically, however, only an entity's kind and name are known.canUserEntityRecord
- is limited to only the edit action check. It was a wrapper forcanUser
and only supported thewp/v2
namespace, which hasn't been required since WP 5.9.The new selector also opens up the possibility to leverage "target hints" and bulk fetch permissions data for DataViews.
Notes
canUser
.canUser
-cacheKey = isAllowed
.Testing Instructions
Basic Testing
Testing canUserEntityRecord changes
Testing Instructions for Keyboard
Same.