Skip to content

Commit

Permalink
Template Part: Fix 'can user edit' check (#64137)
Browse files Browse the repository at this point in the history
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: tyxla <[email protected]>
  • Loading branch information
3 people authored Jul 31, 2024
1 parent 15db088 commit 08e6960
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/block-library/src/template-part/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default function TemplatePartEdit( {
area,
onNavigateToEntityRecord,
title,
canEditTemplate,
canUserEdit,
} = useSelect(
( select ) => {
const { getEditedEntityRecord, hasFinishedResolution } =
Expand All @@ -151,10 +151,13 @@ export default function TemplatePartEdit( {
)
: false;

const _canEditTemplate = select( coreStore ).canUser( 'create', {
kind: 'postType',
name: 'wp_template_part',
} );
const _canUserEdit = hasResolvedEntity
? select( coreStore ).canUser( 'update', {
kind: 'postType',
name: 'wp_template_part',
id: templatePartId,
} )
: false;

return {
hasInnerBlocks: getBlockCount( clientId ) > 0,
Expand All @@ -167,7 +170,7 @@ export default function TemplatePartEdit( {
onNavigateToEntityRecord:
getSettings().onNavigateToEntityRecord,
title: entityRecord?.title,
canEditTemplate: !! _canEditTemplate,
canUserEdit: !! _canUserEdit,
};
},
[ templatePartId, attributes.area, clientId ]
Expand Down Expand Up @@ -237,7 +240,7 @@ export default function TemplatePartEdit( {
<RecursionProvider uniqueId={ templatePartId }>
{ isEntityAvailable &&
onNavigateToEntityRecord &&
canEditTemplate && (
canUserEdit && (
<BlockControls group="other">
<ToolbarButton
onClick={ () =>
Expand Down

1 comment on commit 08e6960

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 08e6960.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/10179755027
📝 Reported issues:

Please sign in to comment.