Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Plugin not working for non-admin users #12

Open
user2684 opened this issue Aug 17, 2022 · 4 comments
Open

Plugin not working for non-admin users #12

user2684 opened this issue Aug 17, 2022 · 4 comments

Comments

@user2684
Copy link

Hi, first of all thanks for refactoring this plugin and make it working with the latest version of HA :-)
I noticed everything works fine for admin users but not for non administrators. The issue seems related to getSidebarItem() when called upon startup returning undefined since looking for "data-panel" equals to "config" which is not there for a non admin user (https://github.com/galloween/custom-sidebar-v2/blob/main/dist/custom-sidebar-v2.js#L145).
As a workaround a tried picking up the latest element (e.g. .at(-1)) of window.$customSidebarV2.SideBarElement which works but I'm sure it breaks out other things.
Thanks!

@seanmccabe
Copy link

+1 have the same issue

@MelvinSnijders
Copy link

Same issue here!

@XxInvictus
Copy link

Took a look myself as I had the same issue, .at(-1) tends to get the blank space element so I grabbed the array in Console and found where config is not present media-browser is the next last array item.

Let me know if the below works for you as well (because I am not sure if media-browser is a default), this is a full drop in for the getSidebarItem function:

  function getSidebarItem(root) {
    if (window.$customSidebarV2.SidebarItemElement) {
      return window.$customSidebarV2.SidebarItemElement;
    }
    if (!root || !root.children) {
      return;
    }
    //return Array.from(root.children).at(-1)
    //return Array.from(root.children).find((element) => {
    //    return (
    //      element.tagName == 'A' && element.getAttribute('data-panel') == 'config'
    //    );
    //  }
    let lastdatapanel = Array.from(root.children).find((element) => {
      return (
        element.tagName == 'A' && element.getAttribute('data-panel') == 'config'
      );
    });
    
    if (!lastdatapanel) {
      lastpanel = Array.from(root.children).find((element) => {
        return (
          element.tagName == 'A' && element.getAttribute('data-panel') == 'media-browser'
        );
      });
    }
      
    return lastpanel;
  }

XxInvictus added a commit to XxInvictus/custom-sidebar-v2 that referenced this issue Jan 17, 2023
Fixing issue highlighted in galloween#12 where non-admin users do not have a config data-panel. If undefined it will instead use media-browser as the last element.
@XxInvictus
Copy link

Also logged a PR with the above, though it may need cleaning up this was a 5-second fix and could probably be cleaner 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants