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

get_database_players(session_state)

Fetch and format all players from database (Admin/Superuser only).

get_database_sessions(session_state)

Fetch and format all active sessions from database (Admin/Superuser only).

get_database_chat(limit, session_state)

Fetch and format recent chat messages from database (Admin/Superuser only).

manage_user(target_username, action, new_role, ...)

Perform user management actions (Admin/Superuser only).

create(session_state)

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:

str

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:

str

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:
  • limit (int) – Maximum number of messages to retrieve

  • session_state (dict) – User’s session state dictionary containing session_id and role

Returns:

Formatted multi-line string with recent chat messages

Return type:

str

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:
  • target_username (str) – Username of user to manage

  • action (str) – Action to perform (change_role, ban, unban)

  • new_role (str) – New role for change_role action (empty string if not applicable)

  • session_state (dict) – User’s session state dictionary containing session_id and role

Returns:

Status message string indicating success or failure

Return type:

str

Examples

>>> session = {"session_id": "admin123", "role": "admin", "logged_in": True}
>>> result = manage_user("alice", "change_role", "worldbuilder", session)
>>> isinstance(result, str)
True
mud_server.admin_gradio.tabs.database_tab.create(session_state)[source]

Create the Database tab with viewer and management interface.

Parameters:

session_state – Gradio State component for session tracking

Returns:

Configured Database tab component

Return type:

gr.Tab