fix template typos and also update settings in memory after a admin PUT

This commit is contained in:
dni ⚡ 2022-11-30 23:47:52 +01:00
parent e740ad3cf8
commit 86d2780c9f
6 changed files with 12 additions and 19 deletions

View File

@ -232,8 +232,8 @@ async def get_wallet_payment(
async def get_latest_payments_by_extension(ext_name: str, ext_id: str, limit: int = 5):
rows = await db.fetchall(
f"""
SELECT * FROM apipayments
WHERE pending = 'false'
SELECT * FROM apipayments
WHERE pending = 'false'
AND extra LIKE ?
AND extra LIKE ?
ORDER BY time DESC LIMIT {limit}

View File

@ -1,4 +1,4 @@
from typing import List, Optional
from typing import Optional
from lnbits.core.crud import create_payment
from lnbits.helpers import urlsafe_short_hash
@ -7,10 +7,10 @@ from lnbits.tasks import internal_invoice_queue
from . import db
from .models import AdminSettings, UpdateSettings
from lnbits.settings import settings
async def update_wallet_balance(wallet_id: str, amount: int) -> None:
temp_id = f"temp_{urlsafe_short_hash()}"
async def update_wallet_balance(wallet_id: str, amount: int):
internal_id = f"internal_{urlsafe_short_hash()}"
payment = await create_payment(
@ -25,6 +25,8 @@ async def update_wallet_balance(wallet_id: str, amount: int) -> None:
# manually send this for now
await internal_invoice_queue.put(internal_id)
return payment
async def get_settings() -> AdminSettings:
row = await db.fetchone("SELECT * FROM admin.settings")
@ -39,6 +41,7 @@ async def get_settings() -> AdminSettings:
async def update_settings(data: UpdateSettings) -> Optional[Settings]:
fields = []
for key, value in data.dict(exclude_none=True).items():
setattr(settings, key, value)
if not key in read_only_variables:
if type(value) == list:
joined = ",".join(value)
@ -52,7 +55,6 @@ async def update_settings(data: UpdateSettings) -> Optional[Settings]:
fields.append(f"{key} = '{value}'")
q = ", ".join(fields)
print("UPDATE", q)
await db.execute(f"UPDATE admin.settings SET {q}")
row = await db.fetchone("SELECT * FROM admin.settings")
assert row, "Newly updated settings couldn't be retrieved"

View File

@ -3,7 +3,7 @@
<h6 class="q-my-none">User Management</h6>
<br />
<p class="q-my-none">
Super Admin: {% raw %}{{settings.lnbits_admin_users[0]}}{% endraw %}
Super Admin: {{ settings.lnbits_admin_users[0] }}
</p>
<br />
<div>
@ -19,18 +19,16 @@
<q-btn @click="addAdminUser" dense flat icon="add"></q-btn>
</q-input>
<div>
{% raw %}
<q-chip
v-for="user in settings.lnbits_admin_users.slice(1)"
v-for="user in settings.lnbits_admin_users"
:key="user"
removable
@remove="removeAdminUser(user)"
color="primary"
text-color="white"
>
{{ user }}
{{ user.id }}
</q-chip>
{% endraw %}
</div>
<br />
</div>

View File

@ -263,7 +263,7 @@
}
],
[
'LnbitsWallet',
'LNbitsWallet',
{
lnbits_endpoint: {
value: null,

View File

@ -12,7 +12,6 @@ from lnbits.server import server_restart
from .crud import delete_settings, get_settings, update_settings, update_wallet_balance
from lnbits.settings import settings, set_settings
@admin_ext.get(
@ -53,7 +52,6 @@ async def api_update_settings(
data: UpdateSettings = Body(...),
):
settings = await update_settings(data)
set_settings(settings)
if settings:
return {"status": "Success", "settings": settings.dict()}

View File

@ -176,11 +176,6 @@ if not settings.lnbits_admin_ui:
logger.debug(f"{key}: {value}")
def set_settings(**kwargs):
for key, value in kwargs.items():
setattr(settings, key, value)
def set_cli_settings(**kwargs):
for key, value in kwargs.items():
setattr(settings, key, value)