From a07fbf0187c72b45e0e102951faf3ed6cbfb75fc Mon Sep 17 00:00:00 2001 From: Tiago vasconcelos Date: Mon, 18 Apr 2022 14:25:06 +0100 Subject: [PATCH] allow user settings without restart --- lnbits/core/views/generic.py | 7 ++++++- lnbits/decorators.py | 8 ++++++++ lnbits/helpers.py | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lnbits/core/views/generic.py b/lnbits/core/views/generic.py index 31a7b0300..83648c444 100644 --- a/lnbits/core/views/generic.py +++ b/lnbits/core/views/generic.py @@ -15,7 +15,9 @@ from lnbits.core import db from lnbits.core.models import User from lnbits.decorators import check_user_exists from lnbits.helpers import template_renderer, url_for +from lnbits.requestvars import g from lnbits.settings import ( + LNBITS_ADMIN_UI, LNBITS_ADMIN_USERS, LNBITS_ALLOWED_USERS, LNBITS_CUSTOM_LOGO, @@ -37,7 +39,6 @@ from ..services import pay_invoice, redeem_lnurl_withdraw core_html_routes: APIRouter = APIRouter(tags=["Core NON-API Website Routes"]) - @core_html_routes.get("/favicon.ico", response_class=FileResponse) async def favicon(): return FileResponse("lnbits/core/static/favicon.ico") @@ -119,6 +120,10 @@ async def wallet( wallet_name = nme service_fee = int(SERVICE_FEE) if int(SERVICE_FEE) == SERVICE_FEE else SERVICE_FEE + if LNBITS_ADMIN_UI: + LNBITS_ADMIN_USERS = g().admin_conf.admin_users + LNBITS_ALLOWED_USERS = g().admin_conf.allowed_users + if not user_id: user = await get_user((await create_account()).id) logger.info(f"Create user {user.id}") # type: ignore diff --git a/lnbits/decorators.py b/lnbits/decorators.py index d4aa63aea..f951163f8 100644 --- a/lnbits/decorators.py +++ b/lnbits/decorators.py @@ -16,6 +16,7 @@ from lnbits.core.models import User, Wallet from lnbits.requestvars import g from lnbits.settings import ( LNBITS_ADMIN_EXTENSIONS, + LNBITS_ADMIN_UI, LNBITS_ADMIN_USERS, LNBITS_ALLOWED_USERS, ) @@ -138,6 +139,9 @@ async def get_key_type( detail="Invoice (or Admin) key required.", ) + if LNBITS_ADMIN_UI: + LNBITS_ADMIN_USERS = g().admin_conf.admin_users + for typenr, WalletChecker in zip( [0, 1], [WalletAdminKeyChecker, WalletInvoiceKeyChecker] ): @@ -231,6 +235,10 @@ async def check_user_exists(usr: UUID4) -> User: raise HTTPException( status_code=HTTPStatus.NOT_FOUND, detail="User does not exist." ) + + if LNBITS_ADMIN_UI: + LNBITS_ADMIN_USERS = g().admin_conf.admin_users + LNBITS_ALLOWED_USERS = g().admin_conf.allowed_users if LNBITS_ALLOWED_USERS and g().user.id not in LNBITS_ALLOWED_USERS: raise HTTPException( diff --git a/lnbits/helpers.py b/lnbits/helpers.py index e456f7150..1167143f8 100644 --- a/lnbits/helpers.py +++ b/lnbits/helpers.py @@ -24,6 +24,9 @@ class Extension(NamedTuple): class ExtensionManager: def __init__(self): + if settings.LNBITS_ADMIN_UI: + settings.LNBITS_DISABLED_EXTENSIONS = g().admin_conf.disabled_ext + settings.LNBITS_ADMIN_EXTENSIONS = g().admin_conf.admin_ext self._disabled: List[str] = settings.LNBITS_DISABLED_EXTENSIONS self._admin_only: List[str] = [ x.strip(" ") for x in settings.LNBITS_ADMIN_EXTENSIONS