Skip to content

Commit

Permalink
fix: admin check (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
motorina0 authored Mar 21, 2024
1 parent 473614f commit 94ae341
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pydantic.types import UUID4
from starlette.responses import JSONResponse

from lnbits.core.crud import get_user
from lnbits.core.services import create_invoice
from lnbits.decorators import (
WalletTypeInfo,
Expand Down Expand Up @@ -60,7 +61,9 @@ async def api_create_relay(
wallet: WalletTypeInfo = Depends(require_admin_key),
) -> NostrRelay:
if len(data.id):
await check_admin(UUID4(wallet.wallet.user))
user = await get_user(wallet.wallet.user)
assert user, "User not found."
assert user.admin, "Only admin users can set the relay ID"
else:
data.id = urlsafe_short_hash()[:8]

Expand Down Expand Up @@ -195,7 +198,7 @@ async def api_create_or_update_account(

try:
data.pubkey = normalize_public_key(data.pubkey)

account = await get_account(data.relay_id, data.pubkey)
if not account:
account = NostrAccount(
Expand All @@ -209,7 +212,7 @@ async def api_create_or_update_account(
account.blocked = data.blocked
if data.allowed is not None:
account.allowed = data.allowed

return await update_account(data.relay_id, account)

except ValueError as ex:
Expand Down

0 comments on commit 94ae341

Please sign in to comment.