Skip to content

Commit

Permalink
Post Editor: Avoid 403 errors for users with low permissions (#42413)
Browse files Browse the repository at this point in the history
* Post Editor: Avoid 403 errors for low capability users
* Use undefined
  • Loading branch information
Mamaduka committed Jul 18, 2022
1 parent f233a32 commit 9f0e6be
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/compat/wordpress-6.1/edit-form-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
function gutenberg_preload_template_permissions( $preload_paths, $context ) {
if ( ! empty( $context->post ) ) {
$preload_paths[] = array( rest_get_route_for_post_type_items( 'wp_template' ), 'OPTIONS' );
$preload_paths[] = array( '/wp/v2/settings', 'OPTIONS' );
}

return $preload_paths;
Expand Down
5 changes: 3 additions & 2 deletions packages/edit-post/src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function Editor( {
getEditedPostTemplate,
getHiddenBlockTypes,
} = select( editPostStore );
const { getEntityRecord, getPostType, getEntityRecords } =
const { getEntityRecord, getPostType, getEntityRecords, canUser } =
select( coreStore );
const { getEditorSettings } = select( editorStore );
const { getBlockTypes } = select( blocksStore );
Expand All @@ -78,6 +78,7 @@ function Editor( {
const supportsTemplateMode =
getEditorSettings().supportsTemplateMode;
const isViewable = getPostType( postType )?.viewable ?? false;
const canEditTemplate = canUser( 'create', 'templates' );

return {
hasFixedToolbar:
Expand All @@ -96,7 +97,7 @@ function Editor( {
keepCaretInsideBlock: isFeatureActive( 'keepCaretInsideBlock' ),
isTemplateMode: isEditingTemplate(),
template:
supportsTemplateMode && isViewable
supportsTemplateMode && isViewable && canEditTemplate
? getEditedPostTemplate()
: null,
post: postObject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ function useBlockEditorSettings( settings, hasTemplate ) {
const isWeb = Platform.OS === 'web';
const { canUser, getEntityRecord } = select( coreStore );

const siteSettings = getEntityRecord( 'root', 'site' );
const siteSettings = canUser( 'read', 'settings' )
? getEntityRecord( 'root', 'site' )
: undefined;

return {
canUseUnfilteredHTML: canUserUseUnfilteredHTML(),
Expand Down

0 comments on commit 9f0e6be

Please sign in to comment.