feat: add per-module scripts/load_path.py with all RBAC paths
This commit is contained in:
parent
e766111aa1
commit
b146cbd628
@ -1,306 +1,205 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Generate RBAC permissions for supplychain module paths.
|
||||
|
||||
Run from Sage root with Sage venv:
|
||||
cd ~/repos/sage && ./py3/bin/python ../supplychain/scripts/load_path.py
|
||||
"""
|
||||
supplychain 模块 RBAC 权限管理脚本
|
||||
|
||||
使用方法:
|
||||
cd ~/repos/sage
|
||||
./py3/bin/python ~/repos/supplychain/scripts/load_path.py
|
||||
|
||||
此脚本注册 supplychain 模块的所有 RBAC 权限路径。
|
||||
每次代码变更如有新 path 出现,需同步更新本脚本的 paths 列表。
|
||||
|
||||
路径分类:
|
||||
- any: 静态资源/菜单,无需登录
|
||||
- logined: 需要认证的页面和 API
|
||||
- reseller.operator: 运营角色 — 供应商、供销合同管理
|
||||
- reseller.sale: 销售角色 — 二级分销商、分销协议管理
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
import os
|
||||
import sys
|
||||
import asyncio
|
||||
|
||||
# 查找 Sage 根目录
|
||||
def find_sage_root():
|
||||
candidates = [
|
||||
os.path.expanduser("~/repos/sage"),
|
||||
os.path.expanduser("~/sage"),
|
||||
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
|
||||
]
|
||||
for c in candidates:
|
||||
if os.path.isdir(os.path.join(c, "py3")) and os.path.isdir(os.path.join(c, "wwwroot")):
|
||||
return c
|
||||
return None
|
||||
sage_root = os.environ.get('SAGE_ROOT')
|
||||
if sage_root and sage_root not in sys.path:
|
||||
sys.path.insert(0, sage_root)
|
||||
|
||||
SAGE_ROOT = find_sage_root()
|
||||
if not SAGE_ROOT:
|
||||
print("ERROR: Cannot find Sage root directory")
|
||||
sys.exit(1)
|
||||
from sqlor.dbpools import DBPools
|
||||
from appPublic.jsonConfig import getConfig
|
||||
from appPublic.dictObject import DictObject
|
||||
from appPublic.uniqueID import getID
|
||||
|
||||
SET_PERM = os.path.join(SAGE_ROOT, "py3", "bin", "python")
|
||||
SET_PERM_SCRIPT = os.path.join(SAGE_ROOT, "set_role_perm.py")
|
||||
|
||||
if not os.path.exists(SET_PERM_SCRIPT):
|
||||
print(f"ERROR: set_role_perm.py not found at {SET_PERM_SCRIPT}")
|
||||
sys.exit(1)
|
||||
|
||||
# ============================================================
|
||||
# 权限路径定义
|
||||
# ============================================================
|
||||
|
||||
# any — 无需登录,静态资源/菜单
|
||||
PATHS_ANY = [
|
||||
"/supplychain/menu.ui",
|
||||
paths = [
|
||||
("/supplychain", "logined"),
|
||||
("/supplychain/api/calculate_accounting.dspy", "logined"),
|
||||
("/supplychain/api/distribution_agreement_items_create.dspy", "logined"),
|
||||
("/supplychain/api/distribution_agreement_items_delete.dspy", "logined"),
|
||||
("/supplychain/api/distribution_agreement_items_update.dspy", "logined"),
|
||||
("/supplychain/api/distribution_agreements_create.dspy", "logined"),
|
||||
("/supplychain/api/distribution_agreements_delete.dspy", "logined"),
|
||||
("/supplychain/api/distribution_agreements_update.dspy", "logined"),
|
||||
("/supplychain/api/get_search_agreement_id.dspy", "logined"),
|
||||
("/supplychain/api/get_search_contract_id.dspy", "logined"),
|
||||
("/supplychain/api/get_search_orgid.dspy", "logined"),
|
||||
("/supplychain/api/get_search_prodtypeid.dspy", "logined"),
|
||||
("/supplychain/api/get_search_productid.dspy", "logined"),
|
||||
("/supplychain/api/get_search_sub_distributor_id.dspy", "logined"),
|
||||
("/supplychain/api/get_search_sub_reseller_id.dspy", "logined"),
|
||||
("/supplychain/api/get_search_supplier_id.dspy", "logined"),
|
||||
("/supplychain/api/get_search_supply_relation_id.dspy", "logined"),
|
||||
("/supplychain/api/import_supplier_product.dspy", "logined"),
|
||||
("/supplychain/api/platform_supply_products_create.dspy", "logined"),
|
||||
("/supplychain/api/platform_supply_products_delete.dspy", "logined"),
|
||||
("/supplychain/api/platform_supply_products_update.dspy", "logined"),
|
||||
("/supplychain/api/platform_supply_relations_create.dspy", "logined"),
|
||||
("/supplychain/api/platform_supply_relations_delete.dspy", "logined"),
|
||||
("/supplychain/api/platform_supply_relations_update.dspy", "logined"),
|
||||
("/supplychain/api/product_supplier_mapping_create.dspy", "logined"),
|
||||
("/supplychain/api/product_supplier_mapping_delete.dspy", "logined"),
|
||||
("/supplychain/api/product_supplier_mapping_update.dspy", "logined"),
|
||||
("/supplychain/api/query_dist_discount.dspy", "logined"),
|
||||
("/supplychain/api/query_platform_products.dspy", "logined"),
|
||||
("/supplychain/api/query_platform_suppliers.dspy", "logined"),
|
||||
("/supplychain/api/query_supply_discount.dspy", "logined"),
|
||||
("/supplychain/api/sales_ledger_create.dspy", "logined"),
|
||||
("/supplychain/api/sales_ledger_delete.dspy", "logined"),
|
||||
("/supplychain/api/sales_ledger_update.dspy", "logined"),
|
||||
("/supplychain/api/sub_distributors_create.dspy", "logined"),
|
||||
("/supplychain/api/sub_distributors_delete.dspy", "logined"),
|
||||
("/supplychain/api/sub_distributors_update.dspy", "logined"),
|
||||
("/supplychain/api/sub_resellers_create.dspy", "logined"),
|
||||
("/supplychain/api/sub_resellers_delete.dspy", "logined"),
|
||||
("/supplychain/api/sub_resellers_update.dspy", "logined"),
|
||||
("/supplychain/api/supplier_resource_price_create.dspy", "logined"),
|
||||
("/supplychain/api/supplier_resource_price_delete.dspy", "logined"),
|
||||
("/supplychain/api/supplier_resource_price_update.dspy", "logined"),
|
||||
("/supplychain/api/suppliers_create.dspy", "logined"),
|
||||
("/supplychain/api/suppliers_delete.dspy", "logined"),
|
||||
("/supplychain/api/suppliers_update.dspy", "logined"),
|
||||
("/supplychain/api/supply_contract_items_create.dspy", "logined"),
|
||||
("/supplychain/api/supply_contract_items_delete.dspy", "logined"),
|
||||
("/supplychain/api/supply_contract_items_update.dspy", "logined"),
|
||||
("/supplychain/api/supply_contracts_create.dspy", "logined"),
|
||||
("/supplychain/api/supply_contracts_delete.dspy", "logined"),
|
||||
("/supplychain/api/supply_contracts_update.dspy", "logined"),
|
||||
("/supplychain/api/supplychain_accounting_create.dspy", "logined"),
|
||||
("/supplychain/api/supplychain_accounting_delete.dspy", "logined"),
|
||||
("/supplychain/api/supplychain_accounting_update.dspy", "logined"),
|
||||
("/supplychain/distribution_agreement_items_list", "logined"),
|
||||
("/supplychain/distribution_agreement_items_list/add_distribution_agreement_items.dspy", "logined"),
|
||||
("/supplychain/distribution_agreement_items_list/delete_distribution_agreement_items.dspy", "logined"),
|
||||
("/supplychain/distribution_agreement_items_list/get_distribution_agreement_items.dspy", "logined"),
|
||||
("/supplychain/distribution_agreement_items_list/index.ui", "logined"),
|
||||
("/supplychain/distribution_agreement_items_list/update_distribution_agreement_items.dspy", "logined"),
|
||||
("/supplychain/distribution_agreements_list", "logined"),
|
||||
("/supplychain/distribution_agreements_list/add_distribution_agreements.dspy", "logined"),
|
||||
("/supplychain/distribution_agreements_list/delete_distribution_agreements.dspy", "logined"),
|
||||
("/supplychain/distribution_agreements_list/get_distribution_agreements.dspy", "logined"),
|
||||
("/supplychain/distribution_agreements_list/index.ui", "logined"),
|
||||
("/supplychain/distribution_agreements_list/update_distribution_agreements.dspy", "logined"),
|
||||
("/supplychain/platform_supply_products_list", "logined"),
|
||||
("/supplychain/platform_supply_products_list/add_platform_supply_products.dspy", "logined"),
|
||||
("/supplychain/platform_supply_products_list/delete_platform_supply_products.dspy", "logined"),
|
||||
("/supplychain/platform_supply_products_list/get_platform_supply_products.dspy", "logined"),
|
||||
("/supplychain/platform_supply_products_list/index.ui", "logined"),
|
||||
("/supplychain/platform_supply_products_list/update_platform_supply_products.dspy", "logined"),
|
||||
("/supplychain/platform_supply_relations_list", "logined"),
|
||||
("/supplychain/platform_supply_relations_list/add_platform_supply_relations.dspy", "logined"),
|
||||
("/supplychain/platform_supply_relations_list/delete_platform_supply_relations.dspy", "logined"),
|
||||
("/supplychain/platform_supply_relations_list/get_platform_supply_relations.dspy", "logined"),
|
||||
("/supplychain/platform_supply_relations_list/index.ui", "logined"),
|
||||
("/supplychain/platform_supply_relations_list/update_platform_supply_relations.dspy", "logined"),
|
||||
("/supplychain/product_supplier_mapping_list", "logined"),
|
||||
("/supplychain/product_supplier_mapping_list/add_product_supplier_mapping.dspy", "logined"),
|
||||
("/supplychain/product_supplier_mapping_list/delete_product_supplier_mapping.dspy", "logined"),
|
||||
("/supplychain/product_supplier_mapping_list/get_product_supplier_mapping.dspy", "logined"),
|
||||
("/supplychain/product_supplier_mapping_list/index.ui", "logined"),
|
||||
("/supplychain/product_supplier_mapping_list/update_product_supplier_mapping.dspy", "logined"),
|
||||
("/supplychain/sales_ledger_list", "logined"),
|
||||
("/supplychain/sales_ledger_list/add_sales_ledger.dspy", "logined"),
|
||||
("/supplychain/sales_ledger_list/delete_sales_ledger.dspy", "logined"),
|
||||
("/supplychain/sales_ledger_list/get_sales_ledger.dspy", "logined"),
|
||||
("/supplychain/sales_ledger_list/index.ui", "logined"),
|
||||
("/supplychain/sales_ledger_list/update_sales_ledger.dspy", "logined"),
|
||||
("/supplychain/sub_distributors_list", "logined"),
|
||||
("/supplychain/sub_distributors_list/add_sub_distributors.dspy", "logined"),
|
||||
("/supplychain/sub_distributors_list/delete_sub_distributors.dspy", "logined"),
|
||||
("/supplychain/sub_distributors_list/get_sub_distributors.dspy", "logined"),
|
||||
("/supplychain/sub_distributors_list/index.ui", "logined"),
|
||||
("/supplychain/sub_distributors_list/update_sub_distributors.dspy", "logined"),
|
||||
("/supplychain/sub_resellers_list", "logined"),
|
||||
("/supplychain/sub_resellers_list/add_sub_resellers.dspy", "logined"),
|
||||
("/supplychain/sub_resellers_list/delete_sub_resellers.dspy", "logined"),
|
||||
("/supplychain/sub_resellers_list/get_sub_resellers.dspy", "logined"),
|
||||
("/supplychain/sub_resellers_list/index.ui", "logined"),
|
||||
("/supplychain/sub_resellers_list/update_sub_resellers.dspy", "logined"),
|
||||
("/supplychain/supplier_resource_price_list", "logined"),
|
||||
("/supplychain/supplier_resource_price_list/index.ui", "logined"),
|
||||
("/supplychain/suppliers_list", "logined"),
|
||||
("/supplychain/suppliers_list/add_suppliers.dspy", "logined"),
|
||||
("/supplychain/suppliers_list/delete_suppliers.dspy", "logined"),
|
||||
("/supplychain/suppliers_list/get_suppliers.dspy", "logined"),
|
||||
("/supplychain/suppliers_list/index.ui", "logined"),
|
||||
("/supplychain/suppliers_list/update_suppliers.dspy", "logined"),
|
||||
("/supplychain/supply_contract_items_list", "logined"),
|
||||
("/supplychain/supply_contract_items_list/add_supply_contract_items.dspy", "logined"),
|
||||
("/supplychain/supply_contract_items_list/delete_supply_contract_items.dspy", "logined"),
|
||||
("/supplychain/supply_contract_items_list/get_supply_contract_items.dspy", "logined"),
|
||||
("/supplychain/supply_contract_items_list/index.ui", "logined"),
|
||||
("/supplychain/supply_contract_items_list/update_supply_contract_items.dspy", "logined"),
|
||||
("/supplychain/supply_contracts_list", "logined"),
|
||||
("/supplychain/supply_contracts_list/add_supply_contracts.dspy", "logined"),
|
||||
("/supplychain/supply_contracts_list/delete_supply_contracts.dspy", "logined"),
|
||||
("/supplychain/supply_contracts_list/get_supply_contracts.dspy", "logined"),
|
||||
("/supplychain/supply_contracts_list/index.ui", "logined"),
|
||||
("/supplychain/supply_contracts_list/update_supply_contracts.dspy", "logined"),
|
||||
("/supplychain/supplychain_accounting_list", "logined"),
|
||||
("/supplychain/supplychain_accounting_list/add_supplychain_accounting.dspy", "logined"),
|
||||
("/supplychain/supplychain_accounting_list/delete_supplychain_accounting.dspy", "logined"),
|
||||
("/supplychain/supplychain_accounting_list/get_supplychain_accounting.dspy", "logined"),
|
||||
("/supplychain/supplychain_accounting_list/index.ui", "logined"),
|
||||
("/supplychain/supplychain_accounting_list/update_supplychain_accounting.dspy", "logined"),
|
||||
("/supplychain/accounting.ui", "logined"),
|
||||
("/supplychain/distribution_agreements.ui", "logined"),
|
||||
("/supplychain/index.ui", "logined"),
|
||||
("/supplychain/menu.ui", "any"),
|
||||
("/supplychain/provider_detail_reconcile.ui", "logined"),
|
||||
("/supplychain/provider_recharge.ui", "logined"),
|
||||
("/supplychain/provider_reconcile.ui", "logined"),
|
||||
("/supplychain/provider_settlement.ui", "logined"),
|
||||
("/supplychain/reseller_detail_reconcile.ui", "logined"),
|
||||
("/supplychain/reseller_reconcile.ui", "logined"),
|
||||
("/supplychain/reseller_settlement.ui", "logined"),
|
||||
("/supplychain/sub_distributors.ui", "logined"),
|
||||
("/supplychain/suppliers.ui", "logined"),
|
||||
("/supplychain/supply_contracts.ui", "logined"),
|
||||
("/supplychain/add_provider_recharge.dspy", "logined"),
|
||||
("/supplychain/add_provider_settlement.dspy", "logined"),
|
||||
("/supplychain/get_provider_detail_reconcile.dspy", "logined"),
|
||||
("/supplychain/get_provider_recharge.dspy", "logined"),
|
||||
("/supplychain/get_provider_reconcile.dspy", "logined"),
|
||||
("/supplychain/get_provider_settlement.dspy", "logined"),
|
||||
("/supplychain/get_reseller_detail_reconcile.dspy", "logined"),
|
||||
("/supplychain/get_reseller_reconcile.dspy", "logined"),
|
||||
("/supplychain/get_reseller_settlement.dspy", "logined"),
|
||||
("/supplychain/update_provider_recharge.dspy", "logined"),
|
||||
("/supplychain/update_provider_settlement.dspy", "logined"),
|
||||
("/supplychain/update_reseller_settlement.dspy", "logined"),
|
||||
]
|
||||
|
||||
# logined — 需要认证的页面和 API
|
||||
PATHS_LOGINED = [
|
||||
# 模块入口
|
||||
"/supplychain",
|
||||
"/supplychain/index.ui",
|
||||
# 功能页面
|
||||
"/supplychain/suppliers.ui",
|
||||
"/supplychain/supply_contracts.ui",
|
||||
"/supplychain/sub_distributors.ui",
|
||||
"/supplychain/distribution_agreements.ui",
|
||||
"/supplychain/accounting.ui",
|
||||
# CRUD 列表目录(需要 bricks 模板渲染)
|
||||
"/supplychain/suppliers_list",
|
||||
"/supplychain/supply_contracts_list",
|
||||
"/supplychain/supply_contract_items_list",
|
||||
"/supplychain/sub_distributors_list",
|
||||
"/supplychain/distribution_agreements_list",
|
||||
"/supplychain/distribution_agreement_items_list",
|
||||
"/supplychain/supplychain_accounting_list",
|
||||
"/supplychain/platform_supply_relations_list",
|
||||
"/supplychain/platform_supply_products_list",
|
||||
"/supplychain/product_supplier_mapping_list",
|
||||
"/supplychain/supplier_resource_price_list",
|
||||
# CRUD 列表页
|
||||
"/supplychain/suppliers_list/index.ui",
|
||||
"/supplychain/supply_contracts_list/index.ui",
|
||||
"/supplychain/supply_contract_items_list/index.ui",
|
||||
"/supplychain/sub_distributors_list/index.ui",
|
||||
"/supplychain/distribution_agreements_list/index.ui",
|
||||
"/supplychain/distribution_agreement_items_list/index.ui",
|
||||
"/supplychain/supplychain_accounting_list/index.ui",
|
||||
# CRUD API — suppliers
|
||||
"/supplychain/api/suppliers_create.dspy",
|
||||
"/supplychain/api/suppliers_update.dspy",
|
||||
"/supplychain/api/suppliers_delete.dspy",
|
||||
# CRUD API — supply_contracts
|
||||
"/supplychain/api/supply_contracts_create.dspy",
|
||||
"/supplychain/api/supply_contracts_update.dspy",
|
||||
"/supplychain/api/supply_contracts_delete.dspy",
|
||||
# CRUD API — supply_contract_items
|
||||
"/supplychain/api/supply_contract_items_create.dspy",
|
||||
"/supplychain/api/supply_contract_items_update.dspy",
|
||||
"/supplychain/api/supply_contract_items_delete.dspy",
|
||||
# Search API — filter dropdowns
|
||||
"/supplychain/api/get_search_supplier_id.dspy",
|
||||
"/supplychain/api/get_search_contract_id.dspy",
|
||||
"/supplychain/api/get_search_prodtypeid.dspy",
|
||||
"/supplychain/api/get_search_productid.dspy",
|
||||
"/supplychain/api/get_search_sub_reseller_id.dspy",
|
||||
"/supplychain/api/get_search_agreement_id.dspy",
|
||||
"/supplychain/api/get_search_orgid.dspy",
|
||||
"/supplychain/api/get_search_sub_distributor_id.dspy",
|
||||
"/supplychain/api/get_search_supply_relation_id.dspy",
|
||||
# CRUD API — sub_distributors
|
||||
"/supplychain/api/sub_distributors_create.dspy",
|
||||
"/supplychain/api/sub_distributors_update.dspy",
|
||||
"/supplychain/api/sub_distributors_delete.dspy",
|
||||
# CRUD API — distribution_agreements
|
||||
"/supplychain/api/distribution_agreements_create.dspy",
|
||||
"/supplychain/api/distribution_agreements_update.dspy",
|
||||
"/supplychain/api/distribution_agreements_delete.dspy",
|
||||
# CRUD API — distribution_agreement_items
|
||||
"/supplychain/api/distribution_agreement_items_create.dspy",
|
||||
"/supplychain/api/distribution_agreement_items_update.dspy",
|
||||
"/supplychain/api/distribution_agreement_items_delete.dspy",
|
||||
# CRUD API — supplychain_accounting
|
||||
"/supplychain/api/supplychain_accounting_create.dspy",
|
||||
"/supplychain/api/supplychain_accounting_update.dspy",
|
||||
"/supplychain/api/supplychain_accounting_delete.dspy",
|
||||
# 业务 API
|
||||
"/supplychain/api/calculate_accounting.dspy",
|
||||
"/supplychain/api/query_supply_discount.dspy",
|
||||
"/supplychain/api/query_dist_discount.dspy",
|
||||
# 平台供销关系
|
||||
"/supplychain/platform_supply_relations_list/index.ui",
|
||||
"/supplychain/platform_supply_relations_list/get_platform_supply_relations.dspy",
|
||||
"/supplychain/platform_supply_relations_list/add_platform_supply_relations.dspy",
|
||||
"/supplychain/platform_supply_relations_list/update_platform_supply_relations.dspy",
|
||||
"/supplychain/platform_supply_relations_list/delete_platform_supply_relations.dspy",
|
||||
"/supplychain/platform_supply_products_list/index.ui",
|
||||
"/supplychain/platform_supply_products_list/get_platform_supply_products.dspy",
|
||||
"/supplychain/platform_supply_products_list/add_platform_supply_products.dspy",
|
||||
"/supplychain/platform_supply_products_list/update_platform_supply_products.dspy",
|
||||
"/supplychain/platform_supply_products_list/delete_platform_supply_products.dspy",
|
||||
"/supplychain/product_supplier_mapping_list/index.ui",
|
||||
"/supplychain/product_supplier_mapping_list/get_product_supplier_mapping.dspy",
|
||||
"/supplychain/product_supplier_mapping_list/add_product_supplier_mapping.dspy",
|
||||
"/supplychain/product_supplier_mapping_list/update_product_supplier_mapping.dspy",
|
||||
"/supplychain/product_supplier_mapping_list/delete_product_supplier_mapping.dspy",
|
||||
# CRUD API — platform_supply_relations
|
||||
"/supplychain/api/platform_supply_relations_create.dspy",
|
||||
"/supplychain/api/platform_supply_relations_update.dspy",
|
||||
"/supplychain/api/platform_supply_relations_delete.dspy",
|
||||
# CRUD API — platform_supply_products
|
||||
"/supplychain/api/platform_supply_products_create.dspy",
|
||||
"/supplychain/api/platform_supply_products_update.dspy",
|
||||
"/supplychain/api/platform_supply_products_delete.dspy",
|
||||
# CRUD API — product_supplier_mapping
|
||||
"/supplychain/api/product_supplier_mapping_create.dspy",
|
||||
"/supplychain/api/product_supplier_mapping_update.dspy",
|
||||
"/supplychain/api/product_supplier_mapping_delete.dspy",
|
||||
# 平台供应链业务 API
|
||||
"/supplychain/api/query_platform_suppliers.dspy",
|
||||
"/supplychain/api/query_platform_products.dspy",
|
||||
"/supplychain/api/import_supplier_product.dspy",
|
||||
# Supplier resource pricing
|
||||
"/supplychain/supplier_resource_price_list",
|
||||
"/supplychain/supplier_resource_price_list/index.ui",
|
||||
"/supplychain/supplier_resource_price_list/get_supplier_resource_price.dspy",
|
||||
"/supplychain/supplier_resource_price_list/add_supplier_resource_price.dspy",
|
||||
"/supplychain/supplier_resource_price_list/update_supplier_resource_price.dspy",
|
||||
"/supplychain/supplier_resource_price_list/delete_supplier_resource_price.dspy",
|
||||
"/supplychain/api/supplier_resource_price_create.dspy",
|
||||
"/supplychain/api/supplier_resource_price_update.dspy",
|
||||
"/supplychain/api/supplier_resource_price_delete.dspy",
|
||||
]
|
||||
|
||||
# 角色专属权限
|
||||
PATHS_OPERATOR = [
|
||||
"/supplychain/suppliers.ui",
|
||||
"/supplychain/suppliers_list",
|
||||
"/supplychain/suppliers_list/index.ui",
|
||||
"/supplychain/api/suppliers_create.dspy",
|
||||
"/supplychain/api/suppliers_update.dspy",
|
||||
"/supplychain/api/suppliers_delete.dspy",
|
||||
"/supplychain/supply_contracts.ui",
|
||||
"/supplychain/supply_contracts_list",
|
||||
"/supplychain/supply_contracts_list/index.ui",
|
||||
"/supplychain/api/supply_contracts_create.dspy",
|
||||
"/supplychain/api/supply_contracts_update.dspy",
|
||||
"/supplychain/api/supply_contracts_delete.dspy",
|
||||
"/supplychain/supply_contract_items_list",
|
||||
"/supplychain/supply_contract_items_list/index.ui",
|
||||
"/supplychain/api/supply_contract_items_create.dspy",
|
||||
"/supplychain/api/supply_contract_items_update.dspy",
|
||||
"/supplychain/api/supply_contract_items_delete.dspy",
|
||||
# 平台供销关系管理
|
||||
"/supplychain/platform_supply_relations_list",
|
||||
"/supplychain/platform_supply_relations_list/index.ui",
|
||||
"/supplychain/platform_supply_relations_list/get_platform_supply_relations.dspy",
|
||||
"/supplychain/platform_supply_relations_list/add_platform_supply_relations.dspy",
|
||||
"/supplychain/platform_supply_relations_list/update_platform_supply_relations.dspy",
|
||||
"/supplychain/platform_supply_relations_list/delete_platform_supply_relations.dspy",
|
||||
"/supplychain/api/platform_supply_relations_create.dspy",
|
||||
"/supplychain/api/platform_supply_relations_update.dspy",
|
||||
"/supplychain/api/platform_supply_relations_delete.dspy",
|
||||
"/supplychain/platform_supply_products_list",
|
||||
"/supplychain/platform_supply_products_list/index.ui",
|
||||
"/supplychain/platform_supply_products_list/get_platform_supply_products.dspy",
|
||||
"/supplychain/platform_supply_products_list/add_platform_supply_products.dspy",
|
||||
"/supplychain/platform_supply_products_list/update_platform_supply_products.dspy",
|
||||
"/supplychain/platform_supply_products_list/delete_platform_supply_products.dspy",
|
||||
"/supplychain/api/platform_supply_products_create.dspy",
|
||||
"/supplychain/api/platform_supply_products_update.dspy",
|
||||
"/supplychain/api/platform_supply_products_delete.dspy",
|
||||
"/supplychain/product_supplier_mapping_list",
|
||||
"/supplychain/product_supplier_mapping_list/index.ui",
|
||||
"/supplychain/product_supplier_mapping_list/get_product_supplier_mapping.dspy",
|
||||
"/supplychain/product_supplier_mapping_list/add_product_supplier_mapping.dspy",
|
||||
"/supplychain/product_supplier_mapping_list/update_product_supplier_mapping.dspy",
|
||||
"/supplychain/product_supplier_mapping_list/delete_product_supplier_mapping.dspy",
|
||||
"/supplychain/api/product_supplier_mapping_create.dspy",
|
||||
"/supplychain/api/product_supplier_mapping_update.dspy",
|
||||
"/supplychain/api/product_supplier_mapping_delete.dspy",
|
||||
"/supplychain/api/query_platform_suppliers.dspy",
|
||||
"/supplychain/api/query_platform_products.dspy",
|
||||
"/supplychain/api/import_supplier_product.dspy",
|
||||
# Supplier resource pricing (operator manages)
|
||||
"/supplychain/supplier_resource_price_list",
|
||||
"/supplychain/supplier_resource_price_list/index.ui",
|
||||
"/supplychain/supplier_resource_price_list/get_supplier_resource_price.dspy",
|
||||
"/supplychain/supplier_resource_price_list/add_supplier_resource_price.dspy",
|
||||
"/supplychain/supplier_resource_price_list/update_supplier_resource_price.dspy",
|
||||
"/supplychain/supplier_resource_price_list/delete_supplier_resource_price.dspy",
|
||||
"/supplychain/api/supplier_resource_price_create.dspy",
|
||||
"/supplychain/api/supplier_resource_price_update.dspy",
|
||||
"/supplychain/api/supplier_resource_price_delete.dspy",
|
||||
]
|
||||
|
||||
PATHS_SALE = [
|
||||
"/supplychain/sub_distributors.ui",
|
||||
"/supplychain/sub_distributors_list",
|
||||
"/supplychain/sub_distributors_list/index.ui",
|
||||
"/supplychain/api/sub_distributors_create.dspy",
|
||||
"/supplychain/api/sub_distributors_update.dspy",
|
||||
"/supplychain/api/sub_distributors_delete.dspy",
|
||||
"/supplychain/distribution_agreements.ui",
|
||||
"/supplychain/distribution_agreements_list",
|
||||
"/supplychain/distribution_agreements_list/index.ui",
|
||||
"/supplychain/api/distribution_agreements_create.dspy",
|
||||
"/supplychain/api/distribution_agreements_update.dspy",
|
||||
"/supplychain/api/distribution_agreements_delete.dspy",
|
||||
"/supplychain/distribution_agreement_items_list",
|
||||
"/supplychain/distribution_agreement_items_list/index.ui",
|
||||
"/supplychain/api/distribution_agreement_items_create.dspy",
|
||||
"/supplychain/api/distribution_agreement_items_update.dspy",
|
||||
"/supplychain/api/distribution_agreement_items_delete.dspy",
|
||||
]
|
||||
|
||||
# ============================================================
|
||||
# 执行注册
|
||||
# ============================================================
|
||||
|
||||
def run_set_perm(role, path, verbose=True):
|
||||
"""Register a single permission path."""
|
||||
cmd = [SET_PERM, SET_PERM_SCRIPT, role, path]
|
||||
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||
if verbose:
|
||||
output = result.stdout.strip()
|
||||
if output:
|
||||
print(f" {role}: {path} -> {output}")
|
||||
return result.returncode == 0
|
||||
async def main():
|
||||
config = getConfig('.')
|
||||
DBPools(config.databases)
|
||||
async with DBPools().sqlorContext('sage') as sor:
|
||||
cnt = 0
|
||||
for path, role in paths:
|
||||
r = await sor.sqlExe(
|
||||
'select * from permission where path = ${path}$',
|
||||
{'path': path}
|
||||
)
|
||||
if len(r) == 0:
|
||||
await sor.sqlExe(
|
||||
'''insert into permission (id, path, name, permtype)
|
||||
values (${id}$, ${path}$, ${name}$, ${permtype}$)''',
|
||||
{
|
||||
'id': getID(),
|
||||
'path': path,
|
||||
'name': path,
|
||||
'permtype': role,
|
||||
}
|
||||
)
|
||||
cnt += 1
|
||||
print(f'{cnt} path(s) inserted for supplychain')
|
||||
|
||||
|
||||
def register_role_paths(role, paths):
|
||||
"""Register all paths for a role."""
|
||||
count = 0
|
||||
for path in paths:
|
||||
if run_set_perm(role, path, verbose=False):
|
||||
count += 1
|
||||
print(f" {role}: {count}/{len(paths)} paths registered")
|
||||
return count
|
||||
|
||||
|
||||
def main():
|
||||
print(f"Sage root: {SAGE_ROOT}")
|
||||
print(f"set_role_perm.py: {SET_PERM_SCRIPT}")
|
||||
print()
|
||||
|
||||
total = 0
|
||||
|
||||
print("[1/4] Registering 'any' role paths...")
|
||||
total += register_role_paths("any", PATHS_ANY)
|
||||
|
||||
print("[2/4] Registering 'logined' role paths...")
|
||||
total += register_role_paths("logined", PATHS_LOGINED)
|
||||
|
||||
print("[3/4] Registering 'reseller.operator' role paths...")
|
||||
total += register_role_paths("reseller.operator", PATHS_OPERATOR)
|
||||
|
||||
print("[4/4] Registering 'reseller.sale' role paths...")
|
||||
total += register_role_paths("reseller.sale", PATHS_SALE)
|
||||
|
||||
print()
|
||||
print(f"Done. Total {total} permission entries registered.")
|
||||
print()
|
||||
print("NOTE: Restart Sage after permission changes to reload RBAC cache.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(main())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user