From ffe0a77106287bb874fc95d7d76ef980f1554a85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Sat, 17 Dec 2022 09:49:00 +0100 Subject: [PATCH] fix admin ui only have superuser to topup --- lnbits/core/views/admin_api.py | 64 +++++++++++++++++----------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/lnbits/core/views/admin_api.py b/lnbits/core/views/admin_api.py index 2ceaa4e60..7c057adc7 100644 --- a/lnbits/core/views/admin_api.py +++ b/lnbits/core/views/admin_api.py @@ -15,16 +15,6 @@ from .. import core_app from ..crud import delete_admin_settings, get_admin_settings, update_admin_settings -@core_app.get( - "/admin/api/v1/restart/", - status_code=HTTPStatus.OK, - dependencies=[Depends(check_super_user)], -) -async def api_restart_server() -> dict[str, str]: - server_restart.set() - return {"status": "Success"} - - @core_app.get("/admin/api/v1/settings/") async def api_get_settings( user: User = Depends(check_admin), # type: ignore @@ -33,26 +23,6 @@ async def api_get_settings( return admin_settings -@core_app.put( - "/admin/api/v1/topup/", - status_code=HTTPStatus.OK, - dependencies=[Depends(check_admin)], -) -async def api_topup_balance( - id: str = Body(...), amount: int = Body(...) -) -> dict[str, str]: - try: - await get_wallet(id) - except: - raise HTTPException( - status_code=HTTPStatus.FORBIDDEN, detail="wallet does not exist." - ) - - await update_wallet_balance(wallet_id=id, amount=int(amount)) - - return {"status": "Success"} - - @core_app.put( "/admin/api/v1/settings/", status_code=HTTPStatus.OK, @@ -67,8 +37,38 @@ async def api_update_settings(data: EditableSetings): @core_app.delete( "/admin/api/v1/settings/", status_code=HTTPStatus.OK, - dependencies=[Depends(check_admin)], + dependencies=[Depends(check_super_user)], ) -async def api_delete_settings() -> dict[str, str]: +async def api_delete_settings() -> None: await delete_admin_settings() + server_restart.set() + + +@core_app.get( + "/admin/api/v1/restart/", + status_code=HTTPStatus.OK, + dependencies=[Depends(check_super_user)], +) +async def api_restart_server() -> dict[str, str]: + server_restart.set() + return {"status": "Success"} + + +@core_app.put( + "/admin/api/v1/topup/", + status_code=HTTPStatus.OK, + dependencies=[Depends(check_super_user)], +) +async def api_topup_balance( + id: str = Body(...), amount: int = Body(...) +) -> dict[str, str]: + try: + await get_wallet(id) + except: + raise HTTPException( + status_code=HTTPStatus.FORBIDDEN, detail="wallet does not exist." + ) + + await update_wallet_balance(wallet_id=id, amount=int(amount)) + return {"status": "Success"}