Replace the hardcoded merchant sidebar with a dynamic menu system driven by module definitions, matching the existing admin frontend pattern. Modules declare FrontendType.MERCHANT menus in their definition.py, and a new API endpoint unions enabled modules across all platforms the merchant is subscribed to — so loyalty only appears when enabled. - Add MERCHANT menu definitions to core, billing, tenancy, loyalty modules - Extend MenuDiscoveryService with enabled_module_codes parameter - Create GET /merchants/core/menu/render/merchant endpoint - Update merchant Alpine.js with loadMenuConfig() and dynamic section state - Replace hardcoded sidebar.html with x-for rendering + loading skeleton + fallback - Add 36 unit and integration tests for menu discovery, service, and endpoint Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
192 lines
6.0 KiB
Python
192 lines
6.0 KiB
Python
# app/modules/core/definition.py
|
|
"""
|
|
Core Platform module definition.
|
|
|
|
Dashboard, settings, and profile management.
|
|
Required for basic operation - cannot be disabled.
|
|
"""
|
|
|
|
from app.modules.base import (
|
|
MenuItemDefinition,
|
|
MenuSectionDefinition,
|
|
ModuleDefinition,
|
|
PermissionDefinition,
|
|
)
|
|
from app.modules.enums import FrontendType
|
|
|
|
core_module = ModuleDefinition(
|
|
code="core",
|
|
name="Core Platform",
|
|
description="Dashboard, settings, and profile management. Required for basic operation.",
|
|
version="1.0.0",
|
|
is_core=True,
|
|
is_self_contained=True,
|
|
# Module-driven permissions
|
|
permissions=[
|
|
PermissionDefinition(
|
|
id="dashboard.view",
|
|
label_key="core.permissions.dashboard_view",
|
|
description_key="core.permissions.dashboard_view_desc",
|
|
category="dashboard",
|
|
),
|
|
PermissionDefinition(
|
|
id="settings.view",
|
|
label_key="core.permissions.settings_view",
|
|
description_key="core.permissions.settings_view_desc",
|
|
category="settings",
|
|
),
|
|
PermissionDefinition(
|
|
id="settings.edit",
|
|
label_key="core.permissions.settings_edit",
|
|
description_key="core.permissions.settings_edit_desc",
|
|
category="settings",
|
|
),
|
|
PermissionDefinition(
|
|
id="settings.theme",
|
|
label_key="core.permissions.settings_theme",
|
|
description_key="core.permissions.settings_theme_desc",
|
|
category="settings",
|
|
),
|
|
PermissionDefinition(
|
|
id="settings.domains",
|
|
label_key="core.permissions.settings_domains",
|
|
description_key="core.permissions.settings_domains_desc",
|
|
category="settings",
|
|
is_owner_only=True, # Only owners can manage domains
|
|
),
|
|
],
|
|
features=[
|
|
"dashboard",
|
|
"settings",
|
|
"profile",
|
|
],
|
|
# Legacy menu_items (IDs only)
|
|
menu_items={
|
|
FrontendType.ADMIN: [
|
|
"dashboard",
|
|
"settings",
|
|
"email-templates",
|
|
"my-menu",
|
|
],
|
|
FrontendType.STORE: [
|
|
"dashboard",
|
|
"profile",
|
|
"settings",
|
|
"email-templates",
|
|
],
|
|
FrontendType.MERCHANT: [
|
|
"dashboard",
|
|
],
|
|
},
|
|
# New module-driven menu definitions
|
|
menus={
|
|
FrontendType.ADMIN: [
|
|
MenuSectionDefinition(
|
|
id="main",
|
|
label_key=None, # No header for main section
|
|
icon=None,
|
|
order=0,
|
|
is_collapsible=False,
|
|
items=[
|
|
MenuItemDefinition(
|
|
id="dashboard",
|
|
label_key="core.menu.dashboard",
|
|
icon="home",
|
|
route="/admin/dashboard",
|
|
order=10,
|
|
is_mandatory=True,
|
|
),
|
|
],
|
|
),
|
|
MenuSectionDefinition(
|
|
id="settings",
|
|
label_key="core.menu.platform_settings",
|
|
icon="cog",
|
|
order=900,
|
|
items=[
|
|
MenuItemDefinition(
|
|
id="settings",
|
|
label_key="core.menu.general",
|
|
icon="cog",
|
|
route="/admin/settings",
|
|
order=10,
|
|
is_mandatory=True,
|
|
),
|
|
MenuItemDefinition(
|
|
id="my-menu",
|
|
label_key="core.menu.my_menu",
|
|
icon="view-grid",
|
|
route="/admin/my-menu",
|
|
order=30,
|
|
is_mandatory=True,
|
|
is_super_admin_only=True,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
FrontendType.MERCHANT: [
|
|
MenuSectionDefinition(
|
|
id="main",
|
|
label_key=None,
|
|
icon=None,
|
|
order=0,
|
|
is_collapsible=False,
|
|
items=[
|
|
MenuItemDefinition(
|
|
id="dashboard",
|
|
label_key="core.menu.dashboard",
|
|
icon="home",
|
|
route="/merchants/dashboard",
|
|
order=10,
|
|
is_mandatory=True,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
FrontendType.STORE: [
|
|
MenuSectionDefinition(
|
|
id="main",
|
|
label_key=None,
|
|
icon=None,
|
|
order=0,
|
|
is_collapsible=False,
|
|
items=[
|
|
MenuItemDefinition(
|
|
id="dashboard",
|
|
label_key="core.menu.dashboard",
|
|
icon="home",
|
|
route="/store/{store_code}/dashboard",
|
|
order=10,
|
|
is_mandatory=True,
|
|
),
|
|
],
|
|
),
|
|
MenuSectionDefinition(
|
|
id="account",
|
|
label_key="core.menu.account_settings",
|
|
icon="user",
|
|
order=900,
|
|
items=[
|
|
MenuItemDefinition(
|
|
id="profile",
|
|
label_key="core.menu.profile",
|
|
icon="user",
|
|
route="/store/{store_code}/profile",
|
|
order=10,
|
|
),
|
|
MenuItemDefinition(
|
|
id="settings",
|
|
label_key="core.menu.settings",
|
|
icon="cog",
|
|
route="/store/{store_code}/settings",
|
|
order=20,
|
|
is_mandatory=True,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
},
|
|
)
|
|
|
|
__all__ = ["core_module"]
|