Check for valid uuid

This commit is contained in:
Andrew 2023-09-01 20:15:33 -04:00
parent f03e8d48a2
commit 9d870f0611

View File

@ -1,5 +1,6 @@
import logging import logging
import json import json
import uuid
from jsonschema import ValidationError, validate from jsonschema import ValidationError, validate
from app.classes.web.base_api_handler import BaseApiHandler from app.classes.web.base_api_handler import BaseApiHandler
@ -92,7 +93,11 @@ class ApiAnnounceIndexHandler(BaseApiHandler):
for item in cleared_notifs[:]: for item in cleared_notifs[:]:
if item not in res: if item not in res:
cleared_notifs.remove(item) cleared_notifs.remove(item)
cleared_notifs.append(data["id"]) if is_valid_uuid(data["id"]):
cleared_notifs.append(data["id"])
else:
self.finish_json(200, {"status": "error", "error": "INVALID_DATA"})
return
updata = {"cleared_notifs": ",".join(cleared_notifs)} updata = {"cleared_notifs": ",".join(cleared_notifs)}
self.controller.users.update_user(auth_data[4]["user_id"], updata) self.controller.users.update_user(auth_data[4]["user_id"], updata)
self.finish_json( self.finish_json(
@ -102,3 +107,12 @@ class ApiAnnounceIndexHandler(BaseApiHandler):
"data": {}, "data": {},
}, },
) )
def is_valid_uuid(value):
try:
uuid.UUID(str(value))
return True
except ValueError:
return False