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

Exceptions do not hide items #4

Open
DanDon opened this issue Dec 17, 2021 · 10 comments
Open

Exceptions do not hide items #4

DanDon opened this issue Dec 17, 2021 · 10 comments

Comments

@DanDon
Copy link

DanDon commented Dec 17, 2021

Adding user specific exceptions and having them hidden does not hide them for that user??

........
],
    "exceptions": [
    {
        "user": [
            "Su"
        ],
        "base_order": false,
        "order": [
            {
                "item": "overview",
                "order": 1
            },
            {
                "item": "energy",
                "hide": true
            },
            {
                "item": "map",
                "hide": true
            },
            {
                "item": "logbook",
                "hide": true
            },
            {
                "item": "history",
                "hide": true
            },
            {
                "item": "media browser",
                "hide": true
            }
        ]
    }
    ]
}
@galloween
Copy link
Owner

galloween commented Dec 17, 2021

@DanDon
Hi! there was a bug - the script expected users in the exceptions to be lowercase.
fixed it now! Update/re-download plugin, then hard-refresh the page and it should work.

If it still doesnt work - check some advises here and here and also take a look at the console for some possible errors.
Current version of the script is 301217_2359 - check you have it in the console log!
There will also be an object with some data that may help you figure out the problem.
CleanShot 2021-12-18 at 00 22 33@2x

P.S.: "clear cache and hard-refresh" menu appears if you right-click on the refresh button while Dev Tools panel is open(F12)

@DanDon
Copy link
Author

DanDon commented Dec 17, 2021

Installing the new version and hard reloading the page (or even using the page in an incognito window) still shows elements that are supposed to be hidden:

Untitled

Although trying the old custom-sidebar DOES properly hide items on a per user basis ... I do no have them both installed at the same time though, I have been switching between them and restarting the server each install. Then using incognito windows or hard reloading the page to see changes.

@galloween
Copy link
Owner

it looks like its not getting your sidebar-order.json file

normally you would see "orderConfig" in that object in the log:

you should also be able to see it in the Network tab:

@DanDon
Copy link
Author

DanDon commented Dec 17, 2021

I can see now that you're right that is does show up normally:

Untitled

But it does not appear/load into the page when logged in as the user with exceptions??

@galloween
Copy link
Owner

galloween commented Dec 17, 2021

it should! at least it does for me
(I also have 2 users, both "admins" - whatever that means, but different sidebars, using exceptions).

you could try to see if the file is where its supposed to be (using file editor/browser),
while you are logged in as the other user.

but if its not there, Im afraid I dont have any idea why.

@DanDon
Copy link
Author

DanDon commented Dec 17, 2021

Ah!! ... you have nailed the problem.

My users are not admins ... otherwise hiding the items would be pointless as they would be able to re-add them.

So the old one works with the user not having to be admin but this v2 doesn't load correctly if the user is not an admin??

@galloween
Copy link
Owner

not sure thats the reason... Also dont think the file is actually missing, any more.
new theory is the plugin cant find the sidebar DOM element.
it may be because of different theme or something like that.

i added some more logging, if you re-download the plugin you should see more stuff in that log object, all of it needs to be truthy, including these 2 elements:

If you dont have them, take a screenshot of the Inspect/Elements, top of the page:

hope we can figure it out, but now I have to go!

@63OR63
Copy link

63OR63 commented Dec 20, 2021

I made my exceptions to hide some items for all users except myself. At first It was working properly, but after some time, I assume after latest update, this addon started to hide items from me as it does for all other users. Let's say my username is John Doe, and my login is john, so I tried all variants, i.e.:

"not_user": ["john doe", "John Doe", "john"]

Custom sidebar shows my currentUser in console as john doe.
I tried to clear site date, server restart, addon reinstall, another browser — the bug persists in all cases.

My full sidebar-order.json (click to expand)
{
  "order": [
    {
      "item": "lovelace"
    },
    {
      "item": "map"
    },
    {
      "item": "history",
      "hide": true
    },
    {
      "item": "alarmo"
    },
    {
      "item": "a0d7b954_motioneye"
    },
    {
      "item": "7ad98f9c_zigbee2mqtt"
    },
    {
      "item": "a0d7b954_esphome"
    },
    {
      "item": "a0d7b954_grafana",
      "icon": "fapro:grafana"
    },
    {
      "item": "a0d7b954_influxdb",
      "icon": "fapro:influxdb"
    },
    {
      "item": "a0d7b954_nodered",
      "icon": "fapro:nodered"
    },
    {
      "item": "a0d7b954_vscode"
    },
    {
      "item": "shopping-list",
      "hide": true
    },
    {
      "item": "media-browser",
      "hide": true
    },
    {
      "item": "hacs",
      "name": "HACS",
      "icon": "fapro:hacs",
      "bottom": true
    },
    {
      "new_item": true,
      "item": "Supervisor",
      "href": "/hassio/dashboard",
      "icon": "mdi:home-assistant",
      "bottom": true
    },
    {
      "item": "developer-tools",
      "icon": "mdi:tools",
      "bottom": true
    },
    {
      "new_item": true,
      "item": "Сервер",
      "href": "/config/server_control",
      "icon": "mdi:cog-refresh",
      "bottom": true
    },
    {
      "item": "config",
      "bottom": true
    }
  ],
  "exceptions": [
    {
      "not_user": ["john doe", "John Doe", "john"],
      "order": [
        {
          "item": "hacs",
          "hide": true
        },
        {
          "item": "Supervisor",
          "hide": true
        },
        {
          "item": "developer-tools",
          "hide": true
        },
        {
          "item": "Сервер",
          "hide": true
        },
        {
          "item": "config",
          "hide": true
        },
        {
          "item": "history",
          "hide": true
        },
        {
          "item": "alarmo",
          "hide": true
        },
        {
          "item": "a0d7b954_motioneye",
          "hide": true
        },
        {
          "item": "7ad98f9c_zigbee2mqtt",
          "hide": true
        },
        {
          "item": "a0d7b954_esphome",
          "hide": true
        },
        {
          "item": "a0d7b954_grafana",
          "hide": true
        },
        {
          "item": "a0d7b954_influxdb",
          "hide": true
        },
        {
          "item": "a0d7b954_nodered",
          "hide": true
        },
        {
          "item": "a0d7b954_vscode",
          "hide": true
        }
      ]
    }
  ]
}

If I can submit some other logs/configs to help mitigate the problem I will gladly do so, as this functionality is crucial for me, I can't believe it wasn't implemented in Home Assistant after so many years of requesting and implementing as addons.

@wastingaeons
Copy link

wastingaeons commented Dec 23, 2021

not sure thats the reason... Also dont think the file is actually missing, any more. new theory is the plugin cant find the sidebar DOM element. it may be because of different theme or something like that.

Hi, chiming in here, I am also seeing the same issue as reported. Comparing your console output to mine, the DrawerLayoutElement and SideBarElement both have valid DOM elements, however, under the 'non-admin' account when exceptions are enabled, SidebarItemElement is undefined. Under an admin account, SideBarItemElement is 'a'

image

EDIT: Looks like this is why it breaks for non-admin users since they don't have the 'Configuration' menu: element.tagName == 'A' && element.getAttribute('data-panel') == 'config'

I removed the && element.getAttribute('data-panel') == 'config' and it seems to be working correctly, but unsure if it'll have other ramifications.

stephen322 added a commit to stephen322/custom-sidebar-v2 that referenced this issue Mar 5, 2022
@illusive-c
Copy link

Kind of an old topic but this bug still seems to be present. We can only limit the sidebar for "admin" user. For the non-admins, the script throws this exception:
image
Works fine for admin users.

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

5 participants