🐛 Fixed get public quizzes

This commit is contained in:
Mawoka
2022-04-06 20:18:17 +02:00
parent f3fa4f3c06
commit 49a62660c1
2 changed files with 7 additions and 3 deletions
+2 -1
View File
@@ -20,5 +20,6 @@ an issue here on GitHub.
## Want to translate?
Go to [Weblate](https://translate.mawoka.eu/projects/classquiz/frontend/). If the language isn't available, please open
Go to [Weblate](https://translate.mawoka.eu/projects/classquiz/frontend/).
If the language isn't available, please open
an issue here, so I'll be able to add it.
+5 -2
View File
@@ -38,11 +38,14 @@ async def get_quiz_from_id(quiz_id: str, user: User | None = Depends(get_current
raise HTTPException(status_code=400, detail="badly formed quiz id")
if user is None:
quiz = await Quiz.objects.get_or_none(id=quiz_id, public=True)
# TODO: User can't be none
else:
quiz = await Quiz.objects.get_or_none(id=quiz_id, user_id=user.id)
if quiz is None:
return JSONResponse(status_code=404, content={"detail": "quiz not found"})
public_quiz = await Quiz.objects.get_or_none(id=quiz_id, public=True)
if public_quiz is None:
return JSONResponse(status_code=404, content={"detail": "quiz not found"})
else:
return public_quiz
else:
return quiz