diff options
author | 2020-12-22 14:23:47 +0200 | |
---|---|---|
committer | 2020-12-22 14:23:47 +0200 | |
commit | feb798140af684e724acb0cfcaca8626973eccfb (patch) | |
tree | 2023ef4b3b1dda0e85cd7c8476fa4df06b04cb4c /backend/routes/admin.py | |
parent | Merge pull request #43 from python-discord/modify-patch-behavior (diff) |
Create route for adding new admins
Diffstat (limited to 'backend/routes/admin.py')
-rw-r--r-- | backend/routes/admin.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/backend/routes/admin.py b/backend/routes/admin.py new file mode 100644 index 0000000..ef01fbd --- /dev/null +++ b/backend/routes/admin.py @@ -0,0 +1,31 @@ +""" +Adds new admin user. +""" +from spectree import Response +from starlette.authentication import requires +from starlette.requests import Request +from starlette.responses import JSONResponse + +from backend.route import Route +from backend.validation import ErrorMessage, OkayResponse, api + + +class AdminRoute(Route): + """Adds new admin user.""" + + name = "admin" + path = "/admin" + + @requires(["authenticated", "admin"]) + @api.validate( + resp=Response(HTTP_200=OkayResponse, HTTP_400=ErrorMessage), + tags=["admin"] + ) + async def post(self, request: Request) -> JSONResponse: + """Inserts new administrator user to DB.""" + data = await request.json() + if "id" not in data: + return JSONResponse({"error": "missing_id"}, status_code=400) + + await request.state.db.admins.insert_one({"_id": str(data["id"])}) + return JSONResponse({"status": "ok"}) |