# -*- coding: utf-8 -*- """world 模块 RBAC 路径注册(显式路径,禁止通配符)。""" import os import sys def find_sage_root(): candidates = [ os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..")), os.path.expanduser("~/repos/sage"), os.path.expanduser("~/sage"), ] for c in candidates: if os.path.isdir(os.path.join(c, "wwwroot")) and os.path.isdir(os.path.join(c, "py3", "bin")): return c return None SAGE_ROOT = find_sage_root() PATHS_ANY = [ "/world/menu.ui", ] PATHS_LOGINED = [ "/world", "/world/index.ui", "/world/world", "/world/world/index.ui", "/world/world/get_world.dspy", "/world/world/add_world.dspy", "/world/world/update_world.dspy", "/world/world/delete_world.dspy", "/world/api/list_worlds.dspy", "/world/api/create_world.dspy", "/world/api/world_update.dspy", "/world/api/world_delete.dspy", "/world/api/get_search_world_type.dspy", "/world/api/get_search_status.dspy", ] def main(): if SAGE_ROOT is None: print("Sage root not found, skip RBAC registration.") return sys.path.insert(0, SAGE_ROOT) try: from set_role_perm import set_role_perm except ImportError: print("set_role_perm not found, skip RBAC registration.") return for p in PATHS_ANY: set_role_perm(p, "any") for p in PATHS_LOGINED: set_role_perm(p, "logined") if __name__ == "__main__": main()