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

Site editor related links are exposed to non-admin users #61419

Closed
t-hamano opened this issue May 7, 2024 · 3 comments · Fixed by #61444
Closed

Site editor related links are exposed to non-admin users #61419

t-hamano opened this issue May 7, 2024 · 3 comments · Fixed by #61444
Assignees
Labels
[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Status] In Progress Tracking issues with work in progress [Type] Regression Related to a regression in the latest release

Comments

@t-hamano
Copy link
Contributor

t-hamano commented May 7, 2024

Description

When generating a link to a page in the site editor, it is determined whether the site editor can be accessed, mainly through the following code, and the link destination is changed depending on the result.

const url = useSelect( ( select ) => {
const { canUser } = select( coreStore );
const defaultUrl = addQueryArgs( 'edit.php', {
post_type: 'wp_block',
} );
const patternsUrl = addQueryArgs( 'site-editor.php', {
path: '/patterns',
} );
// The site editor and templates both check whether the user has
// edit_theme_options capabilities. We can leverage that here and not
// display the manage patterns link if the user can't access it.
return canUser( 'read', 'templates' ) ? patternsUrl : defaultUrl;

However, in the latest version of Gutenberg, canUser( 'read', 'templates' ) returns true for non-administrator users, and they are now considered to have "access to the site editor." As a result, when you run the command, you will receive an error indicating that access is not possible.

Step-by-step reproduction instructions

  • Create a user with the Editor role and log in as that user.
  • Open the post editor.
  • When you start the command, you should see items like Styles, Templates, etc.
  • If you click on those items, you should see an error.
  • The "Manage all patterns" link should give you a similar error.

Screenshots, screen recording, code snippet

74b016a86c8e6130d47a3af5309f25e7.mp4

Environment info

No response

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

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") labels May 7, 2024
@t-hamano
Copy link
Contributor Author

t-hamano commented May 7, 2024

I think this issue is caused by #60317.

@bacoords
Copy link
Contributor

bacoords commented May 7, 2024

Thanks for confirming as I was seeing this in my PRs.

That said, I would also like to throw out the idea that if the ability for editors to read templates were determined not be a regression, perhaps the way we check for a user's ability to access the Site Editor could change.

Perhaps outside the scope of this, but it could be cleaner if we had a core-data function that more closely corresponded to current_user_can() or something similar that we could directly pass user capabilities (i.e. 'edit_theme_options') to.

@fabiankaegy
Copy link
Member

Great find. And yes that seems like my PR introduced this. I would say though that instead of changing the access levels back the way to fix this is using the canUser( 'create', 'templates' ) check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Status] In Progress Tracking issues with work in progress [Type] Regression Related to a regression in the latest release
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants