WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.46k stars 4.18k forks source link

canUser select does not work with the global styles post type. #63438

Open jorgefilipecosta opened 3 months ago

jorgefilipecosta commented 3 months ago

Description

When using the canUser selector against global styles the selector always returns false even for admin users with the capability.

Step-by-step reproduction instructions

Screenshots, screen recording, code snippet

No response

Environment info

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

Mamaduka commented 3 months ago

@jorgefilipecosta, it turns out we made a couple of wrong assumptions.

You can only check capabilities for individual global styles entities - canUser( 'read', { kind: 'root', name: 'globalStyles', id: 41 } );.

The id value can be obtained using select( 'core' ).__experimentalGetCurrentGlobalStylesId(), though I'm unsure if it works for low capability users.

jorgefilipecosta commented 3 months ago

Thank you for researching this @Mamaduka. I think we can close this issue. I used your findings to propose a simplification at https://github.com/WordPress/gutenberg/pull/63812.