feat: modernize error page (#2949)
* can't figure this out! * raise here so it gets picked up by exceptions * add few more info for error rendering * add a few more checks for browser not fail safe just one more layer * cleaner error display ... hopefully * add go to extension * keep buttons add go to extension * feat: identify extensions that are not installed * fix: status code * fix: full path * add account/logout button if 401 prevent getting stuck * fix: ext access * fix user button * fix: 404 page * fix: json 404 response * fix: dumb rendering * fix: `/api` request always json * fix: extension api path * test: check regtest * test: investgate * something made ws slower? * fix: change error code --------- Co-authored-by: Vlad Stan <stan.v.vlad@gmail.com> Co-authored-by: dni ⚡ <office@dnilabs.com> Co-authored-by: Arc <33088785+arcbtc@users.noreply.github.com>
This commit is contained in:
co-authored by
Vlad Stan
dni ⚡
Arc
parent
eeca7de10d
commit
4511891297
+5
-11
@@ -28,6 +28,7 @@ from lnbits.core.models import (
|
||||
WalletTypeInfo,
|
||||
)
|
||||
from lnbits.db import Connection, Filter, Filters, TFilterModel
|
||||
from lnbits.helpers import path_segments
|
||||
from lnbits.settings import AuthMethods, settings
|
||||
|
||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="api/v1/auth", auto_error=False)
|
||||
@@ -261,18 +262,18 @@ async def check_user_extension_access(
|
||||
success=False, message=f"User not authorized for extension '{ext_id}'."
|
||||
)
|
||||
|
||||
if settings.is_extension_id(ext_id):
|
||||
if settings.is_installed_extension_id(ext_id):
|
||||
ext_ids = await get_user_active_extensions_ids(user_id, conn=conn)
|
||||
if ext_id not in ext_ids:
|
||||
return SimpleStatus(
|
||||
success=False, message=f"User extension '{ext_id}' not enabled."
|
||||
success=False, message=f"Extension '{ext_id}' not enabled."
|
||||
)
|
||||
|
||||
return SimpleStatus(success=True, message="OK")
|
||||
|
||||
|
||||
async def _check_user_extension_access(user_id: str, path: str):
|
||||
ext_id = _path_segments(path)[0]
|
||||
ext_id = path_segments(path)[0]
|
||||
status = await check_user_extension_access(user_id, ext_id)
|
||||
if not status.success:
|
||||
raise HTTPException(
|
||||
@@ -331,16 +332,9 @@ async def _check_account_api_access(
|
||||
if not acl:
|
||||
raise HTTPException(HTTPStatus.FORBIDDEN, "Invalid token id.")
|
||||
|
||||
path = "/" + "/".join(_path_segments(path)[:3])
|
||||
path = "/" + "/".join(path_segments(path)[:3])
|
||||
endpoint = acl.get_endpoint(path)
|
||||
if not endpoint:
|
||||
raise HTTPException(HTTPStatus.FORBIDDEN, "Path not allowed.")
|
||||
if not endpoint.supports_method(method):
|
||||
raise HTTPException(HTTPStatus.FORBIDDEN, "Method not allowed.")
|
||||
|
||||
|
||||
def _path_segments(path: str) -> list[str]:
|
||||
segments = path.split("/")
|
||||
if segments[1] == "upgrades":
|
||||
return segments[3:]
|
||||
return segments[1:]
|
||||
|
||||
Reference in New Issue
Block a user