Skip to content

Commit

Permalink
cehck for permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Dec 19, 2024
1 parent 511c60a commit a2d2596
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
5 changes: 5 additions & 0 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@ function Layout( {
kind: 'postType',
name: 'wp_template',
} );
const canDiscoverTemplate = canUser( 'read', {
kind: 'root',
name: 'site',
} );
const { isZoomOut } = unlock( select( blockEditorStore ) );
const { getEditorMode, getRenderingMode } = select( editorStore );
const isRenderingPostOnly = getRenderingMode() === 'post-only';
Expand All @@ -421,6 +425,7 @@ function Layout( {
supportsTemplateMode &&
isViewable &&
canViewTemplate &&
canDiscoverTemplate &&
! isEditingTemplate
? getTemplateId( currentPostType, currentPostId )
: null,
Expand Down
19 changes: 11 additions & 8 deletions packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export const ExperimentalEditorProvider = withRegistryProvider(
BlockEditorProviderComponent = ExperimentalBlockEditorProvider,
__unstableTemplate: template,
} ) => {
const hasTemplate = !! template;
const {
editorSettings,
selection,
Expand Down Expand Up @@ -193,19 +194,16 @@ export const ExperimentalEditorProvider = withRegistryProvider(
hasLoadedPostObject: _hasLoadedPostObject,
editorSettings: getEditorSettings(),
isReady: __unstableIsEditorReady(),
mode: template ? getRenderingMode() : 'post-only',
defaultMode:
template && postTypeObject?.default_rendering_mode
? postTypeObject?.default_rendering_mode
: 'post-only',
mode: getRenderingMode(),
defaultMode: postTypeObject?.default_rendering_mode,
selection: getEditorSelection(),
postTypeEntities:
post.type === 'wp_template'
? getEntitiesConfig( 'postType' )
: null,
};
},
[ template, post.type ]
[ post.type ]
);

const shouldRenderTemplate = !! template && mode !== 'post-only';
Expand Down Expand Up @@ -329,14 +327,19 @@ export const ExperimentalEditorProvider = withRegistryProvider(

// Sets the right rendering mode when loading the editor.
useEffect( () => {
setRenderingMode( defaultMode );
}, [ defaultMode, setRenderingMode ] );
setRenderingMode( hasTemplate ? defaultMode : 'post-only' );
}, [ hasTemplate, defaultMode, setRenderingMode ] );

useHideBlocksFromInserter( post.type, mode );

// Register the editor commands.
useCommands();

console.log( {
notRender: ! isReady || ! mode || ! hasLoadedPostObject,
settings: ! settings.isPreviewMode,
} );

if ( ! isReady || ! mode || ! hasLoadedPostObject ) {
return null;
}
Expand Down

0 comments on commit a2d2596

Please sign in to comment.