fix(admin): restore default menu visibility and protection
This commit is contained in:
@@ -719,6 +719,8 @@
|
||||
- admin 默认授予上述权限。
|
||||
- 菜单口径:
|
||||
- 新增菜单 `admin.power_lines`,路由 `/admin/power-lines`;
|
||||
- 一级菜单默认排序中,`admin.power_lines` 使用最小 `sort_order`,应展示在后台菜单最前面;
|
||||
- 后台默认菜单集合补齐 `admin.fl_analysis`、`admin.fault_recurrence`、`admin.basic_data`、`admin.system_monitor`、`admin.system`;其中后 3 项为无路由目录菜单,用于保留现存菜单树全量可见性。
|
||||
- 页面由 `web/src/app/admin/power-lines/page.tsx` 承载线路与杆塔管理闭环。
|
||||
|
||||
## 线路地图展示口径(2026-04-25)
|
||||
|
||||
@@ -404,7 +404,28 @@ def update_menu(db: Session, menu_id: int, payload: MenuUpdateRequest) -> MenuPu
|
||||
|
||||
def delete_menu(db: Session, menu_id: int) -> bool:
|
||||
menu = get_menu_by_id(db, menu_id)
|
||||
if not menu or menu.code in {"admin.users", "admin.roles", "admin.menus", "admin.system_params", "admin.power_lines", "admin.lightning_currents", "admin.lightning_distribution", "admin.workers", "admin.task_monitor", "admin.atp_models", "admin.tower_models", "admin.files", "admin.elevation", "admin.syslog", "admin.wine_runner"}:
|
||||
if not menu or menu.code in {
|
||||
"admin.users",
|
||||
"admin.roles",
|
||||
"admin.menus",
|
||||
"admin.system_params",
|
||||
"admin.system",
|
||||
"admin.system_monitor",
|
||||
"admin.basic_data",
|
||||
"admin.power_lines",
|
||||
"admin.fl_analysis",
|
||||
"admin.fault_recurrence",
|
||||
"admin.lightning_currents",
|
||||
"admin.lightning_distribution",
|
||||
"admin.workers",
|
||||
"admin.task_monitor",
|
||||
"admin.atp_models",
|
||||
"admin.tower_models",
|
||||
"admin.files",
|
||||
"admin.elevation",
|
||||
"admin.syslog",
|
||||
"admin.wine_runner",
|
||||
}:
|
||||
return False
|
||||
child_exists = db.scalar(select(Menu.id).where(Menu.parent_id == menu_id))
|
||||
if child_exists is not None:
|
||||
|
||||
@@ -67,13 +67,17 @@ PROTECTED_MENU_CODES = {
|
||||
"admin.roles",
|
||||
"admin.menus",
|
||||
"admin.system_params",
|
||||
"admin.system",
|
||||
"admin.system_monitor",
|
||||
"admin.wxapp",
|
||||
"admin.basic_data",
|
||||
"admin.files",
|
||||
"admin.elevation",
|
||||
"admin.tower_models",
|
||||
"admin.filedetector",
|
||||
"admin.baidu_pan",
|
||||
"admin.power_lines",
|
||||
"admin.fl_analysis",
|
||||
"admin.fault_recurrence",
|
||||
"admin.lightning_currents",
|
||||
"admin.lightning_distribution",
|
||||
|
||||
@@ -92,6 +92,7 @@ MENU_CODE_PERMISSION_MAP: dict[str, set[str]] = {
|
||||
"admin.roles": {"role.read", "role.manage"},
|
||||
"admin.menus": {"menu.read", "menu.manage"},
|
||||
"admin.system_params": {"system_param.read", "system_param.manage"},
|
||||
"admin.fl_analysis": {"line.read", "line.manage"},
|
||||
"admin.files": {"file.read", "file.manage"},
|
||||
"admin.elevation": {"elevation.read", "elevation.manage"},
|
||||
"admin.tower_models": {"tower_model.read", "tower_model.manage"},
|
||||
|
||||
@@ -216,7 +216,7 @@ DEFAULT_MENUS: list[dict[str, object]] = [
|
||||
"icon": "Network",
|
||||
"parent_code": None,
|
||||
"type": "menu",
|
||||
"sort_order": 50,
|
||||
"sort_order": 0,
|
||||
"status": "enabled",
|
||||
"visible": True,
|
||||
"cacheable": False,
|
||||
@@ -378,10 +378,70 @@ DEFAULT_MENUS: list[dict[str, object]] = [
|
||||
"cacheable": False,
|
||||
"permission_code": "wine.read",
|
||||
},
|
||||
{
|
||||
"code": "admin.basic_data",
|
||||
"name": "基础数据",
|
||||
"path": None,
|
||||
"icon": "Database",
|
||||
"parent_code": None,
|
||||
"type": "directory",
|
||||
"sort_order": 97,
|
||||
"status": "enabled",
|
||||
"visible": True,
|
||||
"cacheable": False,
|
||||
"permission_code": None,
|
||||
},
|
||||
{
|
||||
"code": "admin.system_monitor",
|
||||
"name": "系统监控",
|
||||
"path": None,
|
||||
"icon": "Activity",
|
||||
"parent_code": None,
|
||||
"type": "directory",
|
||||
"sort_order": 98,
|
||||
"status": "enabled",
|
||||
"visible": True,
|
||||
"cacheable": False,
|
||||
"permission_code": None,
|
||||
},
|
||||
{
|
||||
"code": "admin.system",
|
||||
"name": "系统管理",
|
||||
"path": None,
|
||||
"icon": "Settings2",
|
||||
"parent_code": None,
|
||||
"type": "directory",
|
||||
"sort_order": 99,
|
||||
"status": "enabled",
|
||||
"visible": True,
|
||||
"cacheable": False,
|
||||
"permission_code": None,
|
||||
},
|
||||
]
|
||||
|
||||
ROLE_MENU_BINDINGS: dict[str, list[str]] = {
|
||||
"admin": ["admin.users", "admin.roles", "admin.menus", "admin.system_params", "admin.power_lines", "admin.fl_analysis", "admin.fault_recurrence", "admin.lightning_currents", "admin.lightning_distribution", "admin.workers", "admin.task_monitor", "admin.atp_models", "admin.tower_models", "admin.files", "admin.elevation", "admin.syslog", "admin.wine_runner"],
|
||||
"admin": [
|
||||
"admin.users",
|
||||
"admin.roles",
|
||||
"admin.menus",
|
||||
"admin.system_params",
|
||||
"admin.power_lines",
|
||||
"admin.fl_analysis",
|
||||
"admin.fault_recurrence",
|
||||
"admin.lightning_currents",
|
||||
"admin.lightning_distribution",
|
||||
"admin.workers",
|
||||
"admin.task_monitor",
|
||||
"admin.atp_models",
|
||||
"admin.tower_models",
|
||||
"admin.files",
|
||||
"admin.elevation",
|
||||
"admin.syslog",
|
||||
"admin.wine_runner",
|
||||
"admin.basic_data",
|
||||
"admin.system_monitor",
|
||||
"admin.system",
|
||||
],
|
||||
"user": [],
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
## Work Log - 当前环境将线路管理菜单置顶(2026-06-08)
|
||||
|
||||
- 背景:
|
||||
- 仓库代码已支持 `admin.power_lines` 菜单,但默认排序仍落在其他后台一级菜单之后。
|
||||
- 用户要求在当前环境中让“线路管理”展示在后台菜单最前面。
|
||||
|
||||
- 本次处理:
|
||||
- 当前环境数据库:
|
||||
- 将 `menus.code='admin.power_lines'` 的 `sort_order` 调整为 `0`。
|
||||
- 仓库代码:
|
||||
- `api/app/services/seed_service.py`
|
||||
- 将默认种子菜单中 `admin.power_lines` 的 `sort_order` 同步改为 `0`,避免后续补种回退。
|
||||
- `MEMORY.md`
|
||||
- 补充“线路管理默认置顶”的长期口径。
|
||||
|
||||
- 验证:
|
||||
- 复核后台菜单排序后,`线路管理` 已位于一级菜单首位。
|
||||
|
||||
- 风险与关注点:
|
||||
- 已登录后台的浏览器会话需要刷新页面后才会看到最新菜单顺序。
|
||||
|
||||
## Work Log - 放出后台剩余目录菜单并补齐保护(2026-06-08)
|
||||
|
||||
- 背景:
|
||||
- 当前仓库默认菜单集合缺少 `admin.basic_data`、`admin.system_monitor`、`admin.system` 3 个目录菜单。
|
||||
- `admin.fl_analysis` 已有完整页面,但旧权限映射与菜单保护集合仍未完全覆盖。
|
||||
|
||||
- 本次处理:
|
||||
- `api/app/services/seed_service.py`
|
||||
- 补齐上述 3 个目录菜单,并将其加入 `admin` 默认菜单绑定。
|
||||
- `api/app/services/admin_service.py`
|
||||
- 将 `admin.system`、`admin.system_monitor`、`admin.basic_data`、`admin.fl_analysis`、`admin.fault_recurrence` 加入现代菜单删除保护集合。
|
||||
- `api/app/services/legacy_admin_rbac_service.py`
|
||||
- 将 `admin.system`、`admin.system_monitor`、`admin.basic_data`、`admin.fl_analysis` 加入 legacy 受保护菜单集合。
|
||||
- `api/app/services/legacy_authz_service.py`
|
||||
- 补齐 `admin.fl_analysis` 的 legacy 权限映射。
|
||||
|
||||
- 验证:
|
||||
- `git diff --check` 通过。
|
||||
- `npm --workspace web exec tsc --noEmit` 通过。
|
||||
- `npm --workspace web exec eslint src/app/admin/fl-analysis/page.tsx src/app/admin/fault-recurrence/page.tsx` 通过。
|
||||
- Python 变更文件 AST 语法解析通过。
|
||||
|
||||
- 风险与关注点:
|
||||
- `admin.basic_data`、`admin.system_monitor`、`admin.system` 仍为无 `path` 的目录菜单,只承担菜单树占位与分组作用。
|
||||
Reference in New Issue
Block a user