From c14a4e322d3a8974b57805b4a83267e7afde2c3f Mon Sep 17 00:00:00 2001 From: Jage9 Date: Sun, 8 Mar 2026 19:40:18 -0400 Subject: [PATCH] Extract server UI metadata definitions --- server/app/server.py | 43 ++------------- server/app/ui_metadata.py | 113 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 38 deletions(-) create mode 100644 server/app/ui_metadata.py diff --git a/server/app/server.py b/server/app/server.py index 46e53af..cc5c2c5 100644 --- a/server/app/server.py +++ b/server/app/server.py @@ -107,6 +107,11 @@ from .models import ( WelcomePacket, WorldItem, ) +from .ui_metadata import ( + ADMIN_MENU_ACTION_DEFINITIONS, + ITEM_MANAGEMENT_ACTION_DEFINITIONS, + MAIN_MODE_SERVER_COMMAND_DEFINITIONS, +) LOGGER = logging.getLogger("chgrid.server") PACKET_LOGGER = logging.getLogger("chgrid.server.packet") @@ -133,44 +138,6 @@ AUTH_SESSION_COOKIE_CLEAR_PATH = "/auth/session/clear" AUTH_SESSION_COOKIE_CLIENT_HEADER = "X-Chgrid-Auth-Client" AUTH_LOGIN_FAILURE_MESSAGE = "We couldn't log you in. Check your details and try again." AUTH_RESUME_FAILURE_MESSAGE = "We couldn't restore your session. Please log in again." -ADMIN_MENU_ACTION_DEFINITIONS: tuple[dict[str, str], ...] = ( - {"id": "manage_roles", "label": "Role management", "tooltip": "Manage roles and their permission sets.", "permission": "role.manage"}, - {"id": "change_user_role", "label": "Change user role", "tooltip": "Change a user's assigned role.", "permission": "user.change_role"}, - {"id": "ban_user", "label": "Ban user", "tooltip": "Disable a user account.", "permission": "user.ban_unban"}, - {"id": "unban_user", "label": "Unban user", "tooltip": "Re-enable a disabled user account.", "permission": "user.ban_unban"}, - {"id": "delete_account", "label": "Delete account", "tooltip": "Delete a user account permanently.", "permission": "account.delete.any"}, -) - -ITEM_MANAGEMENT_ACTION_DEFINITIONS: tuple[dict[str, str], ...] = ( - { - "id": "transfer", - "label": "Transfer item", - "tooltip": "Transfer this item to another user.", - "anyPermission": "item.transfer.any", - "ownPermission": "item.transfer.own", - }, - { - "id": "delete", - "label": "Delete item", - "tooltip": "Delete this item from the world.", - "anyPermission": "item.delete.any", - "ownPermission": "item.delete.own", - }, -) - -MAIN_MODE_SERVER_COMMAND_DEFINITIONS: tuple[dict[str, str], ...] = ( - {"id": "addItem", "label": "Add item", "tooltip": "Open the add-item menu."}, - {"id": "useItem", "label": "Use item", "tooltip": "Use the carried item or a usable item on your current square."}, - { - "id": "secondaryUseItem", - "label": "Secondary item action", - "tooltip": "Run the secondary action for the carried item or a usable item on your current square.", - }, - {"id": "pickupDropItem", "label": "Pick up or drop item", "tooltip": "Pick up an item or drop your carried item."}, - {"id": "openItemManagement", "label": "Item management", "tooltip": "Open item management actions for items on your square."}, - {"id": "editItem", "label": "Edit item properties", "tooltip": "Edit the carried item or an item on your current square."}, - {"id": "inspectItem", "label": "Inspect item properties", "tooltip": "Inspect all properties for the carried item or an item on your current square."}, -) class SignalingServer: diff --git a/server/app/ui_metadata.py b/server/app/ui_metadata.py new file mode 100644 index 0000000..cc30db3 --- /dev/null +++ b/server/app/ui_metadata.py @@ -0,0 +1,113 @@ +"""Server-owned UI metadata for menus and server-backed command surfaces.""" + +from __future__ import annotations + +from typing import TypedDict + + +class AdminMenuActionDefinition(TypedDict): + """Server-authored metadata for one admin root action.""" + + id: str + label: str + tooltip: str + permission: str + + +class ItemManagementActionDefinition(TypedDict): + """Server-authored metadata for one item-management action.""" + + id: str + label: str + tooltip: str + anyPermission: str + ownPermission: str + + +class MainModeServerCommandDefinition(TypedDict): + """Server-authored metadata for one server-backed main-mode command.""" + + id: str + label: str + tooltip: str + + +ADMIN_MENU_ACTION_DEFINITIONS: tuple[AdminMenuActionDefinition, ...] = ( + { + "id": "manage_roles", + "label": "Role management", + "tooltip": "Manage roles and their permission sets.", + "permission": "role.manage", + }, + { + "id": "change_user_role", + "label": "Change user role", + "tooltip": "Change a user's assigned role.", + "permission": "user.change_role", + }, + { + "id": "ban_user", + "label": "Ban user", + "tooltip": "Disable a user account.", + "permission": "user.ban_unban", + }, + { + "id": "unban_user", + "label": "Unban user", + "tooltip": "Re-enable a disabled user account.", + "permission": "user.ban_unban", + }, + { + "id": "delete_account", + "label": "Delete account", + "tooltip": "Delete a user account permanently.", + "permission": "account.delete.any", + }, +) + +ITEM_MANAGEMENT_ACTION_DEFINITIONS: tuple[ItemManagementActionDefinition, ...] = ( + { + "id": "transfer", + "label": "Transfer item", + "tooltip": "Transfer this item to another user.", + "anyPermission": "item.transfer.any", + "ownPermission": "item.transfer.own", + }, + { + "id": "delete", + "label": "Delete item", + "tooltip": "Delete this item from the world.", + "anyPermission": "item.delete.any", + "ownPermission": "item.delete.own", + }, +) + +MAIN_MODE_SERVER_COMMAND_DEFINITIONS: tuple[MainModeServerCommandDefinition, ...] = ( + {"id": "addItem", "label": "Add item", "tooltip": "Open the add-item menu."}, + {"id": "useItem", "label": "Use item", "tooltip": "Use the carried item or a usable item on your current square."}, + { + "id": "secondaryUseItem", + "label": "Secondary item action", + "tooltip": "Run the secondary action for the carried item or a usable item on your current square.", + }, + { + "id": "pickupDropItem", + "label": "Pick up or drop item", + "tooltip": "Pick up an item or drop your carried item.", + }, + { + "id": "openItemManagement", + "label": "Item management", + "tooltip": "Open item management actions for items on your square.", + }, + { + "id": "editItem", + "label": "Edit item properties", + "tooltip": "Edit the carried item or an item on your current square.", + }, + { + "id": "inspectItem", + "label": "Inspect item properties", + "tooltip": "Inspect all properties for the carried item or an item on your current square.", + }, +)