#!/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()