mud_server.admin_gradio.ui.state
UI state builders for Gradio interface.
This module provides functions that build Gradio UI state updates based on application state. It encapsulates the complex tuple structures returned by various UI operations.
By separating UI state management from API logic, we: - Make API functions testable without Gradio dependencies - Centralize UI update patterns for consistency - Make it easier to modify the UI layout without changing API code
- State Building Pattern:
UI state builders return tuples in a fixed order matching the Gradio component structure. Each builder documents its return tuple structure.
Functions
|
Build UI state for successful login. |
|
Build UI state for logged out user. |
|
Build UI state for failed login attempt. |
|
Check if a role has admin access. |
|
Update session state with login information. |
|
Clear session state on logout. |
Module Contents
- mud_server.admin_gradio.ui.state.build_logged_in_state(session_state, message, has_admin_access=False)[source]
Build UI state for successful login.
When a user logs in successfully, we: - Clear password fields for security - Show game-related tabs - Show admin tabs if user has admin/superuser role - Keep login tab visible to show success message
- Parameters:
- Returns:
- Tuple of (session_state, message, clear_username, clear_password,
login_tab, register_tab, game_tab, settings_tab, db_tab, ollama_tab, help_tab)
- Return type:
- mud_server.admin_gradio.ui.state.build_logged_out_state(session_state, message)[source]
Build UI state for logged out user.
When a user is logged out (or logout fails), we: - Clear sensitive fields - Hide all game and admin tabs - Show only login and register tabs
- mud_server.admin_gradio.ui.state.build_login_failed_state(session_state, error_message)[source]
Build UI state for failed login attempt.
When login fails, we: - Clear password field for security (but preserve username) - Keep login/register tabs visible - Keep all other tabs hidden - Display error message
- mud_server.admin_gradio.ui.state.is_admin_role(role)[source]
Check if a role has admin access.
- Parameters:
role (str) – User role string
- Returns:
True if role is admin or superuser, False otherwise
- Return type:
Examples
>>> is_admin_role("admin") True >>> is_admin_role("superuser") True >>> is_admin_role("player") False >>> is_admin_role("worldbuilder") False
- mud_server.admin_gradio.ui.state.update_session_state(session_state, session_id, username, role, logged_in=True)[source]
Update session state with login information.
This is a pure function that creates a new session state dictionary with updated values.
- Parameters:
- Returns:
Updated session state dictionary
- Return type:
Examples
>>> state = {} >>> new_state = update_session_state(state, "abc123", "alice", "player") >>> new_state["session_id"] 'abc123' >>> new_state["username"] 'alice' >>> new_state["logged_in"] True
- mud_server.admin_gradio.ui.state.clear_session_state(session_state)[source]
Clear session state on logout.
This is a pure function that resets all session fields to None/False.
- Parameters:
session_state (dict) – Current session state dictionary
- Returns:
Cleared session state dictionary
- Return type:
Examples
>>> state = {"session_id": "abc", "username": "alice", "role": "player", "logged_in": True} >>> cleared = clear_session_state(state) >>> cleared["logged_in"] False >>> cleared["session_id"] is None True