-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Alternative: restrict Navigation permissions and show UI warning if c…
…annot create (#37454) * Test for publish abtility and display warning * Update creation of Nav posts to require admin perms * Only show menu creation option if user has permission to create * Move permission selectors to hook * Show warning if unable to create Navigation Menus * Copy changes from Core patch See https://github.com/WordPress/wordpress-develop/pull/2056/files * Only show error if create is not allowed * Revert "Copy changes from Core patch" This reverts commit 1872f62a454dc41ce787103e3d1830f7ff00d63c. * Use streamlined permissions Kudos to @spacedmonkey for https://github.com/WordPress/gutenberg/pull/37454\#discussion_r771026149 * Remove inline warning and reenable ability to select existing * Refactor Notices to reusable hook * Add notices for creating Menus * Rename dep for clarity * Hide other creation options * Add e2e test * Hide classic Menus from dropdown See https://github.com/WordPress/gutenberg/pull/37454\#issuecomment-996569572 * Fix up e2e tests following changes from rebase * Update to make component props more agnostic * Make component props less tighly coupled to permissions * Remove unneeded undefined fallback * Refactor hooks * Try switch user to admin * Try switching back to admin after each permissions test * Try targetting test that relies on avoiding a 404 from URL details endpoint
- Loading branch information
1 parent
a6a956a
commit 3e30795
Showing
7 changed files
with
161 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/block-library/src/navigation/edit/use-navigation-notice.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useRef } from '@wordpress/element'; | ||
import { useDispatch } from '@wordpress/data'; | ||
import { store as noticeStore } from '@wordpress/notices'; | ||
|
||
function useNavigationNotice( { name, message } = {} ) { | ||
const noticeRef = useRef(); | ||
|
||
const { createWarningNotice, removeNotice } = useDispatch( noticeStore ); | ||
|
||
const showNotice = () => { | ||
if ( noticeRef.current ) { | ||
return; | ||
} | ||
|
||
noticeRef.current = name; | ||
|
||
createWarningNotice( message, { | ||
id: noticeRef.current, | ||
type: 'snackbar', | ||
} ); | ||
}; | ||
|
||
const hideNotice = () => { | ||
if ( ! noticeRef.current ) { | ||
return; | ||
} | ||
removeNotice( noticeRef.current ); | ||
noticeRef.current = null; | ||
}; | ||
|
||
return [ showNotice, hideNotice ]; | ||
} | ||
|
||
export default useNavigationNotice; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.