refactor: remove all backward compatibility code across 70 files
Some checks failed
Some checks failed
Clean up 28 backward compatibility instances identified in the codebase. The app is not live, so all shims are replaced with the target architecture: - Remove legacy Inventory.location column (use bin_location exclusively) - Remove dashboard _extract_metric_value helper (use flat metrics dict) - Remove legacy stat field duplicates (total_stores, total_imports, etc.) - Remove 13 re-export shims and class aliases across modules - Remove module-enabling JSON fallback (use PlatformModule junction table) - Remove menu_to_legacy_format() conversion (return dataclasses directly) - Remove title/description from MarketplaceProductBase schema - Clean billing convenience method docstrings - Clean test fixtures and backward-compat comments - Add PlatformModule seeding to init_production.py Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -492,42 +492,6 @@ class MenuDiscoveryService:
|
||||
|
||||
return None
|
||||
|
||||
def menu_to_legacy_format(
|
||||
self,
|
||||
sections: list[DiscoveredMenuSection],
|
||||
) -> dict:
|
||||
"""
|
||||
Convert discovered menu sections to legacy registry format.
|
||||
|
||||
This allows gradual migration by using new discovery with old rendering.
|
||||
|
||||
Args:
|
||||
sections: List of DiscoveredMenuSection
|
||||
|
||||
Returns:
|
||||
Dict in ADMIN_MENU_REGISTRY/STORE_MENU_REGISTRY format
|
||||
"""
|
||||
return {
|
||||
"sections": [
|
||||
{
|
||||
"id": section.id,
|
||||
"label": section.label_key, # Note: key not resolved
|
||||
"super_admin_only": section.is_super_admin_only,
|
||||
"items": [
|
||||
{
|
||||
"id": item.id,
|
||||
"label": item.label_key, # Note: key not resolved
|
||||
"icon": item.icon,
|
||||
"url": item.route,
|
||||
"super_admin_only": item.is_super_admin_only,
|
||||
}
|
||||
for item in section.items
|
||||
],
|
||||
}
|
||||
for section in sections
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
# Singleton instance
|
||||
menu_discovery_service = MenuDiscoveryService()
|
||||
|
||||
@@ -102,7 +102,9 @@ class MenuService:
|
||||
# Validate menu item exists in registry
|
||||
all_items = menu_discovery_service.get_all_menu_item_ids(frontend_type)
|
||||
if menu_item_id not in all_items:
|
||||
logger.warning(f"Unknown menu item: {menu_item_id} for {frontend_type.value}")
|
||||
logger.warning(
|
||||
f"Unknown menu item: {menu_item_id} for {frontend_type.value}"
|
||||
)
|
||||
return False
|
||||
|
||||
# Check module enablement if platform is specified
|
||||
@@ -159,9 +161,7 @@ class MenuService:
|
||||
|
||||
# Filter by module enablement if platform is specified
|
||||
if platform_id:
|
||||
module_service.get_module_menu_items(
|
||||
db, platform_id, frontend_type
|
||||
)
|
||||
module_service.get_module_menu_items(db, platform_id, frontend_type)
|
||||
# Only keep items from enabled modules (or items not associated with any module)
|
||||
all_items = module_service.filter_menu_items_by_modules(
|
||||
db, platform_id, all_items, frontend_type
|
||||
@@ -228,7 +228,7 @@ class MenuService:
|
||||
user_id: int | None = None,
|
||||
is_super_admin: bool = False,
|
||||
store_code: str | None = None,
|
||||
) -> dict:
|
||||
) -> list:
|
||||
"""
|
||||
Get filtered menu structure for frontend rendering.
|
||||
|
||||
@@ -248,10 +248,9 @@ class MenuService:
|
||||
store_code: Store code for URL placeholder replacement (store frontend)
|
||||
|
||||
Returns:
|
||||
Filtered menu structure ready for rendering
|
||||
List of DiscoveredMenuSection ready for rendering
|
||||
"""
|
||||
# Use the module-driven discovery service to get filtered menu
|
||||
sections = menu_discovery_service.get_menu_for_frontend(
|
||||
return menu_discovery_service.get_menu_for_frontend(
|
||||
db=db,
|
||||
frontend_type=frontend_type,
|
||||
platform_id=platform_id,
|
||||
@@ -260,9 +259,6 @@ class MenuService:
|
||||
store_code=store_code,
|
||||
)
|
||||
|
||||
# Convert to legacy format for backwards compatibility with existing templates
|
||||
return menu_discovery_service.menu_to_legacy_format(sections)
|
||||
|
||||
# =========================================================================
|
||||
# Menu Configuration (Super Admin)
|
||||
# =========================================================================
|
||||
@@ -349,10 +345,10 @@ class MenuService:
|
||||
Returns:
|
||||
List of MenuItemConfig with current visibility state
|
||||
"""
|
||||
shown_items = self._get_shown_items(
|
||||
db, FrontendType.ADMIN, user_id=user_id
|
||||
shown_items = self._get_shown_items(db, FrontendType.ADMIN, user_id=user_id)
|
||||
mandatory_items = menu_discovery_service.get_mandatory_item_ids(
|
||||
FrontendType.ADMIN
|
||||
)
|
||||
mandatory_items = menu_discovery_service.get_mandatory_item_ids(FrontendType.ADMIN)
|
||||
|
||||
# Get all menu items from discovery service
|
||||
all_items = menu_discovery_service.get_all_menu_items(FrontendType.ADMIN)
|
||||
@@ -576,7 +572,9 @@ class MenuService:
|
||||
|
||||
# Create records with is_visible=False for all non-mandatory items
|
||||
all_items = menu_discovery_service.get_all_menu_item_ids(FrontendType.ADMIN)
|
||||
mandatory_items = menu_discovery_service.get_mandatory_item_ids(FrontendType.ADMIN)
|
||||
mandatory_items = menu_discovery_service.get_mandatory_item_ids(
|
||||
FrontendType.ADMIN
|
||||
)
|
||||
|
||||
for item_id in all_items:
|
||||
if item_id not in mandatory_items:
|
||||
@@ -665,7 +663,9 @@ class MenuService:
|
||||
|
||||
# Create records with is_visible=True for all non-mandatory items
|
||||
all_items = menu_discovery_service.get_all_menu_item_ids(FrontendType.ADMIN)
|
||||
mandatory_items = menu_discovery_service.get_mandatory_item_ids(FrontendType.ADMIN)
|
||||
mandatory_items = menu_discovery_service.get_mandatory_item_ids(
|
||||
FrontendType.ADMIN
|
||||
)
|
||||
|
||||
for item_id in all_items:
|
||||
if item_id not in mandatory_items:
|
||||
@@ -717,11 +717,17 @@ class MenuService:
|
||||
return q.filter(AdminMenuConfig.user_id == user_id)
|
||||
|
||||
# Check if any visible records exist (valid opt-in config)
|
||||
visible_count = scope_query().filter(
|
||||
AdminMenuConfig.is_visible == True # noqa: E712
|
||||
).count()
|
||||
visible_count = (
|
||||
scope_query()
|
||||
.filter(
|
||||
AdminMenuConfig.is_visible == True # noqa: E712
|
||||
)
|
||||
.count()
|
||||
)
|
||||
if visible_count > 0:
|
||||
logger.debug(f"Config already exists with {visible_count} visible items, skipping init")
|
||||
logger.debug(
|
||||
f"Config already exists with {visible_count} visible items, skipping init"
|
||||
)
|
||||
return False # Already initialized
|
||||
|
||||
# Check if ANY records exist (even is_visible=False from old opt-out model)
|
||||
@@ -730,7 +736,9 @@ class MenuService:
|
||||
# Clean up old records first
|
||||
deleted = scope_query().delete(synchronize_session="fetch")
|
||||
db.flush() # Ensure deletes are applied before inserts
|
||||
logger.info(f"Cleaned up {deleted} old menu config records before initialization")
|
||||
logger.info(
|
||||
f"Cleaned up {deleted} old menu config records before initialization"
|
||||
)
|
||||
|
||||
# Get all menu items for this frontend
|
||||
all_items = menu_discovery_service.get_all_menu_item_ids(frontend_type)
|
||||
|
||||
Reference in New Issue
Block a user