Add permissions check in service helper (#18596)
* Add permissions check in service helper * Lint * Fix tests * Lint * Typing * Fix unused impoert
This commit is contained in:
parent
8aa2cefd75
commit
36c31a6293
14 changed files with 268 additions and 46 deletions
|
@ -1,24 +1,24 @@
|
|||
"""The exceptions used by Home Assistant."""
|
||||
from typing import Optional, Tuple, TYPE_CHECKING
|
||||
import jinja2
|
||||
|
||||
# pylint: disable=using-constant-test
|
||||
if TYPE_CHECKING:
|
||||
# pylint: disable=unused-import
|
||||
from .core import Context # noqa
|
||||
|
||||
|
||||
class HomeAssistantError(Exception):
|
||||
"""General Home Assistant exception occurred."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class InvalidEntityFormatError(HomeAssistantError):
|
||||
"""When an invalid formatted entity is encountered."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class NoEntitySpecifiedError(HomeAssistantError):
|
||||
"""When no entity is specified."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class TemplateError(HomeAssistantError):
|
||||
"""Error during template rendering."""
|
||||
|
@ -32,16 +32,29 @@ class TemplateError(HomeAssistantError):
|
|||
class PlatformNotReady(HomeAssistantError):
|
||||
"""Error to indicate that platform is not ready."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class ConfigEntryNotReady(HomeAssistantError):
|
||||
"""Error to indicate that config entry is not ready."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class InvalidStateError(HomeAssistantError):
|
||||
"""When an invalid state is encountered."""
|
||||
|
||||
pass
|
||||
|
||||
class Unauthorized(HomeAssistantError):
|
||||
"""When an action is unauthorized."""
|
||||
|
||||
def __init__(self, context: Optional['Context'] = None,
|
||||
user_id: Optional[str] = None,
|
||||
entity_id: Optional[str] = None,
|
||||
permission: Optional[Tuple[str]] = None) -> None:
|
||||
"""Unauthorized error."""
|
||||
super().__init__(self.__class__.__name__)
|
||||
self.context = context
|
||||
self.user_id = user_id
|
||||
self.entity_id = entity_id
|
||||
self.permission = permission
|
||||
|
||||
|
||||
class UnknownUser(Unauthorized):
|
||||
"""When call is made with user ID that doesn't exist."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue