From 98e1bbe96a5a283276774d11b9962d66df6bf4dc Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 5 May 2026 22:22:41 +0800 Subject: [PATCH] fix: register /{module}/{table} page path for CRUD table menu items in init_permissions.py - Menu items use url='{{entire_url('/module/table')}}' format - init_permissions.py now registers both the page path and CRUD API endpoints - Page path: /{module}/{table} (for menu navigation) - API paths: /{module}/api/{table}_{list|create|update|delete}.dspy --- init_permissions.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/init_permissions.py b/init_permissions.py index 1f3b798..583b011 100644 --- a/init_permissions.py +++ b/init_permissions.py @@ -291,20 +291,30 @@ async def main(): print(f" 注册权限: {perm_count}, 授权次数: {grant_count}, 错误: {error_count}") - # ---- 4c: 注册 CRUD API 权限 ---- - print(f"\n [4c] 注册 CRUD API 权限...") + # ---- 4c: 注册 CRUD API 权限 + 数据表页面权限 ---- + print(f"\n [4c] 注册 CRUD API 和数据表页面权限...") crud_count = 0 for module, tables in pc.CRUD_TABLES.items(): for table in tables: + # 1) 注册数据表页面路径: /{module}/{table} (menu.ui 中菜单项的 url) + page_path = f"/{module}/{table}" + try: + permid = await ensure_permission(sor, page_path, permtype='page') + await grant_perm(sor, role_ids['admin_superuser'], permid) + crud_count += 1 + except Exception: + pass + + # 2) 注册 CRUD API 端点: list/create/update/delete for action in ('list', 'create', 'update', 'delete'): - path = f"/{module}/api/{table}_{action}.dspy" + api_path = f"/{module}/api/{table}_{action}.dspy" try: - permid = await ensure_permission(sor, path, permtype='api') + permid = await ensure_permission(sor, api_path, permtype='api') await grant_perm(sor, role_ids['admin_superuser'], permid) crud_count += 1 except Exception: pass - print(f" 注册 CRUD API: {crud_count}") + print(f" 注册 CRUD 权限: {crud_count}") # ---- 4d: 同步 admin_superuser 权限到各机构角色 ---- print(f"\n [4d] 同步 admin_superuser 权限到各机构已有角色...")