mud_server.admin_gradio.tabs.database_tab
Database Tab for MUD Client.
This module provides the database viewer and user management interface. Visible only for admin and superuser roles.
- Migration Notes:
Migrated from old api_client.py to new modular structure
Uses AdminAPIClient for all database operations
Wrapper functions extract session_id and role from session_state
Returns message string for Gradio display
Parameter order changed: session_id and role now come first
Functions
|
Fetch and format all players from database (Admin/Superuser only). |
|
Fetch and format all active sessions from database (Admin/Superuser only). |
|
Fetch and format recent chat messages from database (Admin/Superuser only). |
|
Perform user management actions (Admin/Superuser only). |
|
Create the Database tab with viewer and management interface. |
Module Contents
- mud_server.admin_gradio.tabs.database_tab.get_database_players(session_state)[source]
Fetch and format all players from database (Admin/Superuser only).
Sends request to backend via AdminAPIClient and returns formatted player table.
This function wraps the new AdminAPIClient.get_database_players() method to maintain compatibility with the Gradio interface while using the new modular API.
- Parameters:
session_state (dict) – User’s session state dictionary containing session_id and role
- Returns:
Formatted multi-line string with player database contents
- Return type:
Examples
>>> session = {"session_id": "admin123", "role": "admin", "logged_in": True} >>> result = get_database_players(session) >>> isinstance(result, str) True
- mud_server.admin_gradio.tabs.database_tab.get_database_sessions(session_state)[source]
Fetch and format all active sessions from database (Admin/Superuser only).
Sends request to backend via AdminAPIClient and returns formatted sessions table.
This function wraps the new AdminAPIClient.get_database_sessions() method to maintain compatibility with the Gradio interface while using the new modular API.
- Parameters:
session_state (dict) – User’s session state dictionary containing session_id and role
- Returns:
Formatted multi-line string with sessions database contents
- Return type:
Examples
>>> session = {"session_id": "admin123", "role": "admin", "logged_in": True} >>> result = get_database_sessions(session) >>> isinstance(result, str) True
- mud_server.admin_gradio.tabs.database_tab.get_database_chat(limit, session_state)[source]
Fetch and format recent chat messages from database (Admin/Superuser only).
Sends request to backend via AdminAPIClient and returns formatted chat history.
This function wraps the new AdminAPIClient.get_database_chat() method to maintain compatibility with the Gradio interface while using the new modular API.
Note: Parameter order is maintained from old API (limit, session_state) for compatibility with existing Gradio event handlers.
- Parameters:
- Returns:
Formatted multi-line string with recent chat messages
- Return type:
Examples
>>> session = {"session_id": "admin123", "role": "admin", "logged_in": True} >>> result = get_database_chat(100, session) >>> isinstance(result, str) True
- mud_server.admin_gradio.tabs.database_tab.manage_user(target_username, action, new_role, session_state)[source]
Perform user management actions (Admin/Superuser only).
Supported actions: - change_role: Change user’s role (requires new_role parameter) - ban: Ban/deactivate user account - unban: Unban/reactivate user account
Sends request to backend via AdminAPIClient and returns result message.
This function wraps the new AdminAPIClient.manage_user() method to maintain compatibility with the Gradio interface while using the new modular API.
Note: Parameter order is maintained from old API for compatibility with existing Gradio event handlers.
- Parameters:
- Returns:
Status message string indicating success or failure
- Return type:
Examples
>>> session = {"session_id": "admin123", "role": "admin", "logged_in": True} >>> result = manage_user("alice", "change_role", "worldbuilder", session) >>> isinstance(result, str) True