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