Skip to content

GroupId conditions - js error fix for undefined permission checks#22653

Open
steveatkiss wants to merge 1 commit intoumbraco:mainfrom
steveatkiss:v17/bugfix/22648-user-groups-checks-javascript-error
Open

GroupId conditions - js error fix for undefined permission checks#22653
steveatkiss wants to merge 1 commit intoumbraco:mainfrom
steveatkiss:v17/bugfix/22648-user-groups-checks-javascript-error

Conversation

@steveatkiss
Copy link
Copy Markdown

@steveatkiss steveatkiss commented Apr 29, 2026

  • Added check to currentUser to ensure a valid user exists before checking properties on it

Prerequisites

  • I have added steps to test this contribution in the description below

Fixes #22648

Description

#observeCurrentUser in group-id.condition.ts is called as an observer callback, which can fire before the current user model is set. When this happens, currentUser is undefined, causing a javascript console error when any of the match, oneOf, allOf, or noneOf checks attempt to access currentUser.userGroupUniques.

The fix adds an early return guard at the top of the method. If currentUser is not yet available, this.permitted is set to false and the method returns immediately, preventing the property access error. The condition should re-evaluate correctly once the user is fully loaded.

To reproduce:

  1. Register a dashboard with a Umb.Condition.CurrentUser.GroupId condition using oneOf in umbraco-package.json, eg:
    "extensions": [
        {
...
            "conditions": [
...
                {
                    "alias": "Umb.Condition.CurrentUser.GroupId",
                    "oneOf": [
                        "1234f6c8-7f9c-4b5b-8d5d-9e1e5a4fdcba",
                        "43215490-93cb-4003-9130-dd463660abcd"
                    ]
                }
...
            ]
        }
    ]
  1. Load the Umbraco backoffice and navigate between CMS sections
  2. Observe the error in the browser console: TypeError: Cannot read properties of undefined (reading 'userGroupUniques')

To test the fix:

  1. Apply the change and rebuild
  2. Register a dashboard with a Umb.Condition.CurrentUser.GroupId condition (using match, oneOf, allOf, or noneOf)
  3. Load the backoffice — no console error should appear
  4. Confirm the dashboard is shown/hidden correctly based on the current user's group membership

- Added check to currentUser to ensure a valid user exists before checking properties on it
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 29, 2026

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:

  • It's clear what problem this is solving, there's a connected issue or a description of what the changes do and how to test them
  • The automated tests all pass (see "Checks" tab on this PR)
  • The level of security for this contribution is the same or improved
  • The level of performance for this contribution is the same or improved
  • Avoids creating breaking changes; note that behavioral changes might also be perceived as breaking
  • If this is a new feature, Umbraco HQ provided guidance on the implementation beforehand
  • 💡 The contribution looks original and the contributor is presumably allowed to share it

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 🤖 🙂

@emmagarland
Copy link
Copy Markdown
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Javascript error when GroupId conditions are checked on backend section transitions

2 participants