Refactor User attribute caching to be safer and more efficient (#96723)

* Cache construction of is_admin

This has to be checked for a lot of api calls and the websocket
every time the call is made

* Cache construction of is_admin

This has to be checked for a lot of api calls and the websocket
every time the call is made

* Cache construction of is_admin

This has to be checked for a lot of api calls and the websocket
every time the call is made

* modernize

* coverage

* coverage

* verify caching

* verify caching

* fix type

* fix mocking
This commit is contained in:
J. Nick Koston 2024-01-13 10:10:50 -10:00 committed by GitHub
parent d7910841ef
commit b1d0c6a4f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 72 additions and 30 deletions

View file

@ -684,6 +684,8 @@ async def test_get_entity_state_read_perm(
) -> None:
"""Test getting a state requires read permission."""
hass_admin_user.mock_policy({})
hass_admin_user.groups = []
assert hass_admin_user.is_admin is False
resp = await mock_api_client.get("/api/states/light.test")
assert resp.status == HTTPStatus.UNAUTHORIZED