rbac/wwwroot/api/update_user.dspy
yumoqing 1e2897d8d4 fix: enable/disable 后自动刷新表格 + 捕获真实错误
1. record_toolbar 添加 name 字段 (enable_user/disable_user)
2. 新增 binds: script bind 用 fetch 调用 dspy,成功后 render() 刷新
3. api/add_user.dspy + api/update_user.dspy 用 try/except 捕获真实异常
2026-06-29 15:50:18 +08:00

34 lines
1.2 KiB
Plaintext

ns = params_kw.copy()
for k,v in ns.items():
if v == 'NaN' or v == 'null':
ns[k] = None
for k in list(ns.keys()):
if k.endswith('_text'):
ns.pop(k, None)
userorgid = await get_userorgid()
if not userorgid:
return {"widgettype":"Error","options":{"title":"Authorization Error","timeout":3,"cwidth":16,"cheight":9,"message":"Please login"}}
ns['orgid'] = userorgid
if params_kw.get('password'):
ns['password'] = password_encode(params_kw.get('password'))
else:
ns.pop('password', None)
try:
db = DBPools()
dbname = get_module_dbname('rbac')
async with db.sqlorContext(dbname) as sor:
ns1 = {"orgid": userorgid, "id": params_kw.id}
recs = await sor.R('users', ns1)
if len(recs) < 1:
return {"widgettype":"Error","options":{"title":"Update Error","cwidth":16,"cheight":9,"timeout":3,"message":"Record no exist or with wrong ownership"}}
r = await sor.U('users', ns)
debug('update success')
return {"widgettype":"Message","options":{"title":"Update Success","cwidth":16,"cheight":9,"timeout":3,"message":"ok"}}
except Exception as e:
debug(f'update_user error: {format_exc()}')
return {"widgettype":"Error","options":{"title":"Update Error","cwidth":16,"cheight":9,"timeout":5,"message":str(e)}}