GroupId conditions - js error fix for undefined permission checks#22653
GroupId conditions - js error fix for undefined permission checks#22653steveatkiss wants to merge 1 commit intoumbraco:mainfrom
Conversation
- Added check to currentUser to ensure a valid user exists before checking properties on it
|
Hi there @steveatkiss, thank you for this contribution! 👍 While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:
Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution. If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request. Thanks, from your friendly Umbraco GitHub bot 🤖 🙂 |
|
Hi @steveatkiss Thanks for your PR to fix #22648, where an occasional JavaScript error is logged to the console when the current user is undefined (when a package includes checks on the user groups of the current user). One of the Core Collaborators/HQ team will review this as soon as possible. I haven't seen confirmation on the original issue but hopefully, someone will be in touch soon (especially as it seems to be a focused and repeatable issue). Thanks again, Emma |
currentUserto ensure a valid user exists before checking properties on itPrerequisites
Fixes #22648
Description
#observeCurrentUseringroup-id.condition.tsis called as an observer callback, which can fire before the current user model is set. When this happens,currentUserisundefined, causing a javascript console error when any of thematch,oneOf,allOf, ornoneOfchecks attempt to accesscurrentUser.userGroupUniques.The fix adds an early return guard at the top of the method. If
currentUseris not yet available,this.permittedis set tofalseand the method returns immediately, preventing the property access error. The condition should re-evaluate correctly once the user is fully loaded.To reproduce:
Umb.Condition.CurrentUser.GroupIdcondition usingoneOfinumbraco-package.json, eg:TypeError: Cannot read properties of undefined (reading 'userGroupUniques')To test the fix:
Umb.Condition.CurrentUser.GroupIdcondition (usingmatch,oneOf,allOf, ornoneOf)