diff options
author | 2021-05-17 20:14:18 +0300 | |
---|---|---|
committer | 2021-05-17 20:14:18 +0300 | |
commit | 269b6d3fbb098e290a2a6e236b77a32fa0440976 (patch) | |
tree | 8a57cc86e0cbe55dfd45da4be779430508ae86ac /backend/routes/forms/discover.py | |
parent | Merge pull request #89 from python-discord/admin_endpoint (diff) |
Adds An Empty Form For Authorization
Returns a form with no questions, if the server is not running in
production, and no other forms are found, to aid in setting up.
Signed-off-by: Hassan Abouelela <[email protected]>
Diffstat (limited to 'backend/routes/forms/discover.py')
-rw-r--r-- | backend/routes/forms/discover.py | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/backend/routes/forms/discover.py b/backend/routes/forms/discover.py index c4711aa..d7351d5 100644 --- a/backend/routes/forms/discover.py +++ b/backend/routes/forms/discover.py @@ -5,10 +5,33 @@ from spectree.response import Response from starlette.requests import Request from starlette.responses import JSONResponse -from backend.models import Form, FormList +from backend import constants +from backend.models import Form, FormList, Question from backend.route import Route from backend.validation import api +__FEATURES = [ + constants.FormFeatures.DISCOVERABLE.value, + constants.FormFeatures.OPEN.value, + constants.FormFeatures.REQUIRES_LOGIN.value +] + +__QUESTION = Question( + id="description", + name="Check your cookies after pressing the button.", + type="section", + data={"text": "You can find cookies under \"Application\" in dev tools."}, + required=False +) + +EMPTY_FORM = Form( + id="empty_auth", + features=__FEATURES, + questions=[__QUESTION], + name="Auth form", + description="An empty form to help you get a token." +) + class DiscoverableFormsList(Route): """ @@ -31,6 +54,8 @@ class DiscoverableFormsList(Route): forms = [form.dict(admin=False) for form in forms] - return JSONResponse( - forms - ) + # Return an empty form in development environments to help with authentication. + if not forms and not constants.PRODUCTION: + forms.append(EMPTY_FORM.dict(admin=False)) + + return JSONResponse(forms) |