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

taxonomy-controls.js: Change REST context to "view" when fetching taxonomy terms. #43274

Merged

Conversation

drzraf
Copy link
Contributor

@drzraf drzraf commented Aug 16, 2022

What?

taxonomy-controls.js: Change REST context to "view" when fetching taxonomy terms.

Why?

When the query-loop block is used for a post type and a custom taxonomy exists but edit_terms permission isn't granted,
the following request is issued /wp-json/wp/v2/my_taxonomy?per_page=100&context=edit resulting in a 403 and keeping the
taxonomy selector to appear although it's just a read operation on terms.

How?

Changing getEntityRecords( 'taxonomy', slug, termsQuery ); to pass context=view

Testing Instructions

  1. Create a new, restricted taxonomy, associated with post having particular permissions:
                'capabilities'      => [
                    'manage_terms' => '',
                    'edit_terms'   => '',
                    'delete_terms' => '',
                    'assign_terms' => 'edit_posts',
                ],
  1. Open a Post or Page
  2. Insert a Query Loop
  3. The taxonomy does not appear without this change.

Somehow related

Not unlike #37368 or #33569 and related to #33003 / #37489

…onomy terms.

When the query-loop block is used for a post type and a custom taxonomy exists but `edit_terms` permission isn't granted,
the following request is issued `/wp-json/wp/v2/my_taxonomy?per_page=100&context=edit` resulting in a 403 and keeping the
taxonomy selector to appear although it's just a read operation on terms.
@drzraf drzraf requested a review from ajitbohra as a code owner August 16, 2022 13:31
@ntsekouras ntsekouras added [Type] Bug An existing feature does not function as intended [Block] Query Loop Affects the Query Loop Block labels Aug 16, 2022
Copy link
Contributor

@ntsekouras ntsekouras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you @drzraf! With green CI let's 🚢

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Aug 16, 2022
@github-actions
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @drzraf! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@ntsekouras ntsekouras merged commit 966d79c into WordPress:trunk Aug 16, 2022
@github-actions
Copy link

Congratulations on your first merged pull request, @drzraf! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts:

https://profiles.wordpress.org/me/profile/edit/

And if you don't have a WordPress.org account, you can create one on this page:

https://login.wordpress.org/register

Kudos!

@github-actions github-actions bot added this to the Gutenberg 14.0 milestone Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Query Loop Affects the Query Loop Block First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants