Skip to content

Commit

Permalink
Fix: Check permissions on duplicate pattern and template part actions. (
Browse files Browse the repository at this point in the history
#62757)

Co-authored-by: jorgefilipecosta <[email protected]>
Co-authored-by: ellatrix <[email protected]>
  • Loading branch information
3 people authored Jun 24, 2024
1 parent 7c19dfd commit 29b0a18
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/editor/src/components/post-actions/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1038,13 +1038,16 @@ export const duplicateTemplatePartAction = {
};

export function usePostActions( { postType, onActionPerformed, context } ) {
const { defaultActions, postTypeObject } = useSelect(
const { defaultActions, postTypeObject, userCanCreatePostType } = useSelect(
( select ) => {
const { getPostType } = select( coreStore );
const { getPostType, canUser } = select( coreStore );
const { getEntityActions } = unlock( select( editorStore ) );
const _postTypeObject = getPostType( postType );
const resource = _postTypeObject?.rest_base || '';
return {
postTypeObject: getPostType( postType ),
postTypeObject: _postTypeObject,
defaultActions: getEntityActions( 'postType', postType ),
userCanCreatePostType: canUser( 'create', resource ),
};
},
[ postType ]
Expand Down Expand Up @@ -1073,8 +1076,10 @@ export function usePostActions( { postType, onActionPerformed, context } ) {
! isPattern &&
duplicatePostAction
: false,
isTemplateOrTemplatePart && duplicateTemplatePartAction,
isPattern && duplicatePatternAction,
isTemplateOrTemplatePart &&
userCanCreatePostType &&
duplicateTemplatePartAction,
isPattern && userCanCreatePostType && duplicatePatternAction,
supportsTitle && renamePostAction,
isPattern && exportPatternAsJSONAction,
isTemplateOrTemplatePart ? resetTemplateAction : restorePostAction,
Expand Down Expand Up @@ -1141,6 +1146,7 @@ export function usePostActions( { postType, onActionPerformed, context } ) {
return actions;
}, [
defaultActions,
userCanCreatePostType,
isTemplateOrTemplatePart,
isPattern,
postTypeObject?.viewable,
Expand Down

0 comments on commit 29b0a18

Please sign in to comment.