-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Visual Editor: Fix permission error #45262
Conversation
editedPostTemplate: | ||
supportsTemplateMode && canEditTemplate | ||
? getEditedPostTemplate() | ||
: undefined, |
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.
We should avoid returning new object references here. It will fail shallow equality check and cause unnecessary rerenders.
The postContentBlock
calculation has guard clauses, so I think it's safe to return undefined
. We can also use the EMPTY_OBJECT
reference if that's preferred.
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.
It's also being given a default on line 119 where we destructure the return value of useSelect
so I suppose we should remove that one too.
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.
Assigning default values during destructuring is okay; that doesn't change values returned inside the selector function.
Size Change: +20 B (0%) Total Size: 1.28 MB
ℹ️ View Unchanged
|
5b1c75b
to
458f248
Compare
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.
Thanks for uncovering this bug!
Tested with author user and admin user, on both block and classic themes, and also checked the template editor. Everything is working fine ✅
I guess an outstanding issue here is that an author user isn't able to get the correct layout styles in the post editor, but that's something to be looked at separately.
editedPostTemplate: | ||
supportsTemplateMode && canEditTemplate | ||
? getEditedPostTemplate() | ||
: undefined, |
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.
It's also being given a default on line 119 where we destructure the return value of useSelect
so I suppose we should remove that one too.
Thanks for testing, @tellthemachines! Unfortunately, the incorrect layout issue remains for non-admin users. Maybe we can add the |
I just tried out an alternative approach to fetching the Post Content in #45299 which works for all user types. |
What?
This is a follow-up for #44258.
PR fixes permission errors triggered by
getEditedPostTemplate
for users with lower capabilities.Why?
The editor should check permission before making requests when data isn't available for everyone.
How?
Add check for user permissions before requesting
getEditedPostTemplate
.Testing Instructions