rag/wwwroot/knowledge_bases_list/role_options.dspy

31 lines
1.2 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 角色多选选项value={orgtypeid}.{name}(与 RBAC 校验格式一致)
ns = params_kw.copy()
db = DBPools()
dbname = get_module_dbname('rag')
opts = [{"value": "*", "text": "*(全部角色)"}]
try:
async with db.sqlorContext(dbname) as sor:
recs = await sor.sqlExe(
"SELECT DISTINCT orgtypeid, name FROM role "
"WHERE orgtypeid IS NOT NULL AND name IS NOT NULL "
"ORDER BY orgtypeid, name LIMIT 60", {})
await sor.sqlExe("COMMIT", {})
seen = set()
for r in (recs or []):
o = getattr(r, 'orgtypeid', '') or ''
n = getattr(r, 'name', '') or ''
if not o or not n:
continue
key = o + '.' + n
if key in seen:
continue
seen.add(key)
opts.append({"value": key, "text": key})
# 机构通配选项
orgs = sorted({(getattr(r, 'orgtypeid', '') or '') for r in (recs or []) if getattr(r, 'orgtypeid', '')})
for o in orgs:
opts.append({"value": o + ".*", "text": o + ".*(该机构全部)"})
except Exception as e:
info('role_options: ' + str(e))
return json.dumps(opts, ensure_ascii=False)