feat: add load_path.py RBAC permission registration script
This commit is contained in:
parent
d388769ef1
commit
805f7fc94f
96
scripts/load_path.py
Normal file
96
scripts/load_path.py
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
contract_management 模块 RBAC 权限管理脚本
|
||||||
|
|
||||||
|
使用方法:
|
||||||
|
cd ~/repos/sage
|
||||||
|
./py3/bin/python ~/contract_management/scripts/load_path.py
|
||||||
|
|
||||||
|
每次代码变更如有新 path 出现,需同步更新此脚本。
|
||||||
|
"""
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def find_sage_root():
|
||||||
|
candidates = [
|
||||||
|
os.path.expanduser("~/repos/sage"),
|
||||||
|
os.path.expanduser("~/sage"),
|
||||||
|
os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))),
|
||||||
|
]
|
||||||
|
for c in candidates:
|
||||||
|
if os.path.isdir(os.path.join(c, "py3")) and os.path.isdir(os.path.join(c, "wwwroot")):
|
||||||
|
return c
|
||||||
|
return None
|
||||||
|
|
||||||
|
SAGE_ROOT = find_sage_root()
|
||||||
|
if not SAGE_ROOT:
|
||||||
|
print("ERROR: Cannot find Sage root directory")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
PYTHON = os.path.join(SAGE_ROOT, "py3", "bin", "python")
|
||||||
|
SET_PERM_SCRIPT = os.path.join(SAGE_ROOT, "set_role_perm.py")
|
||||||
|
|
||||||
|
MOD = "contract_management"
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# 权限路径定义 — 每次新增页面或API时同步更新
|
||||||
|
# ============================================================
|
||||||
|
|
||||||
|
# any — 无需登录(菜单、登录页等)
|
||||||
|
PATHS_ANY = [
|
||||||
|
f"/contract_management/menu.ui",]
|
||||||
|
|
||||||
|
# logined — 需要认证的页面和 API
|
||||||
|
PATHS_LOGINED = [
|
||||||
|
f"/contract_management",
|
||||||
|
f"/contract_management/ai_config.ui",
|
||||||
|
f"/contract_management/api/check_contract.dspy",
|
||||||
|
f"/contract_management/api/contract_list.dspy",
|
||||||
|
f"/contract_management/api/contracts_create.dspy",
|
||||||
|
f"/contract_management/api/contracts_delete.dspy",
|
||||||
|
f"/contract_management/api/contracts_update.dspy",
|
||||||
|
f"/contract_management/contract",
|
||||||
|
f"/contract_management/contract_ai_config",
|
||||||
|
f"/contract_management/contract_attachment",
|
||||||
|
f"/contract_management/contract_detail.ui",
|
||||||
|
f"/contract_management/contract_edit.ui",
|
||||||
|
f"/contract_management/contract_list",
|
||||||
|
f"/contract_management/contract_list.dspy",
|
||||||
|
f"/contract_management/contract_list.ui",
|
||||||
|
f"/contract_management/contract_milestones_list",
|
||||||
|
f"/contract_management/contract_versions_list",
|
||||||
|
f"/contract_management/index.ui",
|
||||||
|
f"/contract_management/order_payments_edit",
|
||||||
|
f"/contract_management/order_payments_list",
|
||||||
|
f"/contract_management/orders_edit",
|
||||||
|
f"/contract_management/orders_list",]
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# 执行注册
|
||||||
|
# ============================================================
|
||||||
|
|
||||||
|
def run_set_perm(role, path):
|
||||||
|
cmd = [PYTHON, SET_PERM_SCRIPT, role, path]
|
||||||
|
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||||
|
return result.returncode == 0
|
||||||
|
|
||||||
|
def register_role_paths(role, paths):
|
||||||
|
count = 0
|
||||||
|
for p in paths:
|
||||||
|
if run_set_perm(role, p):
|
||||||
|
count += 1
|
||||||
|
print(f" {role}: {count}/{len(paths)} paths registered")
|
||||||
|
return count
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print(f"Sage root: {SAGE_ROOT}")
|
||||||
|
total = 0
|
||||||
|
total += register_role_paths("any", PATHS_ANY)
|
||||||
|
total += register_role_paths("logined", PATHS_LOGINED)
|
||||||
|
print(f"\nDone. Total {total} permission entries registered.")
|
||||||
|
print("NOTE: Restart Sage after permission changes to reload RBAC cache.")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
x
Reference in New Issue
Block a user