-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Show UI warning to users with insufficient permissions when trying to create a new Navigation #37289
Show UI warning to users with insufficient permissions when trying to create a new Navigation #37289
Conversation
Size Change: +177 B (0%) Total Size: 1.13 MB
ℹ️ View Unchanged
|
Even if this PR doesn't go ahead, I'm interested to know whether we think the changes to |
For reference, there is a ticket at https://core.trac.wordpress.org/ticket/40197 that requests for core to actually start using this meta capability in more cases, since it's currently being under-used. Hopefully this proposal can make some progress in this area. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an interesting exploration, but I don't really think we should make this switch to using 'drafts' for everything. This opens up questions:
- When do the menus get published?
- How does a contributor ever get their menu published?
There's also currently some code that publishes menus when a menu is saved via the entity panel:
https://github.com/WordPress/gutenberg/pull/36024/files#diff-c5815980e7aa19efd287aaa72512569ac7de514d74679af2f0b099f8a9369bc5R141-R150
And I expect this will error whenever a contributor tries to save their post.
I'm thinking that we should consider alternatives to this PR, like handling the 404 when a user tries to create a new menu.
packages/block-library/src/navigation/edit/use-create-navigation-menu.js
Outdated
Show resolved
Hide resolved
if ( isPublish ) { | ||
isAllowed = !! response?.schema?.links?.find( ( link ) => | ||
link.rel.includes( 'action-publish' ) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to add a new unit test for this 👍
canUserPublishNavigation: ref | ||
? canUser( 'publish', 'navigation', ref ) | ||
: undefined, | ||
hasResolvedCanUserPublishNavigationEntity: hasFinishedResolution( | ||
'canUser', | ||
[ 'publish', 'navigation', ref ] | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like the feedback on the other PR, I think this should be folded into useNavigationMenu
.
We need to avoid making the navigation block main edit file any chunkier.
return; | ||
} | ||
|
||
noticeRef.current = uniqueId( 'navBlockNoPublishPermissions' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the comment on the other PR, no need to use a uniqueId here.
|
||
createWarningNotice( | ||
__( | ||
'You do not have permission to publish Navigations. Any edits made will not be saved.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'Navigations' isn't a word 😄
It's a singular noun only.
This PR needs unit test and for the code to broken in to new files / functions. Once that is complete, I will re-review. |
This PR will need a rebase once #37286 is merged. At that point it will be easier to add the unit test and sort the files. I'd rather avoid any major refactors if we're aiming to land this in 5.9, but more than happy to pursue this post 5.9. |
I know this can't stay "as is". It's for illustration only.
This reverts commit 4fbeb72.
b56fe5e
to
1c2f26a
Compare
This isn't going to work. See alternative in #37454 |
Description
Explores part of #36286 (comment) to display a warning to the user if they have insufficient permissions to publish a given Navigation block.
Publish status is not then ability to create a post. Rather it is the ability to publish it. By default only admin Role users can do this.
https://github.com/WordPress/wordpress-develop/blob/424afb85afa2e19f30d9836440f63c5237b4102e/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L2115-L2116
Moreover the Publish capability is a Meta capability meaning it is on a per post basis and not a global thing (i.e. you need a Post ID to check against for "publish" capability).
As things stand
canUser
cannot determine publish status so this PR updates that to enable the abiltity to do so.Moreover, when we're creating the initial Navigation post, because we're attempting to do so with the
publish
status, the POST request fails and thus we never have a Post ID to check against for "publish" permission. This PR amends the initial creation to only create a draft Navigation Post. This allows us to get a Post ID back and use that for thecanUser
publish check. We'd have to amend the block to have a step which changes the post status topublish
once the initial creation is complete.Note this doesn't handle editing existing Navigations. That's handled in #37286.
How has this been tested?
Screenshots
Screen.Capture.on.2021-12-10.at.16-01-26.mp4
Types of changes
Checklist:
*.native.js
files for terms that need renaming or removal).