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 upCore Data: Add entity prop locking and use it in the Site Title block. #18772
Conversation
Not sure I understand why we need the ability to lock properties, for me this is more a value that comes built-in depending on the role of the logged-in user instead of something you should/can set. |
This comment has been minimized.
This comment has been minimized.
Locking will be necessary in situations outside of user permissions/authentication (think Newspack blocks) and even the way we query user permissions can vary enough that we benefit from making this general in the framework. Compare the changes to |
This comment has been minimized.
This comment has been minimized.
I'm still not convinced here to be honest. It's not about the consuming API itself which I'm fine with but it's just a duplicate of It's more about the responsibilities. I don't think locked properties should be defined in the entity config as they can change per user, we should just consume them from the existing Rest APIs and I don't think a public |
This comment has been minimized.
This comment has been minimized.
Think about cases where a prop may be locked for different reasons in different circumstances and this doesn't map directly to things like @mtias also has more thoughts on this. |
epiqueras commentedNov 26, 2019
Description
This PR addresses a need found by #18760 and is an alternative to it.
Certain entity props, like a site's title, should not always be editable depending on editing context and/or user permissions. The framework should provide a declarative way of "locking" these props.
This PR provides a way to define default "locked" values for different entity types in their configs, and a way to track and edit these values on a per-entity-record basis. The "locked" values can either be literals that will be wrapped in getters, i.e.
true
, becomes() => true
and means a prop is locked,false
orundefined
means it's not, or they can be functions that will be pre-bound toselect
.This approach allows for simplicity and the flexibility for consumers to derive the values based on any state, like the site entity config does in this PR with
canUser
.Additionally,
useEntityProp
's setter now throws a warning when trying to set a value for a locked prop, and it also returns a third variable, the evaluated "locked" value for the specified prop. This made the changes needed in the Site Title block minimal and it made it really easy to avoid forking the rendering path when the site title is locked.How has this been tested?
It was verified that using the Site Title block logged in as a contributor renders it disabled.
Types of Changes
New Feature:
core-data
entities now support locked entity props for managing props that shouldn't be editable under certain context and/or with certain user permission levels.Checklist: