Skip to content

Commit 3593ec7

Browse files
committed
Validate unique responses on submission
1 parent a0eeff1 commit 3593ec7

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

backend/routes/forms/submit.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,22 @@ async def submit(self, request: Request) -> JSONResponse:
170170
else:
171171
return JSONResponse({"error": "missing_discord_data"}, status_code=400)
172172

173+
if constants.FormFeatures.UNIQUE_RESPONDER.value in form.features:
174+
if not request.user.is_authenticated:
175+
return JSONResponse({"error": "missing_discord_data"}, status_code=400)
176+
177+
existing_response = await request.state.db.responses.find_one(
178+
{
179+
"form_id": form.id,
180+
"user.id": request.user.payload["id"],
181+
},
182+
)
183+
if existing_response:
184+
return JSONResponse(
185+
{"error": "unique_responder", "message": "You have already submitted this form."},
186+
status_code=400,
187+
)
188+
173189
missing_fields = []
174190
for question in form.questions:
175191
if question.id not in response["response"]:

0 commit comments

Comments
 (0)