aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--SCHEMA.md13
-rw-r--r--backend/constants.py4
-rw-r--r--backend/models/form.py10
-rw-r--r--backend/routes/forms/index.py5
-rw-r--r--backend/routes/forms/submit.py6
5 files changed, 15 insertions, 23 deletions
diff --git a/SCHEMA.md b/SCHEMA.md
index fa5f247..c3edf35 100644
--- a/SCHEMA.md
+++ b/SCHEMA.md
@@ -16,10 +16,10 @@ In this document:
| ------------- | ----------------------------------------- | ----------------------------------------------------------------------------------------- | ---------------------------------------- |
| `id` | Unique identifier | A user selected, unique, descriptive identifier (used in URL routes, so no spaces) | `"ban-appeals"` |
| `features` | List of [form features](#form-features) | A list of features to change the behaviour of the form, described in the features section | `["OPEN", "COLLECT_EMAIL"]` |
-| `meta` | Mapping of [meta options](#meta-options) | Meta properties for the form. | See meta-options section |
| `questions` | List of [form questions](#form-question) | The list of questions to render on a specific form | Too long! See below |
| `name` | String | Name of the form | `"Summer Code Jam 2100"` |
| `description` | String | Form description | `"This is my amazing form description."` |
+| `webhook` | [Webhook object](#webhooks) | An optional discord webhook. | See webhook documentation. |
### Form features
@@ -32,10 +32,13 @@ In this document:
| `DISABLE_ANTISPAM` | Disable the anti-spam checks from running on a form submission. |
| `WEBHOOK_ENABLED` | The form should notify the webhook. Has no effect if no webhook is set. |
-### Meta options
-| Field | Description | Example |
-| --------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
-| `webhook` | Mapping of webhook url and message. Message can use certain [context variables](#webhook-variables). | `"webhook": {"url": "https://discord.com/api/webhooks/id/key", "message": "{user} submitted a form."}` |
+### Webhooks
+Discord webhooks to send information upon form submission.
+
+| Field | Type | Description |
+| ----------| ------ | --------------------------------------------------------------------------------------------------------- |
+| `url` | String | Discord webhook URL. |
+| `message` | String | An optional message to include before the embed. Can use certain [context variables](#webhook-variables). |
#### Webhook Variables
diff --git a/backend/constants.py b/backend/constants.py
index bfcf261..bf0c33c 100644
--- a/backend/constants.py
+++ b/backend/constants.py
@@ -67,7 +67,3 @@ class FormFeatures(Enum):
class WebHook(Enum):
URL = "url"
MESSAGE = "message"
-
-
-class Meta(Enum):
- WEB_HOOK = WebHook
diff --git a/backend/models/form.py b/backend/models/form.py
index d5e2ff5..57372ea 100644
--- a/backend/models/form.py
+++ b/backend/models/form.py
@@ -4,7 +4,7 @@ import httpx
from pydantic import BaseModel, Field, validator
from pydantic.error_wrappers import ErrorWrapper, ValidationError
-from backend.constants import FormFeatures, Meta, WebHook
+from backend.constants import FormFeatures, WebHook
from .question import Question
PUBLIC_FIELDS = ["id", "features", "questions", "name", "description"]
@@ -24,11 +24,6 @@ class _WebHook(BaseModel):
return url
-class _FormMeta(BaseModel):
- """Schema model for form meta data."""
- webhook: _WebHook = None
-
-
class Form(BaseModel):
"""Schema model for form."""
@@ -37,7 +32,7 @@ class Form(BaseModel):
questions: list[Question]
name: str
description: str
- meta: _FormMeta = _FormMeta()
+ webhook: _WebHook = None
class Config:
allow_population_by_field_name = True
@@ -124,7 +119,6 @@ async def validate_hook_url(url: str) -> t.Optional[ValidationError]:
await validate()
except Exception as e:
loc = (
- Meta.__name__.lower(),
WebHook.__name__.lower(),
WebHook.URL.value
)
diff --git a/backend/routes/forms/index.py b/backend/routes/forms/index.py
index 0e1dee8..5fd90ab 100644
--- a/backend/routes/forms/index.py
+++ b/backend/routes/forms/index.py
@@ -6,7 +6,7 @@ from starlette.authentication import requires
from starlette.requests import Request
from starlette.responses import JSONResponse
-from backend.constants import Meta, WebHook
+from backend.constants import WebHook
from backend.models import Form, FormList
from backend.models.form import validate_hook_url
from backend.route import Route
@@ -51,8 +51,7 @@ class FormsList(Route):
# Verify Webhook
try:
# Get url from request
- path = (Meta.__name__.lower(), WebHook.__name__.lower(), WebHook.URL.value)
- url = form_data[path[0]][path[1]][path[2]]
+ url = form_data[WebHook.__name__.lower()][WebHook.URL.value]
# Validate URL
validation = await validate_hook_url(url)
diff --git a/backend/routes/forms/submit.py b/backend/routes/forms/submit.py
index 82caa81..8588a2d 100644
--- a/backend/routes/forms/submit.py
+++ b/backend/routes/forms/submit.py
@@ -155,7 +155,7 @@ class SubmitForm(Route):
) -> None:
"""Helper to send a submission message to a discord webhook."""
# Stop if webhook is not available
- if form.meta.webhook is None:
+ if form.webhook is None:
raise ValueError("Got empty webhook.")
try:
@@ -190,7 +190,7 @@ class SubmitForm(Route):
}
# Set hook message
- message = form.meta.webhook.message
+ message = form.webhook.message
if message:
# Available variables, see SCHEMA.md
ctx = {
@@ -208,5 +208,5 @@ class SubmitForm(Route):
# Post hook
async with httpx.AsyncClient() as client:
- r = await client.post(form.meta.webhook.url, json=hook)
+ r = await client.post(form.webhook.url, json=hook)
r.raise_for_status()