From 4c18eb0b34b733f2b02f96dbb6141dd44d8fab0f Mon Sep 17 00:00:00 2001 From: Tiago vasconcelos Date: Wed, 9 Feb 2022 10:57:24 +0000 Subject: [PATCH 1/4] fix disapearing admin extension --- lnbits/core/crud.py | 14 ++++++++------ lnbits/core/views/generic.py | 4 +--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lnbits/core/crud.py b/lnbits/core/crud.py index ad2d9f2cc..3066b124d 100644 --- a/lnbits/core/crud.py +++ b/lnbits/core/crud.py @@ -1,15 +1,15 @@ -import json import datetime -from uuid import uuid4 -from typing import List, Optional, Dict, Any +import json +from typing import Any, Dict, List, Optional from urllib.parse import urlparse +from uuid import uuid4 from lnbits import bolt11 -from lnbits.db import Connection, POSTGRES, COCKROACH -from lnbits.settings import DEFAULT_WALLET_NAME +from lnbits.db import COCKROACH, POSTGRES, Connection +from lnbits.settings import DEFAULT_WALLET_NAME, LNBITS_ADMIN_USERS from . import db -from .models import User, Wallet, Payment, BalanceCheck +from .models import BalanceCheck, Payment, User, Wallet # accounts # -------- @@ -53,6 +53,7 @@ async def get_user(user_id: str, conn: Optional[Connection] = None) -> Optional[ """, (user_id,), ) + else: return None @@ -61,6 +62,7 @@ async def get_user(user_id: str, conn: Optional[Connection] = None) -> Optional[ email=user["email"], extensions=[e[0] for e in extensions], wallets=[Wallet(**w) for w in wallets], + admin=LNBITS_ADMIN_USERS and user["id"] in LNBITS_ADMIN_USERS ) diff --git a/lnbits/core/views/generic.py b/lnbits/core/views/generic.py index d917ffab8..d2fd8f412 100644 --- a/lnbits/core/views/generic.py +++ b/lnbits/core/views/generic.py @@ -15,8 +15,8 @@ from lnbits.core.models import User from lnbits.decorators import check_user_exists from lnbits.helpers import template_renderer, url_for from lnbits.settings import ( - LNBITS_ALLOWED_USERS, LNBITS_ADMIN_USERS, + LNBITS_ALLOWED_USERS, LNBITS_SITE_TITLE, SERVICE_FEE, ) @@ -118,8 +118,6 @@ async def wallet( return template_renderer().TemplateResponse( "error.html", {"request": request, "err": "User not authorized."} ) - if LNBITS_ADMIN_USERS and user_id in LNBITS_ADMIN_USERS: - user.admin = True if not wallet_id: if user.wallets and not wallet_name: wallet = user.wallets[0] From d1d62583c4a47e73594c5876632faf825d440f3e Mon Sep 17 00:00:00 2001 From: Tiago vasconcelos Date: Wed, 9 Feb 2022 11:16:13 +0000 Subject: [PATCH 2/4] fix for whitespace in admin users list --- lnbits/core/crud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lnbits/core/crud.py b/lnbits/core/crud.py index 3066b124d..e1539212e 100644 --- a/lnbits/core/crud.py +++ b/lnbits/core/crud.py @@ -62,7 +62,7 @@ async def get_user(user_id: str, conn: Optional[Connection] = None) -> Optional[ email=user["email"], extensions=[e[0] for e in extensions], wallets=[Wallet(**w) for w in wallets], - admin=LNBITS_ADMIN_USERS and user["id"] in LNBITS_ADMIN_USERS + admin=LNBITS_ADMIN_USERS and user["id"] in [x.strip() for x in LNBITS_ADMIN_USERS] ) From da6a2e772b5624125cafe28409407949a78718bf Mon Sep 17 00:00:00 2001 From: Arc <33088785+arcbtc@users.noreply.github.com> Date: Thu, 10 Feb 2022 09:56:02 +0000 Subject: [PATCH 3/4] Revert "fix disapearing admin extension" --- lnbits/core/crud.py | 14 ++++++-------- lnbits/core/views/generic.py | 4 +++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lnbits/core/crud.py b/lnbits/core/crud.py index e1539212e..ad2d9f2cc 100644 --- a/lnbits/core/crud.py +++ b/lnbits/core/crud.py @@ -1,15 +1,15 @@ -import datetime import json -from typing import Any, Dict, List, Optional -from urllib.parse import urlparse +import datetime from uuid import uuid4 +from typing import List, Optional, Dict, Any +from urllib.parse import urlparse from lnbits import bolt11 -from lnbits.db import COCKROACH, POSTGRES, Connection -from lnbits.settings import DEFAULT_WALLET_NAME, LNBITS_ADMIN_USERS +from lnbits.db import Connection, POSTGRES, COCKROACH +from lnbits.settings import DEFAULT_WALLET_NAME from . import db -from .models import BalanceCheck, Payment, User, Wallet +from .models import User, Wallet, Payment, BalanceCheck # accounts # -------- @@ -53,7 +53,6 @@ async def get_user(user_id: str, conn: Optional[Connection] = None) -> Optional[ """, (user_id,), ) - else: return None @@ -62,7 +61,6 @@ async def get_user(user_id: str, conn: Optional[Connection] = None) -> Optional[ email=user["email"], extensions=[e[0] for e in extensions], wallets=[Wallet(**w) for w in wallets], - admin=LNBITS_ADMIN_USERS and user["id"] in [x.strip() for x in LNBITS_ADMIN_USERS] ) diff --git a/lnbits/core/views/generic.py b/lnbits/core/views/generic.py index d2fd8f412..d917ffab8 100644 --- a/lnbits/core/views/generic.py +++ b/lnbits/core/views/generic.py @@ -15,8 +15,8 @@ from lnbits.core.models import User from lnbits.decorators import check_user_exists from lnbits.helpers import template_renderer, url_for from lnbits.settings import ( - LNBITS_ADMIN_USERS, LNBITS_ALLOWED_USERS, + LNBITS_ADMIN_USERS, LNBITS_SITE_TITLE, SERVICE_FEE, ) @@ -118,6 +118,8 @@ async def wallet( return template_renderer().TemplateResponse( "error.html", {"request": request, "err": "User not authorized."} ) + if LNBITS_ADMIN_USERS and user_id in LNBITS_ADMIN_USERS: + user.admin = True if not wallet_id: if user.wallets and not wallet_name: wallet = user.wallets[0] From 0f79213b0ffad1972c23424b9e53456bacfb57e3 Mon Sep 17 00:00:00 2001 From: benarc Date: Thu, 10 Feb 2022 10:09:44 +0000 Subject: [PATCH 4/4] Tals admin extension fix --- lnbits/core/crud.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lnbits/core/crud.py b/lnbits/core/crud.py index ad2d9f2cc..61710a722 100644 --- a/lnbits/core/crud.py +++ b/lnbits/core/crud.py @@ -6,7 +6,7 @@ from urllib.parse import urlparse from lnbits import bolt11 from lnbits.db import Connection, POSTGRES, COCKROACH -from lnbits.settings import DEFAULT_WALLET_NAME +from lnbits.settings import DEFAULT_WALLET_NAME, LNBITS_ADMIN_USERS from . import db from .models import User, Wallet, Payment, BalanceCheck @@ -61,6 +61,7 @@ async def get_user(user_id: str, conn: Optional[Connection] = None) -> Optional[ email=user["email"], extensions=[e[0] for e in extensions], wallets=[Wallet(**w) for w in wallets], + admin=LNBITS_ADMIN_USERS and user["id"] in [x.strip() for x in LNBITS_ADMIN_USERS] )