This commit is contained in:
yumoqing 2026-03-20 15:44:25 +08:00
parent 40908cb093
commit 4bebb9c3ee
2 changed files with 1688 additions and 0 deletions

1615
load_path.py Normal file

File diff suppressed because it is too large Load Diff

73
set_role_perm.py Normal file
View File

@ -0,0 +1,73 @@
import sys
import asyncio
from sqlor.dbpools import DBPools
from appPublic.jsonConfig import getConfig
from appPublic.uniqueID import getID
async def delete_anonymous_perm(sor, permid):
await sor.D('rolepermission', {
'roleid': 'anonymous',
'permid': permid
})
async def add_roleperm(sor, roleid, path, permid=None):
if permid is None:
perms = await sor.R('permission', {'path', path})
if perms:
permid = perms[0].id
ns = {
'roleid': roleid
'permid': permid
}
recs = await sor.R('rolepermission', ns)
if recs:
print(f'{role}, {path} 已经存在')
return
await sor.C('rolepermission', {
'id': getID(),
'roleid': 'anonymous',
'perid': p.id
}
print(f'{role}, {path} perm add')
return
async def main():
config = getConfig('.')
db = DBPools(config.databases)
if len(sys.argv) < 3:
print(f'{sys.argv[0]} role path')
sys.exit(1)
role = sys.argv[1]
path = sys.argv[2]
async with db.sqlorContext('sage') as sor:
perms = None
if '%' in path:
perms = await sor.sqlExe('select * from permission where path like ${path}$", {'path': path})
else:
perms = await sor.R('permission', {'path', path})
if role in ['anonymous', 'logined']:
for p in perms:
await add_roleperm(sor, role, p.id)
return
"""
if role == customer.*' # 客户企业的任意角色
if role == '*.admin' # 任意类型的其他的管理员
"""
orgtypeid, name = role.split('.')
ns = {
'orgtypeid': orgtypeid,
'name': name
}
roles = await sor.R('role', ns.copy())
if not roles:
ns['id'] = getID()
await sor.C('role', ns.copy())
for p in perms:
await add_roleperm(sor, ns['id'], path, permid=p.id)
await delete_anonymous_perm(sor, p.id)
if __name__ == '__main__':
asyncio.get_event_loop().run_until_complete(main())