-
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
Add __experimentalUseResourcePermissions #38785
Conversation
Size Change: +83 B (0%) Total Size: 1.24 MB
ℹ️ View Unchanged
|
We can use this hook to replace |
2be93c9
to
caa48a7
Compare
c86f561
to
31de2ce
Compare
I'd like to update this PR once #41139 lands |
5338287
to
c1914d2
Compare
I fixed the unit tests, rebased this on top of trunk, and added a refactor of |
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.
Unit tests are failing, but other than that I think this looks good 👍
commit c86f561 Author: Adam Zieliński <[email protected]> Date: Wed Feb 16 12:17:33 2022 +0100 Move the return type to TS commit eefec13 Author: Adam Zieliński <[email protected]> Date: Wed Feb 16 12:16:36 2022 +0100 Adjust TS types commit 12c7433 Author: Adam Zieliński <[email protected]> Date: Wed Feb 16 12:13:22 2022 +0100 Make useResourcePermissions return a tuple and make hasResolved the first item of the tuple forces the users to think about that variable and it's not easy to accidentally miss it. commit caa48a7 Author: Adam Zieliński <[email protected]> Date: Tue Feb 15 17:03:31 2022 +0100 Fix typo in the tests commit 33cdb4e Author: Adam Zieliński <[email protected]> Date: Mon Feb 14 15:05:09 2022 +0100 Expose __experimentalUseResourcePermissions as a public API commit cf30c5a Author: Adam Zieliński <[email protected]> Date: Mon Feb 14 14:58:42 2022 +0100 Distinguish between global and local resoluion commit 0db7bd2 Author: Adam Zieliński <[email protected]> Date: Mon Feb 14 14:42:36 2022 +0100 Propose useResourcePermissions hook commit 2d5e270 Author: Adam Zieliński <[email protected]> Date: Mon Feb 14 14:48:09 2022 +0100 Move the status computation inside the enriched selectors commit e7ac34e Author: Adam Zieliński <[email protected]> Date: Mon Feb 14 14:01:11 2022 +0100 Propose useEntityRecords
Co-authored-by: Kai Hao <[email protected]>
44dd755
to
c1da2e3
Compare
Originally introduced in Pull Request #38785
Added the Needs Dev Note label in case this needs a dev note (either individual or as part of a "misc" dev note) for WP 6.1 release. |
Dev note proposed at https://make.wordpress.org/core/?p=99829&preview=1&_ppp=2b1db975ea |
Description
This PR is a minimal subset of #38135 focused solely on the
useResourcePermissions
hook.The goal of these new APIs is to lower the barrier of entry for new contributors and make the life of existing contributors easier.
Example usage:
Before
After:
It returns a tuple and with
hasResolved
the first item so that it's intentionally too hard to overlook. Thank you @kevin940726 for this suggestion!See also how the combination of all proposed hooks makes the navigation block ~200 lines leaner.
Test plan
Other considerations
@gziolo said:
API resources are separate from entity records, we refer to them using a different set of identifiers.
You can either pass an id to this hook and get a create/update/delete permissions, or skip an id and get only the create permissions. Both are useful, e.g. in the Gutenberg codebase we sometimes do
canUser( 'update', 'settings' );
and other times we docanUser( 'delete', resource, postId )
.cc @kevin940726 @talldan @gziolo @draganescu @ellatrix @noisysocks @jsnajdr @getdave @Mamaduka @spencerfinnell