fix: get_upapps和get_organizations用属性访问替代字典访问(sqlExe返回对象)

This commit is contained in:
yumoqing 2026-05-31 15:36:13 +08:00
parent dc007a30a9
commit 314da7ae44
2 changed files with 16 additions and 28 deletions

View File

@ -1,19 +1,12 @@
#!/usr/bin/env python3
import json
result = [] result = []
try: async with get_sor_context(request._run_ns, 'rbac') as sor:
async with get_sor_context(request._run_ns, 'rbac') as sor: user_orgid = await get_userorgid()
user_orgid = await get_userorgid() all_orgs = await sor.sqlExe(
orgs = await sor.R('organization', {'id': user_orgid}) "select id, orgname from organization where id = ${id}$ or parentid = ${id}$ order by orgname",
# Get current org and its children {'id': user_orgid}
all_orgs = await sor.sqlExe( )
"select id, orgname from organization where id = ${id}$ or parentid = ${id}$ order by orgname", if all_orgs:
{'id': user_orgid} result = [{'value': r.id, 'text': r.orgname} for r in all_orgs]
)
result = [{'value': r['id'], 'text': r['orgname']} for r in (all_orgs or [])]
except Exception as e:
pass
return json.dumps(result, ensure_ascii=False, default=str) return json.dumps(result, ensure_ascii=False, default=str)

View File

@ -1,17 +1,12 @@
#!/usr/bin/env python3
import json
result = [] result = []
try: async with get_sor_context(request._run_ns, 'uapi') as sor:
async with get_sor_context(request._run_ns, 'uapi') as sor: user_orgid = await get_userorgid()
user_orgid = await get_userorgid() apps = await sor.sqlExe(
apps = await sor.sqlExe( "select id, name from upapp where ownerid = ${ownerid}$ or ownerid is null order by name",
"select id, name from upapp where ownerid = ${ownerid}$ or ownerid is null order by name", {'ownerid': user_orgid}
{'ownerid': user_orgid} )
) if apps:
result = [{'value': r['id'], 'text': r['name']} for r in (apps or [])] result = [{'value': r.id, 'text': r.name} for r in apps]
except Exception as e:
pass
return json.dumps(result, ensure_ascii=False, default=str) return json.dumps(result, ensure_ascii=False, default=str)