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:
Paulus Schoutsen authored and GitHub committed 2019-03-25 10:04:35 -07:00
1 parent b57d809dad
commit f1a0ad9e4a
9 files changed
+90 -14

No files matched your search

@@ -23,6 +23,7 @@ CONF_MODULE_URL = 'module_url'
CONF_EMBED_IFRAME = 'embed_iframe'
CONF_TRUST_EXTERNAL_SCRIPT = 'trust_external_script'
CONF_URL_EXCLUSIVE_GROUP = 'url_exclusive_group'
CONF_REQUIRE_ADMIN = 'require_admin'
MSG_URL_CONFLICT = \
'Pass in only one of webcomponent_path, module_url or js_url'
@@ -52,6 +53,7 @@ CONFIG_SCHEMA = vol.Schema({
default=DEFAULT_EMBED_IFRAME): cv.boolean,
vol.Optional(CONF_TRUST_EXTERNAL_SCRIPT,
default=DEFAULT_TRUST_EXTERNAL): cv.boolean,
vol.Optional(CONF_REQUIRE_ADMIN, default=False): cv.boolean,
})])
}, extra=vol.ALLOW_EXTRA)
@@ -77,7 +79,9 @@ async def async_register_panel(
# Should user be asked for confirmation when loading external source
trust_external=DEFAULT_TRUST_EXTERNAL,
# Configuration to be passed to the panel
config=None):
config=None,
# If your panel should only be shown to admin users
require_admin=False):
"""Register a new custom panel."""
if js_url is None and html_url is None and module_url is None:
raise ValueError('Either js_url, module_url or html_url is required.')
@@ -115,7 +119,8 @@ async def async_register_panel(
sidebar_title=sidebar_title,
sidebar_icon=sidebar_icon,
frontend_url_path=frontend_url_path,
config=config
config=config,
require_admin=require_admin,
)
@@ -134,6 +139,7 @@ async def async_setup(hass, config):
'config': panel.get(CONF_CONFIG),
'trust_external': panel[CONF_TRUST_EXTERNAL_SCRIPT],
'embed_iframe': panel[CONF_EMBED_IFRAME],
'require_admin': panel[CONF_REQUIRE_ADMIN],
}
panel_path = panel.get(CONF_WEBCOMPONENT_PATH)