-
-
Notifications
You must be signed in to change notification settings - Fork 722
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
Passes the user
to the restricted
function of the block settings
#6271
Conversation
✅ Deploy Preview for plone-components canceled.
|
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.
Looks good. Could you please also mention user
in the docs? https://github.com/plone/volto/blob/main/docs/source/development/how-to-restrict-blocks.md
The restricted function is called inside a useMemo. So we can't call useSelector on it. To work around this, we get the user before useMemo and pass it to the restricted function.
622de23
to
462c65e
Compare
Done |
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.
Your change is good. I corrected awkward phrasing of the preceding sentences to improve flow.
Improve flow by removing awkward phrasing.
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.
Changes applied. LGTM. Please merge when ready.
* main: (97 commits) Release 18.0.0-alpha.43 Release @plone/slate 18.0.0-alpha.18 Release @plone/client 1.0.0-alpha.17 Added a notice in the upgrade guide for CookiePlone as the recommended way for generating projects and add-on boilerplate (#6286) Fix typo in Changelog for #6285 (#6287) Update to Volto 6.0.13 (#6285) Fix order component (#6284) Remove dangling `.only` in Cypress test (#6282) Empty GridBlocks will not be rendered in 'View' (#6280) Refactor Content upload modal (#5047) Passes the `user` to the `restricted` function of the block settings (#6271) Refactored SelectMetadataField.jsx to functional component (#5570) Remove "Generate tabs for items other than folders" field from navigation control panel (#6278) Refactor DatetimeWidget (#6213) Added make i18n to volto (#6274) Place the actions-storybook in correct folder (#6275) Refactor ReferenceWidget (#5093) Fix error in SortOn component when there is no sort selected. (#6273) When user changes location, set the userSession.token value based on cookie (#6079) Trivial MyST syntax enhancement ...
It was missing to do the dispatch in getUser. It may be that the user is not in the store yet. I'll see if I can make a PR. |
@wesleybl @sneridagh @davisagli Do you think we can have this backported into Volto 17.x.x? |
@@ -22,12 +22,16 @@ The function has this signature: | |||
block: BlockConfigBase; | |||
navRoot: Content; | |||
contentType: string; | |||
user: Object |
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.
@wesleybl @davisagli The update in the docs are great but you forgot to update @plone/types
:)
volto/packages/types/src/config/Blocks.d.ts
Lines 76 to 83 in 9ffe034
restricted: | |
| ((args: { | |
properties: Content; | |
block: BlockConfigBase; // TODO: This has to be extendable | |
navRoot: Content; | |
contentType: string; | |
}) => boolean) | |
| boolean; |
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.
I will take care:
restricted:
| ((args: {
properties: Content;
block: BlockConfigBase; // TODO: This has to be extendable
navRoot: Content;
contentType: string;
user: User;
}) => boolean)
| boolean;
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.
@sneridagh Er, I haven't really bothered to learn much about typescript yet. I kind of assumed that some linter would yell at me if the types need to be updated. Is that not right? If not, how do I know when there are type declarations that need to be updated?
The
restricted
function is called inside auseMemo
. So we can't calluseSelector
on it. To work around this, we get the user beforeuseMemo
and pass it to therestricted
function.fixes #6264