diff --git a/packages/editor/src/components/post-actions/actions.js b/packages/editor/src/components/post-actions/actions.js index 484b1e503c1e01..fe452578669724 100644 --- a/packages/editor/src/components/post-actions/actions.js +++ b/packages/editor/src/components/post-actions/actions.js @@ -230,7 +230,7 @@ const trashPostAction = { }, }; -function useCanUserEligibilityCheckPostType( capability, resource, action ) { +function useCanUserEligibilityCheckPostType( capability, postType, action ) { const registry = useRegistry(); return useMemo( () => ( { @@ -238,20 +238,22 @@ function useCanUserEligibilityCheckPostType( capability, resource, action ) { isEligible( item ) { return ( action.isEligible( item ) && - registry - .select( coreStore ) - .canUser( capability, resource, item.id ) + registry.select( coreStore ).canUser( capability, { + kind: 'postType', + name: postType, + id: item.id, + } ) ); }, } ), - [ action, registry, capability, resource ] + [ action, registry, capability, postType ] ); } -function useTrashPostAction( resource ) { +function useTrashPostAction( postType ) { return useCanUserEligibilityCheckPostType( 'delete', - resource, + postType, trashPostAction ); } @@ -347,10 +349,10 @@ const permanentlyDeletePostAction = { }, }; -function usePermanentlyDeletePostAction( resource ) { +function usePermanentlyDeletePostAction( postType ) { return useCanUserEligibilityCheckPostType( 'delete', - resource, + postType, permanentlyDeletePostAction ); } @@ -462,10 +464,10 @@ const restorePostAction = { }, }; -function useRestorePostAction( resource ) { +function useRestorePostAction( postType ) { return useCanUserEligibilityCheckPostType( 'update', - resource, + postType, restorePostAction ); } @@ -623,22 +625,21 @@ const renamePostAction = { }, }; -function useRenamePostAction( resource ) { +function useRenamePostAction( postType ) { return useCanUserEligibilityCheckPostType( 'update', - resource, + postType, renamePostAction ); } const useDuplicatePostAction = ( postType ) => { - const { userCanCreatePost } = useSelect( + const userCanCreatePost = useSelect( ( select ) => { - const { getPostType, canUser } = select( coreStore ); - const resource = getPostType( postType )?.rest_base || ''; - return { - userCanCreatePost: canUser( 'create', resource ), - }; + return select( coreStore ).canUser( 'create', { + kind: 'postType', + name: postType, + } ); }, [ postType ] ); @@ -863,7 +864,6 @@ export function usePostActions( { postType, onActionPerformed, context } ) { defaultActions, postTypeObject, userCanCreatePostType, - resource, cachedCanUserResolvers, } = useSelect( ( select ) => { @@ -871,12 +871,13 @@ export function usePostActions( { postType, onActionPerformed, context } ) { select( coreStore ); const { getEntityActions } = unlock( select( editorStore ) ); const _postTypeObject = getPostType( postType ); - const _resource = _postTypeObject?.rest_base || ''; return { postTypeObject: _postTypeObject, defaultActions: getEntityActions( 'postType', postType ), - userCanCreatePostType: canUser( 'create', _resource ), - resource: _resource, + userCanCreatePostType: canUser( 'create', { + kind: 'postType', + name: postType, + } ), cachedCanUserResolvers: getCachedResolvers()?.canUser, }; }, @@ -884,11 +885,11 @@ export function usePostActions( { postType, onActionPerformed, context } ) { ); const duplicatePostAction = useDuplicatePostAction( postType ); - const trashPostActionForPostType = useTrashPostAction( resource ); + const trashPostActionForPostType = useTrashPostAction( postType ); const permanentlyDeletePostActionForPostType = - usePermanentlyDeletePostAction( resource ); - const renamePostActionForPostType = useRenamePostAction( resource ); - const restorePostActionForPostType = useRestorePostAction( resource ); + usePermanentlyDeletePostAction( postType ); + const renamePostActionForPostType = useRenamePostAction( postType ); + const restorePostActionForPostType = useRestorePostAction( postType ); const isTemplateOrTemplatePart = [ TEMPLATE_POST_TYPE, TEMPLATE_PART_POST_TYPE,