blob: ef01fbd65d7807a1b6e678cdda05b686c7a56c76 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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"})
|