voucher/scripts/load_path.py
yumoqing 2b9942f356 feat: 新增客户自助查询 API (v1/available)
- wwwroot/api/v1/available.dspy: Bearer 认证,支持 product_type/product_name/request_amount 过滤
- init.py: get_available_vouchers_api 返回含 template_name 的完整数据
- README: 完善 API 文档,移除 dapi 依赖说明
- load_path.py: 注册 v1 端点权限
2026-05-29 00:51:27 +08:00

77 lines
2.5 KiB
Python

#!/usr/bin/env python3
"""voucher 模块 RBAC 权限注册"""
import os
import sys
import subprocess
def find_sage_root():
for candidate in [
os.path.expanduser("~/repos/sage"),
os.path.expanduser("~/sage"),
]:
if os.path.isdir(os.path.join(candidate, "wwwroot")):
return candidate
return None
def set_perm(sage_root, role, path):
script = os.path.join(sage_root, "set_role_perm.py")
cmd = [os.path.join(sage_root, "py3/bin/python"), script, role, path]
print(f" {role} {path}")
subprocess.run(cmd, cwd=sage_root, capture_output=True)
def main():
sage_root = find_sage_root()
if not sage_root:
print("ERROR: Sage root not found")
sys.exit(1)
print("Registering voucher RBAC permissions...")
# any (公开)
any_paths = [
"/voucher/menu.ui",
]
# logined (登录后)
logined_paths = [
"/voucher",
"/voucher/index.ui",
"/voucher/voucher_template_list",
"/voucher/voucher_template_list/index.ui",
"/voucher/voucher_rule_list",
"/voucher/voucher_rule_list/index.ui",
"/voucher/voucher_instance_list",
"/voucher/voucher_instance_list/index.ui",
"/voucher/voucher_usage_log_list",
"/voucher/voucher_usage_log_list/index.ui",
"/voucher/api/template/voucher_template_create.dspy",
"/voucher/api/template/voucher_template_update.dspy",
"/voucher/api/template/voucher_template_delete.dspy",
"/voucher/api/template/voucher_template_options.dspy",
"/voucher/api/rule/voucher_rule_create.dspy",
"/voucher/api/rule/voucher_rule_update.dspy",
"/voucher/api/rule/voucher_rule_delete.dspy",
"/voucher/api/instance/voucher_instance_create.dspy",
"/voucher/api/instance/voucher_instance_update.dspy",
"/voucher/api/instance/voucher_instance_delete.dspy",
"/voucher/api/instance/voucher_instance_options.dspy",
"/voucher/api/usage/voucher_usage_log_create.dspy",
"/voucher/api/usage/voucher_usage_log_update.dspy",
"/voucher/api/usage/voucher_usage_log_delete.dspy",
"/voucher/api/v1/available.dspy",
"/voucher/api/apply_voucher.dspy",
"/voucher/api/get_available.dspy",
"/voucher/api/rule_types.dspy",
]
for p in any_paths:
set_perm(sage_root, "any", p)
for p in logined_paths:
set_perm(sage_root, "logined", p)
print("Done.")
if __name__ == "__main__":
main()