Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upSite Title: Add a view mode for non-admins #18760
Conversation
@@ -9,14 +11,15 @@ import { Button } from '@wordpress/components'; | |||
import { __ } from '@wordpress/i18n'; | |||
import { RichText } from '@wordpress/block-editor'; | |||
|
|||
export default function SiteTitleEdit() { | |||
export function SiteTitleEdit( props ) { |
This comment has been minimized.
This comment has been minimized.
epiqueras
Nov 26, 2019
Contributor
We should follow the style of the other components in this package and destructure props
.
@@ -1,6 +1,8 @@ | |||
/** | |||
* WordPress dependencies | |||
*/ | |||
import { compose } from '@wordpress/compose'; | |||
import { withSelect } from '@wordpress/data'; |
This comment has been minimized.
This comment has been minimized.
epiqueras
Nov 26, 2019
Contributor
withSelect
uses useSelect
under the hood and we are moving towards using that to better compose with other hooks, take advantage of functional component performance improvements, and improve readability.
<h1>{ title }</h1> | ||
); | ||
|
||
return ( props.canUpdate && props.isSelected ) ? editMode : viewMode; |
This comment has been minimized.
This comment has been minimized.
epiqueras
Nov 26, 2019
Contributor
Can we disable the input instead of introducing this split rendering path?
It seems innocuous in this context, but split edit/view paths will make it really hard to keep a consistent rendering style, so it will be better if we enforce using a single rendering path from the start.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ellatrix
Nov 26, 2019
Member
I agree. We explored a read only mode for RichText
a while ago that could be enabled based on the context (a locked template or block for example). Additionally it would be good to disable attribute updating.
withSelect( ( select, {} ) => { | ||
const { canUser } = select( 'core' ); | ||
return { | ||
canUpdate: canUser( 'update', 'settings' ), |
This comment has been minimized.
This comment has been minimized.
epiqueras
Nov 26, 2019
Contributor
Just a note that I intend to make this part of the framework.
I envision that core-data
will keep track of which entity properties are locked, actions can change that, entity configs provide default values/selectors, and useEntityProp
will return a third boolean variable that says whether the specified prop is locked or not.
This comment has been minimized.
This comment has been minimized.
See #18772. |
This comment has been minimized.
This comment has been minimized.
The site title is available via the index in the REST API under |
This comment has been minimized.
This comment has been minimized.
I've also opened https://core.trac.wordpress.org/ticket/48816 since it seems like using the actual site title with display filters applied would also be wanted? |
This comment has been minimized.
This comment has been minimized.
I updated this to use the index path in the REST API for To avoid splitting the render path we need to do some more work on RichText so it has a read only mode. I'll start on this in a different PR, but maybe we can get this merged anyway, and circle back? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@epiqueras, the problem is that non-admins can't access the REST API for this path at all, so I'm not sure that solution is going to help. :( |
This comment has been minimized.
This comment has been minimized.
We should find a way to unify these two APIs. Either make In the meantime, f6ce79c can still be applied to #18772. See #18772 (comment) for more reasoning. |
This comment has been minimized.
This comment has been minimized.
Also, I imagine the entity engine should be able to switch the API request if needed based on the locked context. |
This comment has been minimized.
This comment has been minimized.
That starts to become too convoluted. There could be multiple reasons why a property is locked and no way to map them to a single "correct" API request without a lot of extra configuration. Different consumers will also have vastly different requirements for this. This should be handled at the endpoint level where the required data and functionality already exists. There is no reason we couldn't have an additional endpoint that delegates to |
This comment has been minimized.
This comment has been minimized.
They are two entirely separate contexts, one is for editing a setting, the other is for getting the rendered site title. We're not going to support updating properties on the site index. Allow users read only access to the settings endpoint has a huge number of security implications. |
This comment has been minimized.
This comment has been minimized.
Is that viable? Only exposing properties which are safe to be read by users of course. |
This comment has been minimized.
This comment has been minimized.
I think those properties would be on the index. If it would be architecturally simpler, we could potential nest them under something like |
This comment has been minimized.
This comment has been minimized.
Yeah, we just need to use the same endpoint for reading and updating. |
This comment has been minimized.
This comment has been minimized.
I don't see why switching the request on the client to the base is a problem? It seems exactly the type of logic the API client would do instead of coding a specific endpoint on the server. That data should also already be loaded. Further, the values themselves should be different. Whatever is on |
This comment has been minimized.
This comment has been minimized.
Because it breaks a single resource into two when there's no need to. It's inconsistent and will make it harder to maintain. Other properties have |
This comment has been minimized.
This comment has been minimized.
This won't be possible, see: https://core.trac.wordpress.org/ticket/48812. I'll investigate the reverse... |
This comment has been minimized.
This comment has been minimized.
The index route isn't currently writable: https://github.com/WordPress/WordPress/blob/master/wp-includes/rest-api/class-wp-rest-server.php#L91 I can't forsee that changing either. Maybe we need to create new routes for each option? |
This comment has been minimized.
This comment has been minimized.
I think we should do this: #18760 (comment). |
This comment has been minimized.
This comment has been minimized.
I started a patch for this on the REST API: https://core.trac.wordpress.org/attachment/ticket/48885 I'm not sure how to go about implementing this in Gutenberg... |
This comment has been minimized.
This comment has been minimized.
Add a new entity for the new resource like you did here for "base": f6ce79c#diff-c5eaec560b039f2dc76f93fa76ba89da. |
This comment has been minimized.
This comment has been minimized.
I created #18970 to use the new API endpoint |
This comment has been minimized.
This comment has been minimized.
I don't think we should have a specific endpoint just for the title. Won't there be other site settings that need this functionality? Why not something like |
This comment has been minimized.
This comment has been minimized.
@epiqueras the endpoint supports /settings/title I wasn't sure how to extend the definition of entities to allow this. |
This comment has been minimized.
This comment has been minimized.
Yes, but why? All of these properties follow the same reading and updating logic. They should be grouped under something like |
This comment has been minimized.
This comment has been minimized.
Would this be identical to what |
This comment has been minimized.
This comment has been minimized.
No:
Only for a safe subset of settings. |
This comment has been minimized.
This comment has been minimized.
Ah, ok, that makes sense thanks. I'll update the patch to take this approach on Monday. Sorry for the confusion. |
This comment has been minimized.
This comment has been minimized.
Awesome! Thanks :-)
|
This comment has been minimized.
This comment has been minimized.
I updated this, and the corresponding core patch (https://core.trac.wordpress.org/ticket/48885) to put all the public settings in the same route. |
scruffian commentedNov 26, 2019
•
edited
Description
This updates the Site Title block to account for non-admins.
It's possible that this block could be added to a post that anyone has access to. Only admins should be able to edit the content, but all users should be able to see this block so that they have an accurate preview.
How has this been tested?
Create a 'non-admin' account on your WordPress site. Add the Site Title block to a post. You should be able to see the site title, but not edit it:
Screenshots
Admin (unchanged)

Non-admin

Types of changes
New feature (non-breaking change which adds functionality)
Checklist: