Opened 6 years ago
Closed 6 years ago
#45098 closed task (blessed) (fixed)
Introduce WP_REST_Block_Renderer_Controller and WP_REST_Blocks_Controller classes
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.0 | Priority: | normal |
Severity: | normal | Version: | |
Component: | REST API | Keywords: | has-patch has-unit-tests fixed-5.0 |
Focuses: | rest-api | Cc: |
Description (last modified by )
The WP_REST_Block_Renderer_Controller
and WP_REST_Blocks_Controller
classes currently exist in Gutenberg. They should be in WordPress core instead.
Related https://github.com/WordPress/gutenberg/issues/10655
Attachments (7)
Change History (41)
#4
@
6 years ago
Why is Gutenberg registering a REST route for every registered block type. It looks like this should be a single route. It appears to already be retrieving the block name from the request object.
This ticket was mentioned in Slack in #core-restapi by desrosj. View the logs.
6 years ago
#6
@
6 years ago
It appears that dynamic route registration was added in https://github.com/WordPress/gutenberg/pull/5602, more specifically 6557877.
$block->attributes
being dynamically passed to the properties
for each endpoint seems to be the reason behind that.
#7
@
6 years ago
While effort has stalled, part of the changes included in the following pull request had proposed the removal of the custom controller for reusable blocks:
https://github.com/WordPress/gutenberg/pull/7453
It's not entirely relevant to the main point of the pull request, but it had been prompted in the course of its development as a question: Is there really any reason we need custom endpoints, vs. simply using the existing /wp/v2/posts
endpoints (as reusable blocks are simply posts of type wp_block
)?
#8
@
6 years ago
@aduth That seems like a substantial architectural change to be making at this point. Do you see that landing in the next two days?
This ticket was mentioned in Slack in #core-restapi by desrosj. View the logs.
6 years ago
#11
@
6 years ago
To summarize conversations in Slack, @aduth is experimenting today with removing the /blocks
endpoint today in favor of using the pre-existing /posts
endpoint.
In case the results of that experiment are not promising, I have attached a patch for moving the WP_REST_Block_Renderer_Controller
and WP_REST_Blocks_Controller
classes over to core in their current state.
The tests are currently failing for the patch due to the absence of the wp_block
post type in core.
This ticket was mentioned in Slack in #core-restapi by desrosj. View the logs.
6 years ago
This ticket was mentioned in Slack in #core-restapi by desrosj. View the logs.
6 years ago
#15
@
6 years ago
In 45098.3.diff
, I've incorporated the changes in https://github.com/WordPress/gutenberg/pull/10751
Notably, we still need the wp_block
post type registered before 45098.3.diff
can land.
#18
@
6 years ago
Minor note about coding standards in [43804]:
- Missing space in post type label
name
:__( 'Blocks')
- Arrow not aligned for
capabilities
key (contrary to e.g.supports
orlabels
#19
@
6 years ago
In [43804] the following meta caps can be removed as they are mapped but not used due to the capabilities array when registering the post:
edit_published_blocks
delete_published_blocks
edit_others_blocks
delete_others_blocks
@pento As mentioned in our conversation in Slack, I am going to keep digging into this and think about custom roles that allow editing of pages but not posts. At the moment, the page editor can't edit shared blocks.
#20
@
6 years ago
I had to add those caps to the post registration, as edit_post
and delete_post
ultimately map to them.
I'm undecided about what to do with CPTs. I'm inclined to leave the behaviour as is, if a CPT chooses to allow reusable blocks, they need to take that into account in how they map caps to roles.
#21
@
6 years ago
Hi, there's a period missing at the end of "Sorry, you are not allowed to read blocks of this post"
wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php:96
#23
@
6 years ago
I'm inclined to leave the behaviour as is, if a CPT chooses to allow reusable blocks, they need to take that into account in how they map caps to roles.
Is there a reason to avoid adding the new *_blocks
caps via an upgrade routine in core?
Given WP allows custom roles, I think mapping the caps to a particular post type causes an unnecessary break to back-compat and is therefore doing it wrong.
The more I think about this, I'm more convinced that the plugin was doing it correctly. The meta caps can continue to use edit_post
, etc as that's the standard behaivour for attachments and other CPTs.
#24
@
6 years ago
I've found an error when an author or contributor attempts to reuse a block created by another user.
When inserting a block, the author can read others blocks and it inserts correctly.
When the author attempts to go back and edit their post, the editor attempts to fetch the blocks in the edit
context, causing any user without the edit_others_posts
permission to see the error "Block has been deleted or is unavailable."
To reproduce:
- Create two users,
user1
(any role) anduser2
(author role) - Log in as
user1
and create a reusable block - Log in as
user2
and create a post usinguser1
's block - The block renders correctly.
- Save the post and refresh the edit screen.
- The block fails to render and displays the error "Block has been deleted or is unavailable."
Note: This happens with the current version and in my proposed patch.
---
In 45098.5.diff, I've modified the permissions to use those as originally used by the feature plugin to account for custom roles and capabilities.
The meta cap changes are no longer required as the primitive caps exist and the edit_post
and other default meta caps map to the post types primitive.
This ticket was mentioned in Slack in #core-editor by peterwilsoncc. View the logs.
6 years ago
#26
@
6 years ago
As noted in https://github.com/WordPress/gutenberg/issues/11272 and https://github.com/WordPress/gutenberg/pull/11278, the post type labels need to be updated/extended.
#28
@
6 years ago
45098.7.diff is 45098.5.diff but with the roles upgrade routine modified to avoid updating the option 33 odd times.
- modified the permissions to use those as originally used by the feature plugin to account for custom roles and capabilities.
- The meta cap changes are no longer required as the primitive caps exist and the edit_post and other default meta caps map to the post types primitive.
#29
@
6 years ago
I've realised 45098.7.diff won't work, it doesn't re-instantiate $wp_roles
and even if it did, any classes storing them as a property won't get the new ones.
Currently blocked by this PR to Gutenberg and #45097.
Attaching a preliminary patch as a starting point for after those two blockers are resolved.