voucher/scripts/load_path.py
yumoqing 2c56aa904a feat: 代金券模块初始实现
- 4张表: voucher_template, voucher_rule, voucher_instance, voucher_usage_log
- 可配置规则引擎: registry + validators + engine
- 8种内置规则: min_amount, max_amount, applicable_product_type,
  applicable_product, exclude_product, max_usage_count, valid_period, user_level
- CRUD定义 + API接口 + 前端页面
- SQL建表脚本 + RBAC权限配置
- 一次性使用,不找零
2026-05-29 00:28:01 +08:00

76 lines
2.4 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/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()