Skip to content

Commit

Permalink
adds check for permissions on the manage menus link; removes rogue sh…
Browse files Browse the repository at this point in the history
…owManageActions
  • Loading branch information
draganescu committed Aug 30, 2022
1 parent 3449647 commit 754811f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
59 changes: 32 additions & 27 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ function Navigation( {
ref,
] );

const hasManagePermissions =
canUserCreateNavigationMenu || canUserUpdateNavigationMenu;
const navigationSelectorRef = useRef();
const [ shouldFocusNavigationSelector, setShouldFocusNavigationSelector ] =
useState( false );
Expand Down Expand Up @@ -628,16 +630,17 @@ function Navigation( {
onCreateNew={ () => createNavigationMenu( '', [] ) }
/* translators: %s: The name of a menu. */
actionLabel={ __( "Switch to '%s'" ) }
showManageActions
/>
<Button
variant="link"
href={ addQueryArgs( 'edit.php', {
post_type: 'wp_navigation',
} ) }
>
{ __( 'Manage menus' ) }
</Button>
{ hasManagePermissions && (
<Button
variant="link"
href={ addQueryArgs( 'edit.php', {
post_type: 'wp_navigation',
} ) }
>
{ __( 'Manage menus' ) }
</Button>
) }
</PanelBody>
</InspectorControls>
{ stylingInspectorControls }
Expand Down Expand Up @@ -702,16 +705,17 @@ function Navigation( {
onCreateNew={ () => createNavigationMenu( '', [] ) }
/* translators: %s: The name of a menu. */
actionLabel={ __( "Switch to '%s'" ) }
showManageActions
/>
<Button
variant="link"
href={ addQueryArgs( 'edit.php', {
post_type: 'wp_navigation',
} ) }
>
{ __( 'Manage menus' ) }
</Button>
{ hasManagePermissions && (
<Button
variant="link"
href={ addQueryArgs( 'edit.php', {
post_type: 'wp_navigation',
} ) }
>
{ __( 'Manage menus' ) }
</Button>
) }
</PanelBody>
</InspectorControls>
<Warning>
Expand Down Expand Up @@ -810,16 +814,17 @@ function Navigation( {
onCreateNew={ () => createNavigationMenu( '', [] ) }
/* translators: %s: The name of a menu. */
actionLabel={ __( "Switch to '%s'" ) }
showManageActions
/>
<Button
variant="link"
href={ addQueryArgs( 'edit.php', {
post_type: 'wp_navigation',
} ) }
>
{ __( 'Manage menus' ) }
</Button>
{ hasManagePermissions && (
<Button
variant="link"
href={ addQueryArgs( 'edit.php', {
post_type: 'wp_navigation',
} ) }
>
{ __( 'Manage menus' ) }
</Button>
) }
</PanelBody>
</InspectorControls>
{ stylingInspectorControls }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ function NavigationMenuSelector(
onSelectNavigationMenu,
onSelectClassicMenu,
onCreateNew,
showManageActions = false,
actionLabel,
toggleProps = {},
},
Expand Down Expand Up @@ -98,7 +97,7 @@ function NavigationMenuSelector(
const showSelectMenus =
( ( canSwitchNavigationMenu || canUserCreateNavigationMenu ) &&
( hasNavigationMenus || hasClassicMenus ) ) ||
( hasManagePermissions && showManageActions );
hasManagePermissions;

if ( ! showSelectMenus ) {
return null;
Expand Down Expand Up @@ -150,7 +149,7 @@ function NavigationMenuSelector(
</MenuGroup>
) }

{ showManageActions && hasManagePermissions && (
{ hasManagePermissions && (
<MenuGroup label={ __( 'Tools' ) }>
{ canUserCreateNavigationMenu && (
<MenuItem onClick={ onCreateNew }>
Expand Down

0 comments on commit 754811f

Please sign in to comment.