Skip to content
Merged
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
21 changes: 8 additions & 13 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,20 +323,15 @@ export default function Image( {
)
: null;

// Check edit permissions. When the media editor experiment is enabled,
// use getEntityRecordPermissions which checks via canUser API.
// Only check when the image is selected to avoid unnecessary API requests.
// Check edit permissions when the media editor experiment is enabled.
// Only check when imageRecord is available to avoid unnecessary API requests.
let canEdit = false;
if ( id && isSingleSelected && window?.__experimentalMediaEditor ) {
const { getEntityRecordPermissions } = unlock(
select( coreStore )
);
const permissions = getEntityRecordPermissions(
'postType',
'attachment',
id
);
canEdit = permissions?.update || false;
if ( imageRecord && window?.__experimentalMediaEditor ) {
canEdit = !! select( coreStore ).canUser( 'update', {
kind: 'postType',
name: 'attachment',
id,
} );
}

return {
Expand Down
Loading