Create super user account if it does not exist (#1688)

* fix: temp create account for `super_user_id` if missing

* chore: remove dumb import

* refactor: move logic outside `crud`

* feat: add uuid4 conversion

* fix: require valid string in .env file

* fix: update the `settings.super_user` value in case or normalisation for UUID4

* fix: allow long super_user

* chore: code format

* fix: add UI redirect with the normalized user

* fix: normalize `super_user` up one level

* fix: should normalize user in non-ui mode also
This commit is contained in:
Vlad Stan
2023-05-09 09:22:19 +01:00
committed by GitHub
parent 132d8a9320
commit 67d8b67ee5
4 changed files with 37 additions and 5 deletions
+10 -3
View File
@@ -2,7 +2,7 @@ import datetime
import json
from typing import Any, Dict, List, Optional
from urllib.parse import urlparse
from uuid import uuid4
from uuid import UUID, uuid4
import shortuuid
@@ -18,8 +18,15 @@ from .models import BalanceCheck, Payment, PaymentFilters, TinyURL, User, Wallet
# --------
async def create_account(conn: Optional[Connection] = None) -> User:
user_id = uuid4().hex
async def create_account(
conn: Optional[Connection] = None, user_id: Optional[str] = None
) -> User:
if user_id:
user_uuid4 = UUID(hex=user_id, version=4)
assert user_uuid4.hex == user_id, "User ID is not valid UUID4 hex string"
else:
user_id = uuid4().hex
await (conn or db).execute("INSERT INTO accounts (id) VALUES (?)", (user_id,))
new_account = await get_account(user_id=user_id, conn=conn)