Skip to content

Commit

Permalink
Core data: batch receiveUserPermission (#63201)
Browse files Browse the repository at this point in the history
Co-authored-by: ellatrix <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
  • Loading branch information
3 people committed Jul 8, 2024
1 parent ab659ae commit cfea061
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,14 @@ export const canUser =
permissions[ actionName ] = allowedMethods.includes( methodName );
}

for ( const action of retrievedActions ) {
dispatch.receiveUserPermission(
`${ action }/${ resourcePath }`,
permissions[ action ]
);
}
registry.batch( () => {
for ( const action of retrievedActions ) {
dispatch.receiveUserPermission(
`${ action }/${ resourcePath }`,
permissions[ action ]
);
}
} );
};

/**
Expand Down
4 changes: 4 additions & 0 deletions packages/core-data/src/test/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ describe( 'canUser', () => {
select: jest.fn( () => ( {
hasStartedResolution: () => false,
} ) ),
batch: ( callback ) => callback(),
};
triggerFetch.mockReset();
} );
Expand Down Expand Up @@ -388,6 +389,7 @@ describe( 'canUser', () => {
} );

registry = {
...registry,
select: () => ( {
hasStartedResolution: ( _, [ action ] ) => action === 'read',
} ),
Expand Down Expand Up @@ -418,6 +420,7 @@ describe( 'canUser', () => {
} );

registry = {
...registry,
select: () => ( {
hasStartedResolution: ( _, [ action ] ) => action === 'read',
} ),
Expand Down Expand Up @@ -456,6 +459,7 @@ describe( 'canUser', () => {
} );

registry = {
...registry,
select: () => ( {
hasStartedResolution: ( _, [ action ] ) => action === 'create',
} ),
Expand Down

0 comments on commit cfea061

Please sign in to comment.