Frontend indicate require admin (#22272)
* Allow panels to indicate they are meant for admins * Panels to indicate when they require admin access * Do not return admin-only panels to non-admin users * Fix flake8
This commit is contained in:
parent
b57d809dad
commit
f1a0ad9e4a
9 changed files with 90 additions and 14 deletions
|
@ -249,7 +249,7 @@ async def test_get_panels(hass, hass_ws_client):
|
|||
"""Test get_panels command."""
|
||||
await async_setup_component(hass, 'frontend')
|
||||
await hass.components.frontend.async_register_built_in_panel(
|
||||
'map', 'Map', 'mdi:tooltip-account')
|
||||
'map', 'Map', 'mdi:tooltip-account', require_admin=True)
|
||||
|
||||
client = await hass_ws_client(hass)
|
||||
await client.send_json({
|
||||
|
@ -266,6 +266,31 @@ async def test_get_panels(hass, hass_ws_client):
|
|||
assert msg['result']['map']['url_path'] == 'map'
|
||||
assert msg['result']['map']['icon'] == 'mdi:tooltip-account'
|
||||
assert msg['result']['map']['title'] == 'Map'
|
||||
assert msg['result']['map']['require_admin'] is True
|
||||
|
||||
|
||||
async def test_get_panels_non_admin(hass, hass_ws_client, hass_admin_user):
|
||||
"""Test get_panels command."""
|
||||
hass_admin_user.groups = []
|
||||
await async_setup_component(hass, 'frontend')
|
||||
await hass.components.frontend.async_register_built_in_panel(
|
||||
'map', 'Map', 'mdi:tooltip-account', require_admin=True)
|
||||
await hass.components.frontend.async_register_built_in_panel(
|
||||
'history', 'History', 'mdi:history')
|
||||
|
||||
client = await hass_ws_client(hass)
|
||||
await client.send_json({
|
||||
'id': 5,
|
||||
'type': 'get_panels',
|
||||
})
|
||||
|
||||
msg = await client.receive_json()
|
||||
|
||||
assert msg['id'] == 5
|
||||
assert msg['type'] == TYPE_RESULT
|
||||
assert msg['success']
|
||||
assert 'history' in msg['result']
|
||||
assert 'map' not in msg['result']
|
||||
|
||||
|
||||
async def test_get_translations(hass, hass_ws_client):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue