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
This commit is contained in:
yumoqing 2026-05-05 22:22:41 +08:00
parent cbbc179491
commit 98e1bbe96a

View File

@ -291,20 +291,30 @@ async def main():
print(f" 注册权限: {perm_count}, 授权次数: {grant_count}, 错误: {error_count}") print(f" 注册权限: {perm_count}, 授权次数: {grant_count}, 错误: {error_count}")
# ---- 4c: 注册 CRUD API 权限 ---- # ---- 4c: 注册 CRUD API 权限 + 数据表页面权限 ----
print(f"\n [4c] 注册 CRUD API 权限...") print(f"\n [4c] 注册 CRUD API 和数据表页面权限...")
crud_count = 0 crud_count = 0
for module, tables in pc.CRUD_TABLES.items(): for module, tables in pc.CRUD_TABLES.items():
for table in tables: for table in tables:
for action in ('list', 'create', 'update', 'delete'): # 1) 注册数据表页面路径: /{module}/{table} (menu.ui 中菜单项的 url)
path = f"/{module}/api/{table}_{action}.dspy" page_path = f"/{module}/{table}"
try: try:
permid = await ensure_permission(sor, path, permtype='api') permid = await ensure_permission(sor, page_path, permtype='page')
await grant_perm(sor, role_ids['admin_superuser'], permid) await grant_perm(sor, role_ids['admin_superuser'], permid)
crud_count += 1 crud_count += 1
except Exception: except Exception:
pass pass
print(f" 注册 CRUD API: {crud_count}")
# 2) 注册 CRUD API 端点: list/create/update/delete
for action in ('list', 'create', 'update', 'delete'):
api_path = f"/{module}/api/{table}_{action}.dspy"
try:
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 权限: {crud_count}")
# ---- 4d: 同步 admin_superuser 权限到各机构角色 ---- # ---- 4d: 同步 admin_superuser 权限到各机构角色 ----
print(f"\n [4d] 同步 admin_superuser 权限到各机构已有角色...") print(f"\n [4d] 同步 admin_superuser 权限到各机构已有角色...")