Skip to content

Commit

Permalink
Return false when entity arg is malformed
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Jul 10, 2024
1 parent 19e01ea commit e900d9a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/reference-guides/data/data-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ _Parameters_

_Returns_

- `boolean | undefined | null`: Whether or not the user can perform the action, or `undefined` if the OPTIONS request is still being made.
- `boolean | undefined`: Whether or not the user can perform the action, or `undefined` if the OPTIONS request is still being made.

### canUserEditEntityRecord

Expand All @@ -42,7 +42,7 @@ _Parameters_

_Returns_

- `boolean | undefined | null`: Whether or not the user can edit, or `undefined` if the OPTIONS request is still being made.
- `boolean | undefined`: Whether or not the user can edit, or `undefined` if the OPTIONS request is still being made.

### getAuthors

Expand Down
4 changes: 2 additions & 2 deletions packages/core-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ _Parameters_

_Returns_

- `boolean | undefined | null`: Whether or not the user can perform the action, or `undefined` if the OPTIONS request is still being made.
- `boolean | undefined`: Whether or not the user can perform the action, or `undefined` if the OPTIONS request is still being made.

### canUserEditEntityRecord

Expand All @@ -363,7 +363,7 @@ _Parameters_

_Returns_

- `boolean | undefined | null`: Whether or not the user can edit, or `undefined` if the OPTIONS request is still being made.
- `boolean | undefined`: Whether or not the user can edit, or `undefined` if the OPTIONS request is still being made.

### getAuthors

Expand Down
6 changes: 3 additions & 3 deletions packages/core-data/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1147,10 +1147,10 @@ export function canUser(
action: string,
resource: string | Record< string, any >,
id?: EntityRecordKey
): boolean | undefined | null {
): boolean | undefined {
const isEntity = typeof resource === 'object';
if ( isEntity && ( ! resource.kind || ! resource.name ) ) {
return null;
return false;
}

const key = (
Expand Down Expand Up @@ -1184,7 +1184,7 @@ export function canUserEditEntityRecord(
kind: string,
name: string,
recordId: EntityRecordKey
): boolean | undefined | null {
): boolean | undefined {
return canUser( state, 'update', { kind, name, id: recordId } );
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core-data/src/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,8 @@ describe( 'canUser', () => {
const state = deepFreeze( {
userPermissions: {},
} );
expect( canUser( state, 'create', { name: 'media' } ) ).toBe( null );
expect( canUser( state, 'create', { kind: 'root' } ) ).toBe( null );
expect( canUser( state, 'create', { name: 'media' } ) ).toBe( false );
expect( canUser( state, 'create', { kind: 'root' } ) ).toBe( false );
} );

it( 'returns whether an action can be performed', () => {
Expand Down

0 comments on commit e900d9a

Please sign in to comment.