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 terms are gone in 4.2 rc-1 #11335

Closed
slimmilkduds opened this issue Oct 31, 2018 · 24 comments · Fixed by #11395
Closed

Taxonomy terms are gone in 4.2 rc-1 #11335

slimmilkduds opened this issue Oct 31, 2018 · 24 comments · Fixed by #11395
Assignees
Labels
[Feature] Document Settings Document settings experience REST API Interaction Related to REST API [Type] Bug An existing feature does not function as intended
Milestone

Comments

@slimmilkduds
Copy link

Describe the bug
For non admin users all taxonomies are now empty in the editor. It throws one (403) Forbidden error per taxonomy.

This is an issue with this specific version of GB, reverting back to 4.1.1 and everything is back to normal

To Reproduce
Steps to reproduce the behavior:

  1. Open or create a new post
  2. Try to expand the taxonomy tabs (I have only tried custom Taxonomies)
  3. Nothing happens (except errors in console)

If these steps to reproduce doesn’t work I’ll add the console log tomorrow as I don’t have a computer available right now.

Desktop (please complete the following information):
Chrome

Additional context
GB 4.2 rc-1

@danielbachhuber danielbachhuber added the [Status] Needs More Info Follow-up required in order to be actionable. label Oct 31, 2018
@danielbachhuber
Copy link
Member

danielbachhuber commented Oct 31, 2018

Hi @slimmilkduds,

Thanks for the report. I wasn't able to reproduce this particular issue.

First, I registered a custom taxonomy called topic:

add_action( 'init', function() {
	register_taxonomy( 'topic', array( 'post' ), array(
		'hierarchical'      => false,
		'public'            => true,
		'show_in_nav_menus' => true,
		'show_ui'           => true,
		'show_admin_column' => false,
		'query_var'         => true,
		'rewrite'           => true,
		'capabilities'      => array(
			'manage_terms'  => 'edit_posts',
			'edit_terms'    => 'edit_posts',
			'delete_terms'  => 'edit_posts',
			'assign_terms'  => 'edit_posts',
		),
		'labels'            => array(
			'name'                       => __( 'Topics', 'YOUR-TEXTDOMAIN' ),
			'singular_name'              => _x( 'Topic', 'taxonomy general name', 'YOUR-TEXTDOMAIN' ),
		),
		'show_in_rest'      => true,
		'rest_base'         => 'topic',
		'rest_controller_class' => 'WP_REST_Terms_Controller',
	) );
});

Next, I signed in as a user with the author role and was able to observe the taxonomy's Post Settings Panel:

image

Can you share:

  1. The code you're using to register your custom taxonomy?
  2. Any modifications you've made to your roles?
  3. The contents of the Network response in your Chrome developer tools?
  4. Any plugins you're running?

@designsimply
Copy link
Member

Tested and confirmed for the Categories panel (not custom) using both the author role and the contributor role. (33s)

screen shot 2018-10-31 at 4 17 18 pm
Seen at http://alittletestblog.com/wp-admin/post.php?post=15405&action=edit running WordPress 4.9.8 and Gutenberg 4.2.0-rc.1 and logged in as the contributor role using Firefox 63.0 on macOS 10.13.6.

In the Network panel in Developer Tools, I see a 403 error for a call to http://alittletestblog.com/wp-json/wp/v2/categories?per_page=100&orderby=name&order=asc&context=edit&_locale=user that looks like this:

{"code":"rest_forbidden_context","message":"Sorry, you are not allowed to edit terms in this taxonomy.","data":{"status":403}}

screen shot 2018-10-31 at 4 02 07 pm
Seen at http://alittletestblog.com/wp-admin/post.php?post=15405&action=edit running WordPress 4.9.8 and Gutenberg 4.2.0-rc.1 and logged in as the contributor role using Firefox 63.0 on macOS 10.13.6.

In the Console panel, this error appears when on page load when I open a post for editing but I am not sure if it's related:

Unhandled promise rejection Error: "[object Object]"
wp-polyfill-ecmascript.min.2ae96136.js:2:29718

screen shot 2018-10-31 at 4 18 44 pm
Seen at http://alittletestblog.com/wp-admin/post.php?post=15405&action=edit running WordPress 4.9.8 and Gutenberg 4.2.0-rc.1 and logged in as the contributor role using Firefox 63.0 on macOS 10.13.6.

I tested using the contributor role on Firefox 63.0 on macOS 10.13.6 as well as the author role on Chrome 70.0.3538.77 on macOS 10.13.6. The alittletestblog.com site is hosted at WP Engine. Gutenberg 4.2.0-rc.1 was the only plugin active at the time of testing.

@designsimply designsimply added [Type] Bug An existing feature does not function as intended [Feature] Document Settings Document settings experience and removed [Status] Needs More Info Follow-up required in order to be actionable. labels Oct 31, 2018
@danielbachhuber danielbachhuber added this to the WordPress 5.0 milestone Oct 31, 2018
@danielbachhuber danielbachhuber added the REST API Interaction Related to REST API label Oct 31, 2018
@danielbachhuber
Copy link
Member

Tested and confirmed for the Categories panel (not custom) using both the author role and the contributor role.

I can confirm with Categories and Contributor. Looking further.

@danielbachhuber
Copy link
Member

The immediate problem is that this request URL has context=edit:

http://alittletestblog.com/wp-json/wp/v2/categories?per_page=100&orderby=name&order=asc&context=edit&_locale=user 

The request URL should have context=view, because authors and contributors don't have permission to edit terms. Tracking down where this was introduced.

@danielbachhuber danielbachhuber modified the milestones: WordPress 5.0, 4.2 Oct 31, 2018
@danielbachhuber
Copy link
Member

I believe the problem originated with #10089, specifically the change to use getEntityRecords( 'taxonomy', slug, DEFAULT_QUERY );, which then inadvertently means the request URL uses context=edit.

@adamsilverstein
Copy link
Member

Can the e2e tests be extended to run as multiple roles so we can catch these types of regressions?

@danielbachhuber
Copy link
Member

Can the e2e tests be extended to run as multiple roles so we can catch these types of regressions?

Yes. We could create a plugin that creates an author user on load and switches to it.


@youknowriad Just so it's stated, I think reverting #10089 is the wrong approach for this.

The data module will eventually need to handle context=view vs. context=edit. There are plenty of scenarios in the WordPress backend where a WordPress User only has read permission for an entity, and can't access the full shape of its contex=edit data. For instance, an Editor can assign authors to a Post but shouldn't be able to view their capabilities data. And, in this specific scenario, an Author should be able to assign Terms to a Post without editing them.

You might disagree with the underlying context abstraction but:

  1. It's what we have.
  2. It isn't going away or changing substantially.
  3. It's is probably what you'd end up designing if you had to solve the problem originally.

To revert #10089 instead of solving for context=view vs. context=edit in the data module is to simply re-introduce the bugs that it fixes and kick the problems further down the road.

cc @aduth

@youknowriad
Copy link
Contributor

The data module will eventually need to handle context=view vs. context=edit.

As discussed in DM. I think the data module shouldn't have to think about context at all. It's not abstraction on the REST API, it's an abstraction to retrieve WordPress Data and the REST API is an implementation detail.

We can't end up with entities in the store having different shapes depending on how they were fetched.

To revert #10089 instead of solving for context=view vs. context=edit in the data module is to simply re-introduce the bugs that it fixes and kick the problems further down the road.

What bugs we will be reintroducing? #10089 is supposed to be a refactoring. If it fixes a bug by inadvertance, we can still fix in the old implementation of the component.

@danielbachhuber
Copy link
Member

danielbachhuber commented Nov 1, 2018

I think the data module shouldn't have to think about context at all. It's not abstraction on the REST API, it's an abstraction to retrieve WordPress Data and the REST API is an implementation detail.

Ok. Where should the distinction between context=view and context=edit live then? The editor must be able to distinguish between the two, and handle both interchangably.

What bugs we will be reintroducing?

Maybe I misunderstood the implementation. I thought it was the path to eventually solving #10873 #7266 #7565

@youknowriad
Copy link
Contributor

Ok. Where should the distinction between context=view and context=edit live then? The editor must be able to distinguish between the two, and handle both.

Why it must?

@danielbachhuber
Copy link
Member

Why it must?

As I mentioned before:

There are plenty of scenarios in the WordPress backend where a WordPress User only has read permission for an entity, and can't access the full shape of its contex=edit data.

Is there an alternative implementation that you'd suggest?

@youknowriad
Copy link
Contributor

Is there an alternative implementation that you'd suggest?

Yes, always return all the fields the user can access to in the context=edit

@youknowriad
Copy link
Contributor

I created this trac ticket to discuss it https://core.trac.wordpress.org/ticket/45252

@youknowriad
Copy link
Contributor

youknowriad commented Nov 1, 2018

Actually, it could be a new "special" context if we don't want to break backwards compatibility.

context=all or something.

@danielbachhuber
Copy link
Member

Yes, always return all the fields the user can access to in the context=edit

But then you'd have two different shapes of data in the store?

Are you expecting that we'd change the implementation of context at this point in the release cycle?

@youknowriad
Copy link
Contributor

But then you'd have two different shapes of data in the store?

No, because the shape won't change for the same user.

Are you expecting that we'd change the implementation of context at this point in the release cycle?

I'm not. I already talked about it a long time and I know It's not going to change now. I do think context=all or something is not that impactful as it's just a new context but I'm more pragmatic than that and thinking of reverting the component to use apiFetch directly and call it a day.

@danielbachhuber
Copy link
Member

I'm more pragmatic than that and thinking of reverting the component to use apiFetch directly and call it a day.

How do we refresh the component then?

@youknowriad
Copy link
Contributor

How do we refresh the component then?

I don't know, a hook maybe (even if it's not my favorite option in term of extensibility). Why would you refresh it though?

@danielbachhuber
Copy link
Member

Why would you refresh it though?

Because of #7565 #7266?

@youknowriad
Copy link
Contributor

For #7565 even hacking with the Data Module seems like the wrong way to deal with those issues, it probably deserves its own component (Sidebar API or other).

#7266 These kind of issues is exactly what the data module is supposed to fix but it also highlights something I was talking about, if we do sepparate view and edit requests we can't automatically refresh the entities as well because we'd need a request on the other context as well.

@danielbachhuber
Copy link
Member

if we do sepparate view and edit requests we can't automatically refresh the entities as well because we'd need a request on the other context as well.

Good point.

@youknowriad
Copy link
Contributor

I'll wait a little bit, it looks like an important discussion, so I'm fine waiting for other opinions on how to solve these issues. I can revert at anytime.

@danielbachhuber
Copy link
Member

Per #core-restapi conversation today, @kadamwhite will create a PR that partially reverts the original PR.

@hughiemolloy
Copy link

I would just like to raise that I think the context=edit is still wrong. If you have permission to 'assign_terms' on the taxonomy you should not get a 403 when editing a post. The context should be used for the edited object not the entity record.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Document Settings Document settings experience REST API Interaction Related to REST API [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants