From ad0b9a2f58ee3db0d8742e2c5c21de4715ea9d22 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 16 Jan 2025 17:53:23 +0800 Subject: [PATCH] bugfix --- script/rbac_roleperm.sh | 7 +++++ script/roleperm.py | 64 +++++++++++++++++++++++++++++++++++++++++ www/user/register.dspy | 2 +- 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 script/rbac_roleperm.sh create mode 100755 script/roleperm.py diff --git a/script/rbac_roleperm.sh b/script/rbac_roleperm.sh new file mode 100644 index 0000000..6aeb616 --- /dev/null +++ b/script/rbac_roleperm.sh @@ -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 + diff --git a/script/roleperm.py b/script/roleperm.py new file mode 100755 index 0000000..5aa060d --- /dev/null +++ b/script/roleperm.py @@ -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) + diff --git a/www/user/register.dspy b/www/user/register.dspy index e369e55..c1704b3 100644 --- a/www/user/register.dspy +++ b/www/user/register.dspy @@ -4,7 +4,7 @@ dbname = await rfexe('get_module_dbname', 'sage') async with db.sqlorContext(dbname) as sor: orgid = await register_user(sor, params_kw) try: - ownerid = await get_owner_orgid(sor) + ownerid = await get_owner_orgid(sor, orgid) await openCustomerAccounts(sor, ownerid, orgid) except Exception as e: fe = format_exc()