From 8b62f99379b0b4657781c5a6240ef2b2ec634318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petter=20Walb=C3=B8=20Johnsg=C3=A5rd?= Date: Tue, 13 Jul 2021 18:19:16 +0200 Subject: [PATCH 1/2] Template: Only show post template actions for users with correct permissions --- .../edit-post/src/components/sidebar/template/index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/edit-post/src/components/sidebar/template/index.js b/packages/edit-post/src/components/sidebar/template/index.js index 3308b3838366a1..d11a230962e7f1 100644 --- a/packages/edit-post/src/components/sidebar/template/index.js +++ b/packages/edit-post/src/components/sidebar/template/index.js @@ -34,6 +34,7 @@ export function TemplatePanel() { isViewable, template, supportsTemplateMode, + canUserEdit, } = useSelect( ( select ) => { const { isEditorPanelEnabled, @@ -45,7 +46,7 @@ export function TemplatePanel() { getEditorSettings, getCurrentPostType, } = select( editorStore ); - const { getPostType, getEntityRecords } = select( coreStore ); + const { getPostType, getEntityRecords, canUser } = select( coreStore ); const _isViewable = getPostType( getCurrentPostType() )?.viewable ?? false; const _supportsTemplateMode = @@ -72,6 +73,7 @@ export function TemplatePanel() { template: _supportsTemplateMode && getEditedPostTemplate(), isViewable: _isViewable, supportsTemplateMode: _supportsTemplateMode, + canUserEdit: canUser( 'update', 'settings' ), }; }, [] ); @@ -88,7 +90,8 @@ export function TemplatePanel() { if ( ! isEnabled || ! isViewable || - ( isEmpty( availableTemplates ) && ! supportsTemplateMode ) + ( isEmpty( availableTemplates ) && + ( ! supportsTemplateMode || ! canUserEdit ) ) ) { return null; } @@ -128,7 +131,7 @@ export function TemplatePanel() { label: templateName, } ) ) } /> - + { canUserEdit && } ); } From 16f2572286a656c93bed70733754defb4e3fadcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petter=20Walb=C3=B8=20Johnsg=C3=A5rd?= Date: Tue, 20 Jul 2021 19:12:47 +0200 Subject: [PATCH 2/2] Check if user can create templates --- .../edit-post/src/components/sidebar/template/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/edit-post/src/components/sidebar/template/index.js b/packages/edit-post/src/components/sidebar/template/index.js index d11a230962e7f1..d7b1a50a698176 100644 --- a/packages/edit-post/src/components/sidebar/template/index.js +++ b/packages/edit-post/src/components/sidebar/template/index.js @@ -34,7 +34,7 @@ export function TemplatePanel() { isViewable, template, supportsTemplateMode, - canUserEdit, + canUserCreate, } = useSelect( ( select ) => { const { isEditorPanelEnabled, @@ -73,7 +73,7 @@ export function TemplatePanel() { template: _supportsTemplateMode && getEditedPostTemplate(), isViewable: _isViewable, supportsTemplateMode: _supportsTemplateMode, - canUserEdit: canUser( 'update', 'settings' ), + canUserCreate: canUser( 'create', 'templates' ), }; }, [] ); @@ -91,7 +91,7 @@ export function TemplatePanel() { ! isEnabled || ! isViewable || ( isEmpty( availableTemplates ) && - ( ! supportsTemplateMode || ! canUserEdit ) ) + ( ! supportsTemplateMode || ! canUserCreate ) ) ) { return null; } @@ -131,7 +131,7 @@ export function TemplatePanel() { label: templateName, } ) ) } /> - { canUserEdit && } + { canUserCreate && } ); }