Move event permissions out of the websocket api into auth (#101975)
parent
3c3f512583
commit
93f10cdce8
|
@ -1,26 +1,18 @@
|
|||
"""Permission constants for the websocket API.
|
||||
|
||||
Separate file to avoid circular imports.
|
||||
"""
|
||||
"""Permission for events."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Final
|
||||
|
||||
from homeassistant.components.frontend import EVENT_PANELS_UPDATED
|
||||
from homeassistant.components.lovelace import EVENT_LOVELACE_UPDATED
|
||||
from homeassistant.components.persistent_notification import (
|
||||
EVENT_PERSISTENT_NOTIFICATIONS_UPDATED,
|
||||
)
|
||||
from homeassistant.components.recorder import (
|
||||
EVENT_RECORDER_5MIN_STATISTICS_GENERATED,
|
||||
EVENT_RECORDER_HOURLY_STATISTICS_GENERATED,
|
||||
)
|
||||
from homeassistant.components.shopping_list import EVENT_SHOPPING_LIST_UPDATED
|
||||
from homeassistant.const import (
|
||||
EVENT_COMPONENT_LOADED,
|
||||
EVENT_CORE_CONFIG_UPDATE,
|
||||
EVENT_LOVELACE_UPDATED,
|
||||
EVENT_PANELS_UPDATED,
|
||||
EVENT_RECORDER_5MIN_STATISTICS_GENERATED,
|
||||
EVENT_RECORDER_HOURLY_STATISTICS_GENERATED,
|
||||
EVENT_SERVICE_REGISTERED,
|
||||
EVENT_SERVICE_REMOVED,
|
||||
EVENT_SHOPPING_LIST_UPDATED,
|
||||
EVENT_STATE_CHANGED,
|
||||
EVENT_THEMES_UPDATED,
|
||||
)
|
||||
|
@ -38,7 +30,6 @@ SUBSCRIBE_ALLOWLIST: Final[set[str]] = {
|
|||
EVENT_ENTITY_REGISTRY_UPDATED,
|
||||
EVENT_LOVELACE_UPDATED,
|
||||
EVENT_PANELS_UPDATED,
|
||||
EVENT_PERSISTENT_NOTIFICATIONS_UPDATED,
|
||||
EVENT_RECORDER_5MIN_STATISTICS_GENERATED,
|
||||
EVENT_RECORDER_HOURLY_STATISTICS_GENERATED,
|
||||
EVENT_SERVICE_REGISTERED,
|
|
@ -17,7 +17,12 @@ from homeassistant.components import onboarding, websocket_api
|
|||
from homeassistant.components.http.view import HomeAssistantView
|
||||
from homeassistant.components.websocket_api.connection import ActiveConnection
|
||||
from homeassistant.config import async_hass_config_yaml
|
||||
from homeassistant.const import CONF_MODE, CONF_NAME, EVENT_THEMES_UPDATED
|
||||
from homeassistant.const import (
|
||||
CONF_MODE,
|
||||
CONF_NAME,
|
||||
EVENT_PANELS_UPDATED,
|
||||
EVENT_THEMES_UPDATED,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||
from homeassistant.helpers import service
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -40,7 +45,6 @@ CONF_EXTRA_MODULE_URL = "extra_module_url"
|
|||
CONF_EXTRA_JS_URL_ES5 = "extra_js_url_es5"
|
||||
CONF_FRONTEND_REPO = "development_repo"
|
||||
CONF_JS_VERSION = "javascript_version"
|
||||
EVENT_PANELS_UPDATED = "panels_updated"
|
||||
|
||||
DEFAULT_THEME_COLOR = "#03A9F4"
|
||||
|
||||
|
|
|
@ -3,13 +3,18 @@ from typing import Any
|
|||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import CONF_ICON, CONF_MODE, CONF_TYPE, CONF_URL
|
||||
from homeassistant.const import (
|
||||
CONF_ICON,
|
||||
CONF_MODE,
|
||||
CONF_TYPE,
|
||||
CONF_URL,
|
||||
EVENT_LOVELACE_UPDATED, # noqa: F401
|
||||
)
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.util import slugify
|
||||
|
||||
DOMAIN = "lovelace"
|
||||
EVENT_LOVELACE_UPDATED = "lovelace_updated"
|
||||
|
||||
DEFAULT_ICON = "hass:view-dashboard"
|
||||
|
||||
|
|
|
@ -30,10 +30,6 @@ ATTR_TITLE: Final = "title"
|
|||
ATTR_STATUS: Final = "status"
|
||||
|
||||
|
||||
# Remove EVENT_PERSISTENT_NOTIFICATIONS_UPDATED in Home Assistant 2023.9
|
||||
EVENT_PERSISTENT_NOTIFICATIONS_UPDATED = "persistent_notifications_updated"
|
||||
|
||||
|
||||
class Notification(TypedDict):
|
||||
"""Persistent notification."""
|
||||
|
||||
|
|
|
@ -6,7 +6,12 @@ from typing import Any
|
|||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import CONF_EXCLUDE, EVENT_STATE_CHANGED
|
||||
from homeassistant.const import (
|
||||
CONF_EXCLUDE,
|
||||
EVENT_RECORDER_5MIN_STATISTICS_GENERATED, # noqa: F401
|
||||
EVENT_RECORDER_HOURLY_STATISTICS_GENERATED, # noqa: F401
|
||||
EVENT_STATE_CHANGED,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entityfilter import (
|
||||
|
@ -25,8 +30,6 @@ from .const import ( # noqa: F401
|
|||
CONF_DB_INTEGRITY_CHECK,
|
||||
DATA_INSTANCE,
|
||||
DOMAIN,
|
||||
EVENT_RECORDER_5MIN_STATISTICS_GENERATED,
|
||||
EVENT_RECORDER_HOURLY_STATISTICS_GENERATED,
|
||||
INTEGRATION_PLATFORM_COMPILE_STATISTICS,
|
||||
INTEGRATION_PLATFORMS_LOAD_IN_RECORDER_THREAD,
|
||||
SQLITE_URL_PREFIX,
|
||||
|
|
|
@ -2,7 +2,13 @@
|
|||
|
||||
from enum import StrEnum
|
||||
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, ATTR_RESTORED, ATTR_SUPPORTED_FEATURES
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
ATTR_RESTORED,
|
||||
ATTR_SUPPORTED_FEATURES,
|
||||
EVENT_RECORDER_5MIN_STATISTICS_GENERATED, # noqa: F401
|
||||
EVENT_RECORDER_HOURLY_STATISTICS_GENERATED, # noqa: F401
|
||||
)
|
||||
from homeassistant.helpers.json import JSON_DUMP # noqa: F401
|
||||
|
||||
DATA_INSTANCE = "recorder_instance"
|
||||
|
@ -13,9 +19,6 @@ MYSQLDB_URL_PREFIX = "mysql://"
|
|||
MYSQLDB_PYMYSQL_URL_PREFIX = "mysql+pymysql://"
|
||||
DOMAIN = "recorder"
|
||||
|
||||
EVENT_RECORDER_5MIN_STATISTICS_GENERATED = "recorder_5min_statistics_generated"
|
||||
EVENT_RECORDER_HOURLY_STATISTICS_GENERATED = "recorder_hourly_statistics_generated"
|
||||
|
||||
CONF_DB_INTEGRITY_CHECK = "db_integrity_check"
|
||||
|
||||
MAX_QUEUE_BACKLOG_MIN_VALUE = 65000
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
"""All constants related to the shopping list component."""
|
||||
|
||||
from homeassistant.const import EVENT_SHOPPING_LIST_UPDATED # noqa: F401
|
||||
|
||||
DOMAIN = "shopping_list"
|
||||
EVENT_SHOPPING_LIST_UPDATED = "shopping_list_updated"
|
||||
|
||||
|
||||
ATTR_REVERSE = "reverse"
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.auth.models import User
|
||||
from homeassistant.auth.permissions.const import POLICY_READ
|
||||
from homeassistant.auth.permissions.events import SUBSCRIBE_ALLOWLIST
|
||||
from homeassistant.const import (
|
||||
EVENT_STATE_CHANGED,
|
||||
MATCH_ALL,
|
||||
|
@ -128,10 +129,6 @@ def handle_subscribe_events(
|
|||
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
|
||||
) -> None:
|
||||
"""Handle subscribe events command."""
|
||||
# Circular dep
|
||||
# pylint: disable-next=import-outside-toplevel
|
||||
from .permissions import SUBSCRIBE_ALLOWLIST
|
||||
|
||||
event_type = msg["event_type"]
|
||||
|
||||
if event_type not in SUBSCRIBE_ALLOWLIST and not connection.user.is_admin:
|
||||
|
|
|
@ -293,6 +293,13 @@ EVENT_SERVICE_REGISTERED: Final = "service_registered"
|
|||
EVENT_SERVICE_REMOVED: Final = "service_removed"
|
||||
EVENT_STATE_CHANGED: Final = "state_changed"
|
||||
EVENT_THEMES_UPDATED: Final = "themes_updated"
|
||||
EVENT_PANELS_UPDATED: Final = "panels_updated"
|
||||
EVENT_LOVELACE_UPDATED: Final = "lovelace_updated"
|
||||
EVENT_RECORDER_5MIN_STATISTICS_GENERATED: Final = "recorder_5min_statistics_generated"
|
||||
EVENT_RECORDER_HOURLY_STATISTICS_GENERATED: Final = (
|
||||
"recorder_hourly_statistics_generated"
|
||||
)
|
||||
EVENT_SHOPPING_LIST_UPDATED: Final = "shopping_list_updated"
|
||||
|
||||
# #### DEVICE CLASSES ####
|
||||
# DEVICE_CLASS_* below are deprecated as of 2021.12
|
||||
|
|
Loading…
Reference in New Issue