fix: create default wallet for auto created super_user
This commit is contained in:
parent
d596992993
commit
1751831e57
2 changed files with 23 additions and 13 deletions
|
|
@ -591,16 +591,7 @@ async def update_super_user(super_user: str):
|
||||||
return await get_super_settings()
|
return await get_super_settings()
|
||||||
|
|
||||||
|
|
||||||
async def init_admin_settings(super_user: str = None):
|
async def create_admin_settings(super_user: str, new_settings: dict):
|
||||||
user = None
|
|
||||||
if super_user:
|
|
||||||
user = await get_account(super_user)
|
|
||||||
if not user:
|
|
||||||
account = await create_account()
|
|
||||||
super_user = account.id
|
|
||||||
|
|
||||||
editable_settings = EditableSetings.from_dict(settings.dict())
|
|
||||||
|
|
||||||
sql = f"INSERT INTO settings (super_user, editable_settings) VALUES (?, ?)"
|
sql = f"INSERT INTO settings (super_user, editable_settings) VALUES (?, ?)"
|
||||||
await db.execute(sql, (super_user, json.dumps(editable_settings.dict())))
|
await db.execute(sql, (super_user, json.dumps(new_settings)))
|
||||||
return await get_super_settings()
|
return await get_super_settings()
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ from typing import Dict, List, Optional, Tuple
|
||||||
from urllib.parse import parse_qs, urlparse
|
from urllib.parse import parse_qs, urlparse
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from fastapi import Depends, WebSocket, WebSocketDisconnect
|
from fastapi import Depends, WebSocket
|
||||||
from lnurl import LnurlErrorResponse
|
from lnurl import LnurlErrorResponse
|
||||||
from lnurl import decode as decode_lnurl # type: ignore
|
from lnurl import decode as decode_lnurl # type: ignore
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
@ -23,6 +23,7 @@ from lnbits.helpers import url_for, urlsafe_short_hash
|
||||||
from lnbits.requestvars import g
|
from lnbits.requestvars import g
|
||||||
from lnbits.settings import (
|
from lnbits.settings import (
|
||||||
FAKE_WALLET,
|
FAKE_WALLET,
|
||||||
|
EditableSetings,
|
||||||
get_wallet_class,
|
get_wallet_class,
|
||||||
readonly_variables,
|
readonly_variables,
|
||||||
send_admin_user_to_saas,
|
send_admin_user_to_saas,
|
||||||
|
|
@ -33,12 +34,15 @@ from lnbits.wallets.base import PaymentResponse, PaymentStatus
|
||||||
from . import db
|
from . import db
|
||||||
from .crud import (
|
from .crud import (
|
||||||
check_internal,
|
check_internal,
|
||||||
|
create_account,
|
||||||
|
create_admin_settings,
|
||||||
create_payment,
|
create_payment,
|
||||||
|
create_wallet,
|
||||||
delete_wallet_payment,
|
delete_wallet_payment,
|
||||||
|
get_account,
|
||||||
get_super_settings,
|
get_super_settings,
|
||||||
get_wallet,
|
get_wallet,
|
||||||
get_wallet_payment,
|
get_wallet_payment,
|
||||||
init_admin_settings,
|
|
||||||
update_payment_details,
|
update_payment_details,
|
||||||
update_payment_status,
|
update_payment_status,
|
||||||
update_super_user,
|
update_super_user,
|
||||||
|
|
@ -460,6 +464,21 @@ def update_cached_settings(sets_dict: dict):
|
||||||
setattr(settings, "super_user", sets_dict["super_user"])
|
setattr(settings, "super_user", sets_dict["super_user"])
|
||||||
|
|
||||||
|
|
||||||
|
async def init_admin_settings(super_user: str = None):
|
||||||
|
account = None
|
||||||
|
if super_user:
|
||||||
|
account = await get_account(super_user)
|
||||||
|
if not account:
|
||||||
|
account = await create_account()
|
||||||
|
super_user = account.id
|
||||||
|
if not account.wallets or len(account.wallets) == 0:
|
||||||
|
await create_wallet(user_id=account.id)
|
||||||
|
|
||||||
|
editable_settings = EditableSetings.from_dict(settings.dict())
|
||||||
|
|
||||||
|
return await create_admin_settings(account.id, editable_settings.dict())
|
||||||
|
|
||||||
|
|
||||||
class WebsocketConnectionManager:
|
class WebsocketConnectionManager:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.active_connections: List[WebSocket] = []
|
self.active_connections: List[WebSocket] = []
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue