Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template Part: Hide Advanced panel for non-admin users #64721

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export function TemplatePartAdvancedControls( {
} }
onFocus={ ( event ) => event.target.select() }
/>

<SelectControl
__next40pxDefaultSize
__nextHasNoMarginBottom
Expand Down
22 changes: 12 additions & 10 deletions packages/block-library/src/template-part/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,18 @@ export default function TemplatePartEdit( {
</ToolbarButton>
</BlockControls>
) }
<InspectorControls group="advanced">
<TemplatePartAdvancedControls
tagName={ tagName }
setAttributes={ setAttributes }
isEntityAvailable={ isEntityAvailable }
templatePartId={ templatePartId }
defaultWrapper={ areaObject.tagName }
hasInnerBlocks={ hasInnerBlocks }
/>
</InspectorControls>
{ canUserEdit && (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's something that feels off to me here: why are we checking the user rights to edit template part when these changes won't be made in the template part object? they will be made in the container (whether that is a post or template is unknown here)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Come to think of it, you are right.

Does this mean that we need additional code like the following to check if the template (not the template part) can be edited?

const canUserEditTemplates = select( coreStore ).canUser( 'create', {
	kind: 'postType',
	name: 'wp_template',
} );

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really IMO, it feels like a symptom of something else. Do you know why the block is selectable in the first place here? I mean if you can't edit a template, why should you be able to select a block within that template?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why the block is selectable in the first place here?

From what I can see, #60010 makes it possible to select template parts in the page content focus mode.

Perhaps should we make some changes to the code changed in #60010 to prevent non-admin users from selecting template parts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps should we make some changes to the code changed in #60010 to prevent non-admin users from selecting template parts?

That would be a good intermediary step but to be honest I never liked the fact that you are able to select template parts in "page focus mode", it feels contradictory to me and I'm not sure about the UX improvement. cc @noisysocks @richtabor

<InspectorControls group="advanced">
<TemplatePartAdvancedControls
tagName={ tagName }
setAttributes={ setAttributes }
isEntityAvailable={ isEntityAvailable }
templatePartId={ templatePartId }
defaultWrapper={ areaObject.tagName }
hasInnerBlocks={ hasInnerBlocks }
/>
</InspectorControls>
) }
{ isPlaceholder && (
<TagName { ...blockProps }>
<TemplatePartPlaceholder
Expand Down
Loading