mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-26 15:42:30 +01:00
* feat: add shortcuts for insert_query and update_query into `Database` example: await db.insert("table_name", base_model) * remove where from argument * chore: code clean-up * extension manager * lnbits-qrcode components * parse date from dict * refactor: make `settings` a fixture * chore: remove verbose key names * fix: time column * fix: cast balance to `int` * extension toggle vue3 * vue3 @input migration * fix: payment extra and payment hash * fix dynamic fields and ext db migration * remove shadow on cards in dark theme * screwed up and made more css pushes to this branch * attempt to make chip component in settings dynamic fields * dynamic chips * qrscanner * clean init admin settings * make get_user better * add dbversion model * remove update_payment_status/extra/details * traces for value and assertion errors * refactor services * add PaymentFiatAmount * return Payment on api endpoints * rename to get_user_from_account * refactor: just refactor (#2740) * rc5 * Fix db cache (#2741) * [refactor] split services.py (#2742) * refactor: spit `core.py` (#2743) * refactor: make QR more customizable * fix: print.html * fix: qrcode options * fix: white shadow on dark theme * fix: datetime wasnt parsed in dict_to_model * add timezone for conversion * only parse timestamp for sqlite, postgres does it * log internal payment success * fix: export wallet to phone QR * Adding a customisable border theme, like gradient (#2746) * fixed mobile scan btn * fix test websocket * fix get_payments tests * dict_to_model skip none values * preimage none instead of defaulting to 0000... * fixup test real invoice tests * fixed pheonixd for wss * fix nodemanager test settings * fix lnbits funding * only insert extension when they dont exist --------- Co-authored-by: Vlad Stan <stan.v.vlad@gmail.com> Co-authored-by: Tiago Vasconcelos <talvasconcelos@gmail.com> Co-authored-by: Arc <ben@arc.wales> Co-authored-by: Arc <33088785+arcbtc@users.noreply.github.com>
71 lines
2.1 KiB
Python
71 lines
2.1 KiB
Python
import json
|
|
from typing import Optional
|
|
|
|
from lnbits.core.db import db
|
|
from lnbits.settings import (
|
|
AdminSettings,
|
|
EditableSettings,
|
|
SuperSettings,
|
|
settings,
|
|
)
|
|
|
|
|
|
async def get_super_settings() -> Optional[SuperSettings]:
|
|
row: dict = await db.fetchone("SELECT * FROM settings")
|
|
if not row:
|
|
return None
|
|
editable_settings = json.loads(row["editable_settings"])
|
|
return SuperSettings(**{"super_user": row["super_user"], **editable_settings})
|
|
|
|
|
|
async def get_admin_settings(is_super_user: bool = False) -> Optional[AdminSettings]:
|
|
sets = await get_super_settings()
|
|
if not sets:
|
|
return None
|
|
row_dict = dict(sets)
|
|
row_dict.pop("super_user")
|
|
row_dict.pop("auth_all_methods")
|
|
|
|
admin_settings = AdminSettings(
|
|
is_super_user=is_super_user,
|
|
lnbits_allowed_funding_sources=settings.lnbits_allowed_funding_sources,
|
|
**row_dict,
|
|
)
|
|
return admin_settings
|
|
|
|
|
|
async def delete_admin_settings() -> None:
|
|
await db.execute("DELETE FROM settings")
|
|
|
|
|
|
async def update_admin_settings(data: EditableSettings) -> None:
|
|
row: dict = await db.fetchone("SELECT editable_settings FROM settings")
|
|
editable_settings = json.loads(row["editable_settings"]) if row else {}
|
|
editable_settings.update(data.dict(exclude_unset=True))
|
|
await db.execute(
|
|
"UPDATE settings SET editable_settings = :settings",
|
|
{"settings": json.dumps(editable_settings)},
|
|
)
|
|
|
|
|
|
async def update_super_user(super_user: str) -> SuperSettings:
|
|
await db.execute(
|
|
"UPDATE settings SET super_user = :user",
|
|
{"user": super_user},
|
|
)
|
|
settings = await get_super_settings()
|
|
assert settings, "updated super_user settings could not be retrieved"
|
|
return settings
|
|
|
|
|
|
async def create_admin_settings(super_user: str, new_settings: dict):
|
|
await db.execute(
|
|
"""
|
|
INSERT INTO settings (super_user, editable_settings)
|
|
VALUES (:user, :settings)
|
|
""",
|
|
{"user": super_user, "settings": json.dumps(new_settings)},
|
|
)
|
|
settings = await get_super_settings()
|
|
assert settings, "created admin settings could not be retrieved"
|
|
return settings
|