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:
1 parent
b57d809dad
commit
f1a0ad9e4a
9 files changed
+90
-14
No files matched your search
@@ -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):
|
||||
|
||||
@@ -8,6 +8,7 @@ import pytest
|
||||
from homeassistant.auth.const import GROUP_ID_ADMIN
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components.hassio import STORAGE_KEY
|
||||
from homeassistant.components import frontend
|
||||
|
||||
from tests.common import mock_coro
|
||||
|
||||
@@ -44,6 +45,28 @@ def test_setup_api_ping(hass, aioclient_mock):
|
||||
assert hass.components.hassio.is_hassio()
|
||||
|
||||
|
||||
async def test_setup_api_panel(hass, aioclient_mock):
|
||||
"""Test setup with API ping."""
|
||||
assert await async_setup_component(hass, 'frontend', {})
|
||||
with patch.dict(os.environ, MOCK_ENVIRON):
|
||||
result = await async_setup_component(hass, 'hassio', {})
|
||||
assert result
|
||||
|
||||
panels = hass.data[frontend.DATA_PANELS]
|
||||
|
||||
assert panels.get('hassio').to_response() == {
|
||||
'component_name': 'custom',
|
||||
'icon': 'hass:home-assistant',
|
||||
'title': 'Hass.io',
|
||||
'url_path': 'hassio',
|
||||
'require_admin': True,
|
||||
'config': {'_panel_custom': {'embed_iframe': True,
|
||||
'js_url': '/api/hassio/app/entrypoint.js',
|
||||
'name': 'hassio-main',
|
||||
'trust_external': False}},
|
||||
}
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_setup_api_push_api_data(hass, aioclient_mock):
|
||||
"""Test setup with API push."""
|
||||
|
||||
@@ -130,6 +130,7 @@ async def test_module_webcomponent(hass):
|
||||
},
|
||||
'embed_iframe': True,
|
||||
'trust_external_script': True,
|
||||
'require_admin': True,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +146,7 @@ async def test_module_webcomponent(hass):
|
||||
|
||||
panel = panels['nice_url']
|
||||
|
||||
assert panel.require_admin
|
||||
assert panel.config == {
|
||||
'hello': 'world',
|
||||
'_panel_custom': {
|
||||
|
||||
@@ -41,11 +41,13 @@ class TestPanelIframe(unittest.TestCase):
|
||||
'icon': 'mdi:network-wireless',
|
||||
'title': 'Router',
|
||||
'url': 'http://192.168.1.1',
|
||||
'require_admin': True,
|
||||
},
|
||||
'weather': {
|
||||
'icon': 'mdi:weather',
|
||||
'title': 'Weather',
|
||||
'url': 'https://www.wunderground.com/us/ca/san-diego',
|
||||
'require_admin': True,
|
||||
},
|
||||
'api': {
|
||||
'icon': 'mdi:weather',
|
||||
@@ -67,7 +69,8 @@ class TestPanelIframe(unittest.TestCase):
|
||||
'config': {'url': 'http://192.168.1.1'},
|
||||
'icon': 'mdi:network-wireless',
|
||||
'title': 'Router',
|
||||
'url_path': 'router'
|
||||
'url_path': 'router',
|
||||
'require_admin': True,
|
||||
}
|
||||
|
||||
assert panels.get('weather').to_response() == {
|
||||
@@ -76,6 +79,7 @@ class TestPanelIframe(unittest.TestCase):
|
||||
'icon': 'mdi:weather',
|
||||
'title': 'Weather',
|
||||
'url_path': 'weather',
|
||||
'require_admin': True,
|
||||
}
|
||||
|
||||
assert panels.get('api').to_response() == {
|
||||
@@ -84,6 +88,7 @@ class TestPanelIframe(unittest.TestCase):
|
||||
'icon': 'mdi:weather',
|
||||
'title': 'Api',
|
||||
'url_path': 'api',
|
||||
'require_admin': False,
|
||||
}
|
||||
|
||||
assert panels.get('ftp').to_response() == {
|
||||
@@ -92,4 +97,5 @@ class TestPanelIframe(unittest.TestCase):
|
||||
'icon': 'mdi:weather',
|
||||
'title': 'FTP',
|
||||
'url_path': 'ftp',
|
||||
'require_admin': False,
|
||||
}
|
||||
Reference in new issue
Block a user