mud_server.admin_gradio.tabs.database_tab ========================================= .. py:module:: mud_server.admin_gradio.tabs.database_tab .. autoapi-nested-parse:: 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 --------- .. autoapisummary:: mud_server.admin_gradio.tabs.database_tab.get_database_players mud_server.admin_gradio.tabs.database_tab.get_database_sessions mud_server.admin_gradio.tabs.database_tab.get_database_chat mud_server.admin_gradio.tabs.database_tab.manage_user mud_server.admin_gradio.tabs.database_tab.create Module Contents --------------- .. py:function:: get_database_players(session_state) 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. :param session_state: User's session state dictionary containing session_id and role :returns: Formatted multi-line string with player database contents .. admonition:: Examples >>> session = {"session_id": "admin123", "role": "admin", "logged_in": True} >>> result = get_database_players(session) >>> isinstance(result, str) True .. py:function:: get_database_sessions(session_state) 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. :param session_state: User's session state dictionary containing session_id and role :returns: Formatted multi-line string with sessions database contents .. admonition:: Examples >>> session = {"session_id": "admin123", "role": "admin", "logged_in": True} >>> result = get_database_sessions(session) >>> isinstance(result, str) True .. py:function:: get_database_chat(limit, session_state) 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. :param limit: Maximum number of messages to retrieve :param session_state: User's session state dictionary containing session_id and role :returns: Formatted multi-line string with recent chat messages .. admonition:: Examples >>> session = {"session_id": "admin123", "role": "admin", "logged_in": True} >>> result = get_database_chat(100, session) >>> isinstance(result, str) True .. py:function:: manage_user(target_username, action, new_role, session_state) 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. :param target_username: Username of user to manage :param action: Action to perform (change_role, ban, unban) :param new_role: New role for change_role action (empty string if not applicable) :param session_state: User's session state dictionary containing session_id and role :returns: Status message string indicating success or failure .. admonition:: Examples >>> session = {"session_id": "admin123", "role": "admin", "logged_in": True} >>> result = manage_user("alice", "change_role", "worldbuilder", session) >>> isinstance(result, str) True .. py:function:: create(session_state) Create the Database tab with viewer and management interface. :param session_state: Gradio State component for session tracking :returns: Configured Database tab component :rtype: gr.Tab