aboutsummaryrefslogtreecommitdiffstats
path: root/backend/models/form.py
diff options
context:
space:
mode:
authorGravatar Hassan Abouelela <[email protected]>2021-03-15 02:14:21 +0300
committerGravatar Hassan Abouelela <[email protected]>2021-03-15 02:16:29 +0300
commit4f4dac9c8c863646a8292a9a2db53c0651d96b37 (patch)
treee4274fddbd1dd8544d696533c1ffc7374ee86423 /backend/models/form.py
parentAdds Logging To Helpers (diff)
Adds Logging For Routeslogging
Adds logging for most routes, to make it easier to debug the routes, and keep a better record of major changes. Most operations would not get logged, except the beginning of a more sensitive operation, especially ones that require admin permissions. Signed-off-by: Hassan Abouelela <[email protected]>
Diffstat (limited to 'backend/models/form.py')
-rw-r--r--backend/models/form.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/backend/models/form.py b/backend/models/form.py
index eac0b63..cef1977 100644
--- a/backend/models/form.py
+++ b/backend/models/form.py
@@ -1,3 +1,4 @@
+import logging
import typing as t
import httpx
@@ -9,6 +10,8 @@ from .question import Question
PUBLIC_FIELDS = ["id", "features", "questions", "name", "description", "submitted_text"]
+logger = logging.getLogger(__name__)
+
class _WebHook(BaseModel):
"""Schema model of discord webhooks."""
@@ -54,11 +57,14 @@ class Form(BaseModel):
def dict(self, admin: bool = True, **kwargs: t.Any) -> dict[str, t.Any]:
"""Wrapper for original function to exclude private data for public access."""
+ logger.debug("Converting form to dict.")
data = super().dict(**kwargs)
returned_data = {}
if not admin:
+ logger.debug("Removing non-public fields, as admin was false.")
+
for field in PUBLIC_FIELDS:
if field == "id" and kwargs.get("by_alias"):
fetch_field = "_id"
@@ -67,6 +73,7 @@ class Form(BaseModel):
returned_data[field] = data[fetch_field]
else:
+ logger.debug("Including all fields.")
returned_data = data
return returned_data
@@ -86,6 +93,7 @@ async def validate_hook_url(url: str) -> t.Optional[ValidationError]:
raise ValueError("URL must be a discord webhook.")
try:
+ logger.debug("Pinging discord to verify webhook.")
async with httpx.AsyncClient() as client:
response = await client.get(url)
response.raise_for_status()
@@ -117,6 +125,7 @@ async def validate_hook_url(url: str) -> t.Optional[ValidationError]:
# Validate, and return errors, if any
try:
+ logger.info("Validating a webhook url.")
await validate()
except Exception as e:
loc = (