entity/scripts/load_path.py

63 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""entity 模块 RBAC 权限注册scripts/load_path.py
每次代码变更如有新 path 出现,需同步更新本脚本。禁止通配符,路径全显式。
"""
import os
import sys
HERE = os.path.dirname(os.path.abspath(__file__))
# 显式路径清单(禁止 % / * 通配符)
PATHS_LOGINED = [
# 页面
'/entity/index.ui',
'/entity/import_page.ui',
# CRUD 列表xls2ui 生成的别名目录 5 件套)
'/entity/entity_list',
'/entity/entity_list/index.ui',
'/entity/entity_list/get_entity_list.dspy',
'/entity/entity_list/add_entity_list.dspy',
'/entity/entity_list/update_entity_list.dspy',
'/entity/entity_list/delete_entity_list.dspy',
'/entity/entity_import_list',
'/entity/entity_import_list/index.ui',
'/entity/entity_import_list/get_entity_import_list.dspy',
'/entity/entity_import_list/add_entity_import_list.dspy',
'/entity/entity_import_list/update_entity_import_list.dspy',
'/entity/entity_import_list/delete_entity_import_list.dspy',
# REST API统一 /api/* 前缀)
'/entity/api/entity_list.dspy',
'/entity/api/entity_get.dspy',
'/entity/api/entity_create.dspy',
'/entity/api/entity_update.dspy',
'/entity/api/entity_delete.dspy',
'/entity/api/entity_import.dspy',
'/entity/api/get_search_world_id.dspy',
'/entity/api/get_search_scene_id.dspy',
'/entity/api/get_search_entity_type.dspy',
'/entity/api/get_search_status.dspy',
'/entity/api/get_search_import_status.dspy',
]
PATHS_ANY = []
def main():
sys.path.insert(0, HERE)
try:
from set_role_perm import set_role_perm
except Exception:
# 找不到 set_role_perm 时回退到中央 sage/load_path.py 已注册的路径,仅提示
print('WARN: set_role_perm 不可用,请确保中央 load_path.py 已包含上述路径')
return
for path in PATHS_LOGINED:
set_role_perm(path, 'logined')
for path in PATHS_ANY:
set_role_perm(path, 'any')
print(f'entity: registered {len(PATHS_LOGINED)} logined + {len(PATHS_ANY)} any paths')
if __name__ == '__main__':
main()