refactor: use wildcard % in load_path.py for auto-coverage
This commit is contained in:
parent
b7e69b48cd
commit
c041c76c9f
@ -4,26 +4,26 @@ pricing 模块 RBAC 权限管理脚本
|
|||||||
|
|
||||||
使用方法:
|
使用方法:
|
||||||
cd ~/repos/sage
|
cd ~/repos/sage
|
||||||
./py3/bin/python ~/pricing/scripts/load_path.py
|
./py3/bin/python ~/repos/pricing/scripts/load_path.py
|
||||||
|
|
||||||
每次代码变更如有新 path 出现,需同步更新此脚本。
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def find_sage_root():
|
def find_sage_root():
|
||||||
candidates = [
|
candidates = [
|
||||||
os.path.expanduser("~/repos/sage"),
|
os.path.expanduser("~/repos/sage"),
|
||||||
os.path.expanduser("~/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:
|
for c in candidates:
|
||||||
if os.path.isdir(os.path.join(c, "py3")) and os.path.isdir(os.path.join(c, "wwwroot")):
|
if os.path.isdir(os.path.join(c, "py3")) and os.path.isdir(os.path.join(c, "wwwroot")):
|
||||||
return c
|
return c
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
SAGE_ROOT = find_sage_root()
|
SAGE_ROOT = find_sage_root()
|
||||||
if not SAGE_ROOT:
|
if not SAGE_ROOT:
|
||||||
print("ERROR: Cannot find Sage root directory")
|
print("ERROR: Cannot find Sage root directory")
|
||||||
@ -35,46 +35,45 @@ SET_PERM_SCRIPT = os.path.join(SAGE_ROOT, "set_role_perm.py")
|
|||||||
MOD = "pricing"
|
MOD = "pricing"
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
# 权限路径定义 — 每次新增页面或API时同步更新
|
# 权限路径定义
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|
||||||
# any — 无需登录(菜单、登录页等)
|
# any — 无需登录
|
||||||
PATHS_ANY = [
|
PATHS_ANY = [
|
||||||
f"/pricing/menu.ui",]
|
f"/{MOD}/menu.ui",
|
||||||
|
]
|
||||||
|
|
||||||
# logined — 需要认证的页面和 API
|
# logined — 所有已登录用户
|
||||||
PATHS_LOGINED = [
|
PATHS_LOGINED = [
|
||||||
f"/pricing",
|
# 模块入口
|
||||||
f"/pricing/download_pricing_data.dspy",
|
f"/{MOD}",
|
||||||
f"/pricing/download_pricing_pattern.dspy",
|
f"/{MOD}/index.ui",
|
||||||
f"/pricing/get_all_pricing_programs.dspy",
|
|
||||||
f"/pricing/get_platform_providers.dspy",
|
# 顶层 .ui 页面
|
||||||
f"/pricing/index.ui",
|
f"/{MOD}/load_pricing_data.ui",
|
||||||
f"/pricing/load_pricing_data.ui",
|
f"/{MOD}/pricing_test.ui",
|
||||||
f"/pricing/pi_get_all_specs.dspy",
|
f"/{MOD}/test_pricing_program.ui",
|
||||||
f"/pricing/pricing_item",
|
|
||||||
f"/pricing/pricing_item/add_pricing_item.dspy",
|
# 顶层 .dspy — 通配
|
||||||
f"/pricing/pricing_item/delete_pricing_item.dspy",
|
f"/{MOD}/%.dspy",
|
||||||
f"/pricing/pricing_item/get_pricing_item.dspy",
|
|
||||||
f"/pricing/pricing_item/get_spec_fields_by_psid.dspy",
|
# CRUD 子目录 — 通配
|
||||||
f"/pricing/pricing_item/index.ui",
|
f"/{MOD}/pricing_program/%",
|
||||||
f"/pricing/pricing_item/update_pricing_item.dspy",
|
f"/{MOD}/pricing_program_timing/%",
|
||||||
f"/pricing/pricing_program",
|
f"/{MOD}/pricing_item/%",
|
||||||
f"/pricing/pricing_program_timing",
|
]
|
||||||
f"/pricing/pricing_test.ui",
|
|
||||||
f"/pricing/test_pricing_program.dspy",
|
|
||||||
f"/pricing/test_pricing_program.ui",
|
|
||||||
f"/pricing/upload_pricing_data.dspy",]
|
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
# 执行注册
|
# 执行注册
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|
||||||
|
|
||||||
def run_set_perm(role, path):
|
def run_set_perm(role, path):
|
||||||
cmd = [PYTHON, SET_PERM_SCRIPT, role, path]
|
cmd = [PYTHON, SET_PERM_SCRIPT, role, path]
|
||||||
result = subprocess.run(cmd, capture_output=True, text=True)
|
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||||
return result.returncode == 0
|
return result.returncode == 0
|
||||||
|
|
||||||
|
|
||||||
def register_role_paths(role, paths):
|
def register_role_paths(role, paths):
|
||||||
count = 0
|
count = 0
|
||||||
for p in paths:
|
for p in paths:
|
||||||
@ -83,6 +82,7 @@ def register_role_paths(role, paths):
|
|||||||
print(f" {role}: {count}/{len(paths)} paths registered")
|
print(f" {role}: {count}/{len(paths)} paths registered")
|
||||||
return count
|
return count
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print(f"Sage root: {SAGE_ROOT}")
|
print(f"Sage root: {SAGE_ROOT}")
|
||||||
total = 0
|
total = 0
|
||||||
@ -91,5 +91,6 @@ def main():
|
|||||||
print(f"\nDone. Total {total} permission entries registered.")
|
print(f"\nDone. Total {total} permission entries registered.")
|
||||||
print("NOTE: Restart Sage after permission changes to reload RBAC cache.")
|
print("NOTE: Restart Sage after permission changes to reload RBAC cache.")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user