- Add SDLC dashboard, pipeline editor, ops center UI - build.sh: clone business modules to pkgs/, xls2ui CRUD, fix created_by - global_func.py: password_encode None-safe wrapper - pipeline_app.py: permission cache warmup removed - load_path.py: RBAC permission registration for all modules - scripts/merge_i18n.py: i18n merge tool - bin/init_perms.py, bin/init_data.py: init scripts - set_role_perm.py: single permission registration - Model uitype fields set for form editing - pipeline_core/pipeline_ops load_path.py scripts
62 lines
2.3 KiB
Python
62 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Initialize RBAC permissions for pipeline modules."""
|
|
import sys, os, asyncio
|
|
|
|
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
ROOT_DIR = os.path.dirname(SCRIPT_DIR)
|
|
sys.path.insert(0, os.path.join(ROOT_DIR, 'py3', 'lib', 'python3.10', 'site-packages'))
|
|
sys.path.insert(0, ROOT_DIR)
|
|
|
|
from sqlor.dbpools import DBPools
|
|
from appPublic.jsonConfig import getConfig
|
|
from appPublic.folderUtils import ProgramPath
|
|
from appPublic.uniqueID import getID
|
|
from ahserver.serverenv import ServerEnv
|
|
from ahserver.globalEnv import initEnv
|
|
|
|
PERMS = [
|
|
('/pipeline_core/', '产线管理访问', 'pipeline_core', 'logined'),
|
|
('/pipeline-sdlc/', '开发产线访问', 'pipeline_sdlc', 'logined'),
|
|
('/pipeline_ops/', '运营管理访问', 'pipeline_ops', 'logined'),
|
|
('/pipeline_dist/', '分销管理访问', 'pipeline_dist', 'logined'),
|
|
('/pipeline_task/', '任务中心访问', 'pipeline_task', 'logined'),
|
|
('/showcase/', '展示平台访问', 'showcase', 'guest'),
|
|
('/', '应用首页', 'app', 'guest'),
|
|
]
|
|
|
|
async def init_perms():
|
|
config = getConfig(ROOT_DIR, NS={'workdir': ROOT_DIR, 'ProgramPath': ProgramPath()})
|
|
DBPools(config.databases)
|
|
initEnv()
|
|
env = ServerEnv()
|
|
env.get_module_dbname = lambda m: 'sage'
|
|
|
|
async with DBPools().sqlorContext('sage') as sor:
|
|
for path, name, perm_type, role_name in PERMS:
|
|
# Build safe SQL with repr
|
|
sql = "SELECT id FROM permission WHERE path=" + repr(path) + " LIMIT 1"
|
|
existing = await sor.sqlExe(sql, {})
|
|
if existing:
|
|
print('SKIP {:<8s} {}'.format(role_name, path))
|
|
continue
|
|
|
|
pid = getID()
|
|
await sor.C('permission', {
|
|
'id': pid, 'name': name, 'path': path,
|
|
'permtype': perm_type
|
|
})
|
|
role_sql = "SELECT id FROM role WHERE name=" + repr(role_name) + " LIMIT 1"
|
|
role_recs = await sor.sqlExe(role_sql, {})
|
|
if role_recs:
|
|
await sor.C('rolepermission', {
|
|
'id': getID(),
|
|
'roleid': role_recs[0].id,
|
|
'permid': pid
|
|
})
|
|
print('ADD {:<8s} {}'.format(role_name, path))
|
|
|
|
print('\nInitialized {} permissions'.format(len(PERMS)))
|
|
|
|
if __name__ == '__main__':
|
|
asyncio.run(init_perms())
|