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

core-data: Fix canUser allowed methods handling #63615

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ describe( 'useResourcePermissions', () => {
registry.register( coreDataStore );

triggerFetch.mockImplementation( () => ( {
headers: {
get: () => ( {
allow: 'POST',
} ),
},
headers: new Headers( {
allow: 'POST',
} ),
Comment on lines +27 to +29
Copy link
Member Author

Choose a reason for hiding this comment

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

Headers is the right interface for dealing with response headers. Just using the constructor adds the necessary functionality, including proper support for .get().

} ) );
} );

Expand Down
3 changes: 1 addition & 2 deletions packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,7 @@ export const canUser =
// Optional chaining operator is used here because the API requests don't
// return the expected result in the native version. Instead, API requests
// only return the result, without including response properties like the headers.
const allowHeader = response.headers?.get( 'allow' );
const allowedMethods = allowHeader?.allow || allowHeader || '';
const allowedMethods = response.headers?.get( 'allow' ) || '';
Copy link
Member Author

Choose a reason for hiding this comment

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

Cleaning up as the .allow access was not necessary.


const permissions = {};
const methods = {
Expand Down
Loading