bugfix
This commit is contained in:
parent
d29850c297
commit
ad0b9a2f58
7
script/rbac_roleperm.sh
Normal file
7
script/rbac_roleperm.sh
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
python ~/py/rbac/script/roleperm.py sage rbac owner superuser role permission rolepermission user user role organizationorgtypes
|
||||||
|
python ~/py/rbac/script/roleperm.py sage rbac owner admin user userrole
|
||||||
|
python ~/py/rbac/script/roleperm.py sage rbac customer admin user userrole
|
||||||
|
python ~/py/rbac/script/roleperm.py sage rbac reseller admin user userrole
|
||||||
|
|
64
script/roleperm.py
Executable file
64
script/roleperm.py
Executable file
@ -0,0 +1,64 @@
|
|||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import asyncio
|
||||||
|
from sqlor.dbpools import DBPools
|
||||||
|
from appPublic.jsonConfig import getConfig
|
||||||
|
from appPublic.uniqueID import getID
|
||||||
|
from appPublic.asynciorun import run
|
||||||
|
|
||||||
|
async def set_role_perm(dbname, module, orgtype, role, tblname):
|
||||||
|
db = DBPools()
|
||||||
|
async with db.sqlorContext(dbname) as sor:
|
||||||
|
paths = [
|
||||||
|
f'/{module}/{tblname}/index.ui',
|
||||||
|
f'/{module}/{tblname}/get_{tblname}.dspy',
|
||||||
|
f'/{module}/{tblname}/add_{tblname}.dspy',
|
||||||
|
f'/{module}/{tblname}/delete_{tblname}.dspy',
|
||||||
|
f'/{module}/{tblname}/update_{tblname}.dspy'
|
||||||
|
]
|
||||||
|
for pat in paths:
|
||||||
|
recs = await sor.R('permission', {'path': pat})
|
||||||
|
if len(recs) == 0:
|
||||||
|
permid = getID()
|
||||||
|
await sor.C('permission', {'id':permid, 'path':pat})
|
||||||
|
else:
|
||||||
|
permid = recs[0].id
|
||||||
|
recs = await sor.R('role', {'orgtypeid':orgtype, 'name':role})
|
||||||
|
if len(recs) == 0:
|
||||||
|
roleid = getID()
|
||||||
|
await sor.C('role', {
|
||||||
|
'id':roleid,
|
||||||
|
'name':role,
|
||||||
|
'orgtypeid':orgtype
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
roleid = recs[0].id
|
||||||
|
await sor.C('rolepermission', {
|
||||||
|
'id':getID(),
|
||||||
|
'roleid':roleid,
|
||||||
|
'permid':permid
|
||||||
|
})
|
||||||
|
print(f'{orgtype=}, {role=}, {tblname=} permission configured')
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
if len(sys.argv) < 6:
|
||||||
|
print(f'{sys.argv[0]} dbname module orgtype role tblname ...\n')
|
||||||
|
sys.exit(1)
|
||||||
|
dbname = sys.argv[1]
|
||||||
|
module = sys.argv[2]
|
||||||
|
orgtype = sys.argv[3]
|
||||||
|
role = sys.argv[4]
|
||||||
|
for tblname in sys.argv[5:]:
|
||||||
|
await set_role_perm(dbname, module, orgtype, role, tblname)
|
||||||
|
|
||||||
|
def run(coro):
|
||||||
|
p = '.'
|
||||||
|
config = getConfig(p, {'woridir':p})
|
||||||
|
DBPools(config.databases)
|
||||||
|
loop = asyncio.new_event_loop()
|
||||||
|
asyncio.set_event_loop(loop)
|
||||||
|
loop.run_until_complete(coro())
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
run(main)
|
||||||
|
|
@ -4,7 +4,7 @@ dbname = await rfexe('get_module_dbname', 'sage')
|
|||||||
async with db.sqlorContext(dbname) as sor:
|
async with db.sqlorContext(dbname) as sor:
|
||||||
orgid = await register_user(sor, params_kw)
|
orgid = await register_user(sor, params_kw)
|
||||||
try:
|
try:
|
||||||
ownerid = await get_owner_orgid(sor)
|
ownerid = await get_owner_orgid(sor, orgid)
|
||||||
await openCustomerAccounts(sor, ownerid, orgid)
|
await openCustomerAccounts(sor, ownerid, orgid)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
fe = format_exc()
|
fe = format_exc()
|
||||||
|
Loading…
Reference in New Issue
Block a user