70 lines
2.0 KiB
Python
70 lines
2.0 KiB
Python
"""Generate RBAC permissions for msp module paths.
|
|
|
|
Run from Sage root with Sage venv:
|
|
cd ~/repos/sage && ./py3/bin/python ../msp/scripts/load_path.py
|
|
"""
|
|
import os
|
|
import sys
|
|
import asyncio
|
|
|
|
sage_root = os.environ.get('SAGE_ROOT')
|
|
if sage_root and sage_root not in sys.path:
|
|
sys.path.insert(0, sage_root)
|
|
|
|
from sqlor.dbpools import DBPools
|
|
from appPublic.jsonConfig import getConfig
|
|
from appPublic.dictObject import DictObject
|
|
from appPublic.uniqueID import getID
|
|
|
|
|
|
paths = [
|
|
("/msp", "logined"),
|
|
("/msp/index.ui", "logined"),
|
|
("/msp/menu.ui", "any"),
|
|
("/msp/accordion.ui", "logined"),
|
|
("/msp/app_panel.ui", "logined"),
|
|
("/msp/bottom.ui", "logined"),
|
|
("/msp/center.ui", "logined"),
|
|
("/msp/connecthost.ui", "logined"),
|
|
("/msp/connecthost.xterm", "logined"),
|
|
("/msp/keypress.ui", "logined"),
|
|
("/msp/msp_profile.md", "logined"),
|
|
("/msp/msp_profile.ui", "logined"),
|
|
("/msp/sagelog.ui", "logined"),
|
|
("/msp/sagelog.xterm", "logined"),
|
|
("/msp/test.ui", "logined"),
|
|
("/msp/top.ui", "logined"),
|
|
("/msp/get_code.dspy", "logined"),
|
|
("/msp/imgs/%", "any"),
|
|
]
|
|
|
|
|
|
async def main():
|
|
config = getConfig('.')
|
|
DBPools(config.databases)
|
|
dbname = 'sage'
|
|
async with DBPools().sqlorContext(dbname) as sor:
|
|
cnt = 0
|
|
for path, role in paths:
|
|
r = await sor.sqlExe(
|
|
'select * from permission where permcode = ${permcode}$',
|
|
{'permcode': path}
|
|
)
|
|
if len(r) == 0:
|
|
await sor.sqlExe(
|
|
'''insert into permission (id, permcode, permname, permtype)
|
|
values (${id}$, ${permcode}$, ${permname}$, ${permtype}$)''',
|
|
{
|
|
'id': getID(),
|
|
'permcode': path,
|
|
'permname': path,
|
|
'permtype': role,
|
|
}
|
|
)
|
|
cnt += 1
|
|
print(f'{cnt} path(s) inserted for msp')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
asyncio.run(main())
|