Add new validation rules MOD-020 to MOD-023 for module definition completeness and standardize permissions across all modules. Changes: - Add MOD-020: Module definitions must have required attributes - Add MOD-021: Modules with menus should have features - Add MOD-022: Feature modules should have permissions - Add MOD-023: Modules with routers should use get_*_with_routers pattern Module permissions added: - analytics: view, export, manage_dashboards - billing: view_tiers, manage_tiers, view_subscriptions, manage_subscriptions, view_invoices - cart: view, manage - checkout: view_settings, manage_settings - cms: view_pages, manage_pages, view_media, manage_media, manage_themes - loyalty: view_programs, manage_programs, view_rewards, manage_rewards - marketplace: view_integration, manage_integration, sync_products - messaging: view_messages, send_messages, manage_templates - payments: view_gateways, manage_gateways, view_transactions Module improvements: - Complete cart module with features and permissions - Complete checkout module with features and permissions - Add features to catalog module - Add version to cms module - Fix loyalty platform_router attachment - Add path definitions to payments module - Remove empty scheduled_tasks from dev_tools module Documentation: - Update module-system.md with new validation rules - Update architecture-rules.md with MOD-020 to MOD-023 Tests: - Add unit tests for module definition completeness - Add tests for permission structure validation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
123 lines
4.0 KiB
Python
123 lines
4.0 KiB
Python
# app/modules/analytics/definition.py
|
|
"""
|
|
Analytics module definition.
|
|
|
|
Defines the analytics module including its features, menu items,
|
|
route configurations, and self-contained module settings.
|
|
"""
|
|
|
|
from app.modules.base import MenuItemDefinition, MenuSectionDefinition, ModuleDefinition, PermissionDefinition
|
|
from app.modules.enums import FrontendType
|
|
|
|
|
|
def _get_vendor_api_router():
|
|
"""Lazy import of vendor API router to avoid circular imports."""
|
|
from app.modules.analytics.routes.api.vendor import router
|
|
|
|
return router
|
|
|
|
|
|
def _get_vendor_page_router():
|
|
"""Lazy import of vendor page router to avoid circular imports."""
|
|
from app.modules.analytics.routes.pages.vendor import router
|
|
|
|
return router
|
|
|
|
|
|
# Analytics module definition
|
|
analytics_module = ModuleDefinition(
|
|
code="analytics",
|
|
name="Analytics & Reporting",
|
|
description="Dashboard analytics, custom reports, and data exports.",
|
|
version="1.0.0",
|
|
features=[
|
|
"basic_reports", # Basic reporting
|
|
"analytics_dashboard", # Analytics dashboard
|
|
"custom_reports", # Custom report builder
|
|
"export_reports", # Export to CSV/Excel
|
|
"usage_metrics", # Usage and performance metrics
|
|
],
|
|
# Module-driven permissions
|
|
permissions=[
|
|
PermissionDefinition(
|
|
id="analytics.view",
|
|
label_key="analytics.permissions.view",
|
|
description_key="analytics.permissions.view_desc",
|
|
category="analytics",
|
|
),
|
|
PermissionDefinition(
|
|
id="analytics.export",
|
|
label_key="analytics.permissions.export",
|
|
description_key="analytics.permissions.export_desc",
|
|
category="analytics",
|
|
),
|
|
PermissionDefinition(
|
|
id="analytics.manage_dashboards",
|
|
label_key="analytics.permissions.manage_dashboards",
|
|
description_key="analytics.permissions.manage_dashboards_desc",
|
|
category="analytics",
|
|
),
|
|
],
|
|
menu_items={
|
|
FrontendType.ADMIN: [
|
|
# Analytics appears in dashboard for admin
|
|
],
|
|
FrontendType.VENDOR: [
|
|
"analytics", # Vendor analytics page
|
|
],
|
|
},
|
|
# New module-driven menu definitions
|
|
menus={
|
|
FrontendType.VENDOR: [
|
|
MenuSectionDefinition(
|
|
id="main",
|
|
label_key=None,
|
|
icon=None,
|
|
order=0,
|
|
is_collapsible=False,
|
|
items=[
|
|
MenuItemDefinition(
|
|
id="analytics",
|
|
label_key="analytics.menu.analytics",
|
|
icon="chart-bar",
|
|
route="/vendor/{vendor_code}/analytics",
|
|
order=20,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
},
|
|
is_core=False,
|
|
# =========================================================================
|
|
# Self-Contained Module Configuration
|
|
# =========================================================================
|
|
is_self_contained=True,
|
|
services_path="app.modules.analytics.services",
|
|
models_path="app.modules.analytics.models",
|
|
schemas_path="app.modules.analytics.schemas",
|
|
exceptions_path="app.modules.analytics.exceptions",
|
|
# Module templates (namespaced as analytics/admin/*.html and analytics/vendor/*.html)
|
|
templates_path="templates",
|
|
# Module-specific translations (accessible via analytics.* keys)
|
|
locales_path="locales",
|
|
)
|
|
|
|
|
|
def get_analytics_module_with_routers() -> ModuleDefinition:
|
|
"""
|
|
Get analytics module with routers attached.
|
|
|
|
This function attaches the routers lazily to avoid circular imports
|
|
during module initialization.
|
|
|
|
Routers:
|
|
- vendor_api_router: API endpoints for vendor analytics
|
|
- vendor_page_router: Page routes for vendor analytics dashboard
|
|
"""
|
|
analytics_module.vendor_api_router = _get_vendor_api_router()
|
|
analytics_module.vendor_page_router = _get_vendor_page_router()
|
|
return analytics_module
|
|
|
|
|
|
__all__ = ["analytics_module", "get_analytics_module_with_routers"]
|