-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Block Directory REST API cleanup #17669
Conversation
…ck name is unavailable.
…irect `api.wordpress.org` request.
…ng duplicate requests.
… them back directly.
…unction. This needs to be expanded upon to handle more scenarios.
…PI request in order to find the block plugin.
…slug` not changing in preference to using `install_plugin_install_status()` which requires an API call.
…cks that check the finer-grained permissions in addition to the broad permission capabilities.
…e stored and do not required prompting.
…as we're only passing one route per call.
This covers some parts of #17440 |
…REST_Controller::get_items_permissions_check()`
…ck name is unavailable.
…irect `api.wordpress.org` request.
…ng duplicate requests.
… them back directly.
…unction. This needs to be expanded upon to handle more scenarios.
…slug` not changing in preference to using `install_plugin_install_status()` which requires an API call.
…cks that check the finer-grained permissions in addition to the broad permission capabilities.
…e stored and do not required prompting.
…as we're only passing one route per call.
…REST_Controller::get_items_permissions_check()`
Disable the linter for permissions check.
So is the only difference between querying for blocks vs plugins from .org the use of the of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not all that familiar with the REST API, and I haven't tested anything, but I left a few minor comments.
/* phpcs:enable */ | ||
|
||
/** | ||
* Checks whether a given request has permission to install and activate plugins. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description of this function is the same as get_items_permissions_check
. Would be great to detail why/how they're different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference is very minimal, and I'm not sure how best to explain, other than the code..
It's possible to a user to be able to "get" plugins and potentially be able to install/activate them, but it's only once they actually attempt to install a singular item that the true capability checks can be processed.
*/ | ||
public function permissions_check() { | ||
public function get_items_permissions_check( $request ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the code, it seems like this permissions check is now only used for retrieving a list of plugins, so I wondered whether the current_user_can( 'activate_plugins' )
check still relevant in this function?
189a904
to
f3e2d0a
Compare
Chatting with @kadamwhite, ideally we'd separate plugin installation/deletion to a separate bare-bones plugins endpoint instead of including it with the block directory endpoints. I'll try and PR that separately. |
Would it be okay to add that to the Block Directory backlog and return to it in another PR? There are some updates in this PR that will be immediately useful and since this feature is still experimental we are keen on iterating quickly. The risk is that this PR grows in scope and gets stale. Also, if we are ok with that, is there anything else that needs addressing before we can merge? |
“Immediately useful” after sitting stale for three months? Feels like something which should be addressed now as so often these types of things get backlogged and never addressed, then we end up shipping code which doesn’t mirror other core behavior. |
To be clear, this PR updates already shipped code. For example, we have already shipped a bunch of invalid php in the form of fatal So with that said, @chrisvanpatten, what do we need to do to get this over the line? |
For the exact reasons you mention, REST API code that is merged should be in a shape that at least generally follows WordPress core patterns. There is a larger refactor that I mentioned in my comment, but that doesn't need to be completed right now. IMO, the controllers should be update to use |
Okay sounds good. We'll get that change in. |
Closing this out since it has been superseded by #22454 which contains these changed. |
This draws on WordPress#17669 and tellyworth/wordpress-develop#1. It fixes many small issues with the block directory controller, and adds unit tests.
Description
Fixes #17664, fixes #17535.
This PR contains a lot of changes, which is my first pass at the Block Directory rest api endpoints.
In short, the major components of this include:
permission_callback
for each endpoint that calls the more fine-grained capabilities$plugin_slug
as the unique identifier internally, removing the need for multiple WordPress.org API callsplugins_api()
where possibleThere's a TODO remaining in the content where a change needs to be made on api.wordpress.org before the code can be altered.
How has this been tested?
Types of changes
This change is only code cleanup and bug fixes.
Checklist: