creating first admin and update restrictions for ordinary users

This commit is contained in:
2026-03-04 17:06:43 +03:00
parent 08e48aac29
commit ea06c16aac
16 changed files with 128 additions and 58 deletions

34
run.py
View File

@@ -1,4 +1,7 @@
from server.backend.schema.pydantic import settings
from server.backend.database.db import create_user, list_users
from server.backend.schema.pydantic import UserCreate
import asyncio
import uvicorn
def start(log_level:str):
if __name__ == "__main__":
@@ -11,18 +14,33 @@ def start(log_level:str):
access_log=True
)
import argparse
parser = argparse.ArgumentParser(description="logging")
parser = argparse.ArgumentParser(description="logging and admin creation")
parser.add_argument(
"--mode",
choices=["debug","info"],
default="info",
help="Режим логирования (по умолчанию: info)"
)
parser.add_argument(
"--user_name",
type=str,
required=True,
help="Создание первого пользователя)"
)
args = parser.parse_args()
match args.mode:
case "debug":
print("Режим:", args.mode)
start(args.mode)
case "info":
print("Режим:", args.mode)
start(args.mode)
async def arguments(args):
admin_user = {
"code": "123456",
"name": args.user_name,
"surname": args.user_name,
"admin": True
}
users = await list_users()
label = any(u.admin for u in users)
if not label:
await create_user(UserCreate(**admin_user))
match args.mode:
case "debug" | "info":
print("Режим:", args.mode)
start(args.mode)
asyncio.run(arguments(args))