mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add EVENT_USER_UPDATED (#71965)
This commit is contained in:
parent
2f106112df
commit
211e5432ac
@ -20,6 +20,7 @@ from .mfa_modules import MultiFactorAuthModule, auth_mfa_module_from_config
|
|||||||
from .providers import AuthProvider, LoginFlow, auth_provider_from_config
|
from .providers import AuthProvider, LoginFlow, auth_provider_from_config
|
||||||
|
|
||||||
EVENT_USER_ADDED = "user_added"
|
EVENT_USER_ADDED = "user_added"
|
||||||
|
EVENT_USER_UPDATED = "user_updated"
|
||||||
EVENT_USER_REMOVED = "user_removed"
|
EVENT_USER_REMOVED = "user_removed"
|
||||||
|
|
||||||
_MfaModuleDict = dict[str, MultiFactorAuthModule]
|
_MfaModuleDict = dict[str, MultiFactorAuthModule]
|
||||||
@ -338,6 +339,8 @@ class AuthManager:
|
|||||||
else:
|
else:
|
||||||
await self.async_deactivate_user(user)
|
await self.async_deactivate_user(user)
|
||||||
|
|
||||||
|
self.hass.bus.async_fire(EVENT_USER_UPDATED, {"user_id": user.id})
|
||||||
|
|
||||||
async def async_activate_user(self, user: models.User) -> None:
|
async def async_activate_user(self, user: models.User) -> None:
|
||||||
"""Activate a user."""
|
"""Activate a user."""
|
||||||
await self._store.async_activate_user(user)
|
await self._store.async_activate_user(user)
|
||||||
|
@ -8,6 +8,7 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant import auth, data_entry_flow
|
from homeassistant import auth, data_entry_flow
|
||||||
from homeassistant.auth import (
|
from homeassistant.auth import (
|
||||||
|
EVENT_USER_UPDATED,
|
||||||
InvalidAuthError,
|
InvalidAuthError,
|
||||||
auth_store,
|
auth_store,
|
||||||
const as auth_const,
|
const as auth_const,
|
||||||
@ -1097,3 +1098,20 @@ async def test_rename_does_not_change_refresh_token(mock_hass):
|
|||||||
token_after = list(user.refresh_tokens.values())[0]
|
token_after = list(user.refresh_tokens.values())[0]
|
||||||
|
|
||||||
assert token_before == token_after
|
assert token_before == token_after
|
||||||
|
|
||||||
|
|
||||||
|
async def test_event_user_updated_fires(hass):
|
||||||
|
"""Test the user updated event fires."""
|
||||||
|
manager = await auth.auth_manager_from_config(hass, [], [])
|
||||||
|
user = MockUser().add_to_auth_manager(manager)
|
||||||
|
await manager.async_create_refresh_token(user, CLIENT_ID)
|
||||||
|
|
||||||
|
assert len(list(user.refresh_tokens.values())) == 1
|
||||||
|
|
||||||
|
events = async_capture_events(hass, EVENT_USER_UPDATED)
|
||||||
|
|
||||||
|
await manager.async_update_user(user, name="new name")
|
||||||
|
assert user.name == "new name"
|
||||||
|
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert len(events) == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user