Skip to content

Commit

Permalink
Cherry pick Fix: Check permissions on duplicate pattern and template …
Browse files Browse the repository at this point in the history
…part actions. #62757
  • Loading branch information
jorgefilipecosta authored and ellatrix committed Jun 25, 2024
1 parent 411d705 commit 0e03332
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/editor/src/components/post-actions/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1075,15 +1075,22 @@ export const duplicateTemplatePartAction = {
};

export function usePostActions( { postType, onActionPerformed, context } ) {
const { postTypeObject, resource, cachedCanUserResolvers } = useSelect(
const {
postTypeObject,
resource,
cachedCanUserResolvers,
userCanCreatePostType,
} = useSelect(
( select ) => {
const { getPostType, getCachedResolvers } = select( coreStore );
const { getPostType, getCachedResolvers, canUser } =
select( coreStore );
const _postTypeObject = getPostType( postType );
const _resource = _postTypeObject?.rest_base || '';
return {
postTypeObject: _postTypeObject,
resource: _resource,
cachedCanUserResolvers: getCachedResolvers()?.canUser,
userCanCreatePostType: canUser( 'create', _resource ),
};
},
[ postType ]
Expand Down Expand Up @@ -1115,8 +1122,10 @@ export function usePostActions( { postType, onActionPerformed, context } ) {
! isPattern &&
duplicatePostAction
: false,
isTemplateOrTemplatePart && duplicateTemplatePartAction,
isPattern && duplicatePatternAction,
isTemplateOrTemplatePart &&
userCanCreatePostType &&
duplicateTemplatePartAction,
isPattern && userCanCreatePostType && duplicatePatternAction,
supportsTitle && renamePostActionForPostType,
isPattern && exportPatternAsJSONAction,
isTemplateOrTemplatePart
Expand Down Expand Up @@ -1199,6 +1208,7 @@ export function usePostActions( { postType, onActionPerformed, context } ) {
supportsRevisions,
supportsTitle,
context,
userCanCreatePostType,
cachedCanUserResolvers,
] );
}

0 comments on commit 0e03332

Please sign in to comment.