mirror of
https://github.com/thekiwismarthome/shopping-list-manager.git
synced 2026-05-01 11:46:30 +00:00
Update websocket_api.py
This commit is contained in:
@@ -56,6 +56,14 @@ async def websocket_add_product(
|
|||||||
"""
|
"""
|
||||||
manager = hass.data[DOMAIN]["manager"]
|
manager = hass.data[DOMAIN]["manager"]
|
||||||
list_id = msg.get("list_id", "groceries")
|
list_id = msg.get("list_id", "groceries")
|
||||||
|
lists = manager.get_visible_lists(connection.user)
|
||||||
|
if list_id not in lists:
|
||||||
|
connection.send_error(
|
||||||
|
msg["id"],
|
||||||
|
"not_authorized",
|
||||||
|
f"You do not have access to list '{list_id}'"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
product = await manager.async_add_product(
|
product = await manager.async_add_product(
|
||||||
@@ -109,7 +117,7 @@ async def ws_get_lists(
|
|||||||
try:
|
try:
|
||||||
# Ensure lists are loaded
|
# Ensure lists are loaded
|
||||||
await manager._ensure_lists_loaded()
|
await manager._ensure_lists_loaded()
|
||||||
lists = manager._lists
|
lists = manager.get_visible_lists(connection.user)
|
||||||
connection.send_result(msg["id"], lists)
|
connection.send_result(msg["id"], lists)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
_LOGGER.error("Error getting lists: %s", err)
|
_LOGGER.error("Error getting lists: %s", err)
|
||||||
@@ -159,6 +167,14 @@ async def websocket_set_qty(
|
|||||||
"""
|
"""
|
||||||
manager = hass.data[DOMAIN]["manager"]
|
manager = hass.data[DOMAIN]["manager"]
|
||||||
list_id = msg.get("list_id", "groceries")
|
list_id = msg.get("list_id", "groceries")
|
||||||
|
lists = manager.get_visible_lists(connection.user)
|
||||||
|
if list_id not in lists:
|
||||||
|
connection.send_error(
|
||||||
|
msg["id"],
|
||||||
|
"not_authorized",
|
||||||
|
f"You do not have access to list '{list_id}'"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await manager.async_set_qty(
|
await manager.async_set_qty(
|
||||||
@@ -212,6 +228,14 @@ async def websocket_get_products(
|
|||||||
"""
|
"""
|
||||||
manager = hass.data[DOMAIN]["manager"]
|
manager = hass.data[DOMAIN]["manager"]
|
||||||
list_id = msg.get("list_id", "groceries")
|
list_id = msg.get("list_id", "groceries")
|
||||||
|
lists = manager.get_visible_lists(connection.user)
|
||||||
|
if list_id not in lists:
|
||||||
|
connection.send_error(
|
||||||
|
msg["id"],
|
||||||
|
"not_authorized",
|
||||||
|
f"You do not have access to list '{list_id}'"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
products = await manager.async_get_products(list_id=list_id)
|
products = await manager.async_get_products(list_id=list_id)
|
||||||
@@ -250,6 +274,14 @@ async def websocket_get_active(
|
|||||||
"""
|
"""
|
||||||
manager = hass.data[DOMAIN]["manager"]
|
manager = hass.data[DOMAIN]["manager"]
|
||||||
list_id = msg.get("list_id", "groceries")
|
list_id = msg.get("list_id", "groceries")
|
||||||
|
lists = manager.get_visible_lists(connection.user)
|
||||||
|
if list_id not in lists:
|
||||||
|
connection.send_error(
|
||||||
|
msg["id"],
|
||||||
|
"not_authorized",
|
||||||
|
f"You do not have access to list '{list_id}'"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
active = await manager.async_get_active(list_id=list_id)
|
active = await manager.async_get_active(list_id=list_id)
|
||||||
@@ -288,6 +320,14 @@ async def websocket_delete_product(
|
|||||||
"""
|
"""
|
||||||
manager = hass.data[DOMAIN]["manager"]
|
manager = hass.data[DOMAIN]["manager"]
|
||||||
list_id = msg.get("list_id", "groceries")
|
list_id = msg.get("list_id", "groceries")
|
||||||
|
lists = manager.get_visible_lists(connection.user)
|
||||||
|
if list_id not in lists:
|
||||||
|
connection.send_error(
|
||||||
|
msg["id"],
|
||||||
|
"not_authorized",
|
||||||
|
f"You do not have access to list '{list_id}'"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await manager.async_delete_product(list_id=list_id, key=msg["key"])
|
await manager.async_delete_product(list_id=list_id, key=msg["key"])
|
||||||
|
|||||||
Reference in New Issue
Block a user