Skip to content

Block Directory: Use canUser() to determine install user permissions.#19830

Closed
StevenDufresne wants to merge 1 commit into
WordPress:masterfrom
StevenDufresne:try/block-directory-user-permissions
Closed

Block Directory: Use canUser() to determine install user permissions.#19830
StevenDufresne wants to merge 1 commit into
WordPress:masterfrom
StevenDufresne:try/block-directory-user-permissions

Conversation

@StevenDufresne
Copy link
Copy Markdown
Contributor

Description

The Block Directory package makes use of its own approach to check user permissions. This PR will align its approach to check permissions with the rest of the project by using canUser from core-data.

This PR does include a change to the canUser function to be able to handle REST endpoints that are experimental.

This PR has been opened early to initiate discussion.

To Do Before Merge

  • Add unit tests

How has this been tested?

There is currently no new test added. They need to be.

Types of changes

Considering this makes changes to a well used, shared function, this refactor has an impact larger than this package.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR. .

}

const path = id ? `/wp/v2/${ resource }/${ id }` : `/wp/v2/${ resource }`;
const apiPrefix = resource && resource.isExperimental ? '/__experimental/' : '/wp/v2/';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not so sure about the interface we've created for this.

A few thoughts occur to me:

  • Depending on how we define the endpoint, can __experimental be part of the resource ?
    • i.e. /wp/v2/__experimental/media
  • Could the function signature allow one to customize the namespace altogether, vs. "experimental" as being a specialized concept?
    • i.e. { endpoint: 'media', namespace: '/wp/__experimental' }
    • Aside: Is "endpoint" the correct verbiage here?
  • Is there any potential reuse or conflict from the changes or ideas proposed at Core Data: Add support for fetching permissions of custom actions #18956 ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can't speak to the history of how __experimental, which appears to be used in 3 different WP_REST_Controller extensions (widget-forms, block-directory & widget-areas) came to pass and the reasoning for not having them be part of the resource. I wouldn't be opposed to having to it but I don't know who would need to be looped in for context.

@StevenDufresne
Copy link
Copy Markdown
Contributor Author

Closed this. We'll be moving out of the 'experimental' state before this would be moved in, and at that point we will reassess user permissions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants