Fallback for `user_in_X` theme setting support fails when resolved value is false

I tried that now, but I think I noticed an issue while testing:
If a user is not in any of the allowed groups, the new check for user_in_copy_button_allowed_groups does not return a result. So, the fallback code for forums which cannot yet handle user_in_setting is executed but fails:

[THEME 254 'Copy post button'] TypeError: Cannot read properties of undefined (reading 'split')

Steps to reproduce:

  1. Install the component and add it to your theme
  2. Limit the allowed_groups to admins
  3. Impersonate a non-admin test user and check the browser console

I think the issue is here:

if (Object.hasOwn(settings, "user_in_copy_button_allowed_groups")) {
    if (settings.user_in_copy_button_allowed_groups) {
      return true;
    }
  }

This only returns early when the value is true. When it’s false, the fallback code below is executed, which expects the setting value to still exist as a string - but in my testing with my [1] component where I copied the fallback pattern from copy-post, it’s undefined once user_in_X support is active. I’d guess the fix is to return false in that case too, so the fallback is only used when the user_in_X key doesn’t exist at all (older core), not whenever the resolved value happens to be false.

Is my assumption correct, or is the setting still expected to provide the groups as a string?


  1. prefilled composer link ↩︎

1 Like