pipeline-sdlc/wwwroot/api/check_perm.dspy
2026-08-12 12:08:05 +08:00

19 lines
777 B
Plaintext

# check_perm.dspy
dbname = get_module_dbname('rbac')
async with DBPools().sqlorContext(dbname) as sor:
# Search for up_login in permissions
login_perms = await sor.sqlExe(
"SELECT id, path FROM permission WHERE path LIKE '%%up_login%%' OR path LIKE '%%login.ui%%' OR path LIKE '%%rbac/user%%'", {})
result = []
for r in (login_perms or []):
pid = getattr(r, "id", "")
path = getattr(r, "path", "")
# Check if in 'any' role
rp = await sor.sqlExe(
"SELECT roleid FROM rolepermission WHERE permid=${p}$", {"p": pid})
roles = [getattr(r2, "roleid", "") for r2 in (rp or [])]
result.append({"id": pid, "path": path, "roles": roles})
return json.dumps({"login_perms": result}, ensure_ascii=False)