refactor: use wildcard % in load_path.py for auto-coverage
This commit is contained in:
parent
5fa058add9
commit
8f36013ad6
@ -4,26 +4,26 @@ accounting 模块 RBAC 权限管理脚本
|
||||
|
||||
使用方法:
|
||||
cd ~/repos/sage
|
||||
./py3/bin/python ~/accounting/scripts/load_path.py
|
||||
|
||||
每次代码变更如有新 path 出现,需同步更新此脚本。
|
||||
./py3/bin/python ~/repos/accounting/scripts/load_path.py
|
||||
"""
|
||||
|
||||
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__))))),
|
||||
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")
|
||||
@ -35,56 +35,55 @@ SET_PERM_SCRIPT = os.path.join(SAGE_ROOT, "set_role_perm.py")
|
||||
MOD = "accounting"
|
||||
|
||||
# ============================================================
|
||||
# 权限路径定义 — 每次新增页面或API时同步更新
|
||||
# 权限路径定义
|
||||
# ============================================================
|
||||
|
||||
# any — 无需登录(菜单、登录页等)
|
||||
# any — 无需登录
|
||||
PATHS_ANY = [
|
||||
f"/accounting/usermenu.ui",]
|
||||
f"/{MOD}/usermenu.ui",
|
||||
]
|
||||
|
||||
# logined — 需要认证的页面和 API
|
||||
# logined — 所有已登录用户
|
||||
PATHS_LOGINED = [
|
||||
f"/accounting",
|
||||
f"/accounting/acc_balance",
|
||||
f"/accounting/acc_detail",
|
||||
f"/accounting/accdetail.dspy",
|
||||
f"/accounting/accdetail.ui",
|
||||
f"/accounting/account",
|
||||
f"/accounting/account_config",
|
||||
f"/accounting/accounting_config",
|
||||
f"/accounting/accounting_log",
|
||||
f"/accounting/get_user_balance.dspy",
|
||||
f"/accounting/index.ui",
|
||||
f"/accounting/myaccounts.dspy",
|
||||
f"/accounting/myaccounts.ui",
|
||||
f"/accounting/mybalance.dspy",
|
||||
f"/accounting/oca.dspy",
|
||||
f"/accounting/open_customer_accounts.dspy",
|
||||
f"/accounting/open_owner_accounts.dspy",
|
||||
f"/accounting/open_provider_accounts.dspy",
|
||||
f"/accounting/open_reseller_accounts.dspy",
|
||||
f"/accounting/open_reseller_provider_accounts.dspy",
|
||||
f"/accounting/stat_account_count.ui",
|
||||
f"/accounting/stat_month_consumption.ui",
|
||||
f"/accounting/stat_today_consumption.ui",
|
||||
f"/accounting/stat_total_balance.ui",
|
||||
f"/accounting/subject",
|
||||
f"/accounting/credit_limit",
|
||||
f"/accounting/credit_limit/index.ui",
|
||||
f"/accounting/credit_limit/get_credit_limit.dspy",
|
||||
f"/accounting/credit_limit/add_credit_limit.dspy",
|
||||
f"/accounting/credit_limit/update_credit_limit.dspy",
|
||||
f"/accounting/credit_limit/delete_credit_limit.dspy",]
|
||||
# 模块入口
|
||||
f"/{MOD}",
|
||||
f"/{MOD}/index.ui",
|
||||
|
||||
# 顶层 .ui 页面
|
||||
f"/{MOD}/myaccounts.ui",
|
||||
f"/{MOD}/accdetail.ui",
|
||||
|
||||
# 顶层 .dspy
|
||||
f"/{MOD}/%.dspy",
|
||||
|
||||
# 统计卡片 .ui
|
||||
f"/{MOD}/stat_total_balance.ui",
|
||||
f"/{MOD}/stat_today_consumption.ui",
|
||||
f"/{MOD}/stat_month_consumption.ui",
|
||||
f"/{MOD}/stat_account_count.ui",
|
||||
|
||||
# CRUD 子目录 — 通配
|
||||
f"/{MOD}/acc_balance/%",
|
||||
f"/{MOD}/acc_detail/%",
|
||||
f"/{MOD}/account/%",
|
||||
f"/{MOD}/account_config/%",
|
||||
f"/{MOD}/accounting_config/%",
|
||||
f"/{MOD}/accounting_log/%",
|
||||
f"/{MOD}/subject/%",
|
||||
f"/{MOD}/credit_limit/%",
|
||||
]
|
||||
|
||||
# ============================================================
|
||||
# 执行注册
|
||||
# ============================================================
|
||||
|
||||
|
||||
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:
|
||||
@ -93,6 +92,7 @@ def register_role_paths(role, paths):
|
||||
print(f" {role}: {count}/{len(paths)} paths registered")
|
||||
return count
|
||||
|
||||
|
||||
def main():
|
||||
print(f"Sage root: {SAGE_ROOT}")
|
||||
total = 0
|
||||
@ -101,5 +101,6 @@ def main():
|
||||
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