diff --git a/views_api.py b/views_api.py index 3276b04..4ab8cff 100644 --- a/views_api.py +++ b/views_api.py @@ -1344,58 +1344,28 @@ async def api_get_castle_users( wallet: WalletTypeInfo = Depends(require_admin_key), ) -> list[dict]: """ - Get all users who have Castle accounts (receivables, payables, equity, or permissions). - This returns only users who are actively using Castle, not all LNbits users. + Get all users who have configured their wallet in Castle. + These are users who can interact with Castle (submit expenses, receive permissions, etc.). Admin only. """ from lnbits.core.crud.users import get_user - from .crud import get_all_equity_eligible_users - # Get all user-specific accounts (Receivable/Payable/Equity) - all_accounts = await get_all_accounts() - user_accounts = [acc for acc in all_accounts if acc.user_id is not None] + # Get all users who have configured their wallet + user_settings = await get_all_user_wallet_settings() - # Get all users who have permissions - all_permissions = [] - for account in all_accounts: - account_perms = await get_account_permissions(account.id) - all_permissions.extend(account_perms) - - # Get all equity-eligible users - equity_users = await get_all_equity_eligible_users() - - # Collect unique user IDs - user_ids = set() - - # Add users with accounts - for acc in user_accounts: - user_ids.add(acc.user_id) - - # Add users with permissions - for perm in all_permissions: - user_ids.add(perm.user_id) - - # Add equity-eligible users - for equity in equity_users: - user_ids.add(equity.user_id) - - # Build user list with enriched data users = [] - for user_id in user_ids: + for setting in user_settings: # Get user details from core - user = await get_user(user_id) + user = await get_user(setting.id) # Use username if available, otherwise use user_id username = user.username if user and user.username else None - # Get user's wallet setting if exists - user_wallet = await get_user_wallet(user_id) - users.append({ - "id": user_id, - "user_id": user_id, # Compatibility with existing code + "id": setting.id, + "user_id": setting.id, # Compatibility with existing code "username": username, - "user_wallet_id": user_wallet.user_wallet_id if user_wallet else None, + "user_wallet_id": setting.user_wallet_id, }) # Sort by username (None values last)