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

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

Closed
jorgefilipecosta opened this issue Jul 11, 2024 · 2 comments
Closed
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json REST API Interaction Related to REST API [Type] Bug An existing feature does not function as intended

Comments

@jorgefilipecosta
Copy link
Member

jorgefilipecosta commented Jul 11, 2024

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

  • Load the site editor with an admin user, and verify you can change global styles.
  • Paste the following code in the browser console: await wp.data.resolveSelect('core').canUser('read', {kind: 'postType', name: 'wp_global_styles' });, verify it returns false when it should be true.
  • Paste the follow code in browser console: await wp.data.resolveSelect('core').canUser( 'read', 'global_styles' );, verify it returns false when it should be true.

Screenshots, screen recording, code snippet

No response

Environment info

  • Gutenberg trunk with the latest WordPress trunk, also in WordPress trunk without the plugin.

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

@jorgefilipecosta jorgefilipecosta added the [Type] Bug An existing feature does not function as intended label Jul 11, 2024
@Mamaduka Mamaduka added REST API Interaction Related to REST API Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Jul 11, 2024
@Mamaduka
Copy link
Member

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

  • The global styles entity is registered with kind: 'root', name: 'globalStyles', not as a post type.
  • It doesn't have a route for list items, with means the following selectors won't work - select( 'core' ).canUser( 'read', { kind: 'root', name: 'globalStyles' } ) and select( 'core' ).getEntityRecords( 'root', 'globalStyles' ).

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
Copy link
Member Author

Thank you for researching this @Mamaduka. I think we can close this issue. I used your findings to propose a simplification at #63812.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json REST API Interaction Related to REST API [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

3 participants