You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.7 KiB
Python
69 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, field
|
|
from typing import Any
|
|
from typing import Protocol
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class ModulePermission:
|
|
"""业务模块声明的权限码。"""
|
|
|
|
code: str
|
|
name: str
|
|
description: str | None = None
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class ModuleMenuSeed:
|
|
"""业务模块声明的菜单 seed 数据。"""
|
|
|
|
id: str
|
|
name: str
|
|
type: str
|
|
path: str | None = None
|
|
component: str | None = None
|
|
redirect: str | None = None
|
|
parent_id: str | None = None
|
|
auth_code: str | None = None
|
|
meta: dict[str, Any] = field(default_factory=dict)
|
|
sort: int = 0
|
|
status: str = "enabled"
|
|
admin_roles: tuple[str, ...] = ("ADMIN",)
|
|
|
|
def as_menu_payload(self) -> dict[str, Any]:
|
|
return {
|
|
"id": self.id,
|
|
"name": self.name,
|
|
"type": self.type,
|
|
"path": self.path,
|
|
"component": self.component,
|
|
"redirect": self.redirect,
|
|
"parent_id": self.parent_id,
|
|
"auth_code": self.auth_code,
|
|
"meta": self.meta,
|
|
"sort": self.sort,
|
|
"status": self.status,
|
|
}
|
|
|
|
|
|
class ItiModule(Protocol):
|
|
"""Protocol for in-process business modules."""
|
|
|
|
name: str
|
|
|
|
def init_app(self, app) -> None:
|
|
"""Initialize the module against the Flask app."""
|
|
|
|
def register_routes(self, app) -> None:
|
|
"""Register module routes."""
|
|
|
|
def register_permissions(self, app) -> None:
|
|
"""Register permission metadata."""
|
|
|
|
def register_menu_seed(self, app) -> None:
|
|
"""Register menu seed metadata."""
|
|
|
|
def register_commands(self, app) -> None:
|
|
"""Register CLI commands."""
|