pipeline_core/wwwroot/secrets/update_user_secret.dspy

47 lines
2.5 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.

# update_user_secret.dspy - 行内编辑回传Tabular update 整行 POST
# 语义status 与库中不同 → 启停操作label/remark 不同 → 元数据更新。仅本人条目。
import json
uid = await get_user()
if not uid:
return json.dumps({"success": False, "error": "未登录"}, ensure_ascii=False)
p = params_kw or {}
name = str(p.get('name', '') or '').strip()
sid = str(p.get('id', '') or '').strip()
if not name and not sid:
return json.dumps({"success": False, "error": "缺少名称或 id"}, ensure_ascii=False)
org = (await get_userorgid()) or ''
from pipeline_service import secret_vault as sv
msgs = []
async with DBPools().sqlorContext('pipeline') as sor:
row = await sv.get_secret_row(sor, name=name or None, secret_id=sid or None,
org_id=org, user_id=uid, own_only=True)
if not row:
return json.dumps({"success": False, "error": "找不到该凭据(或不属于你本人)"},
ensure_ascii=False)
cur_name = row.get("name", "")
cur_status = str(row.get("status", "") or "active")
new_status = str(p.get('status', '') or '').strip()
if new_status and new_status != cur_status:
if new_status not in ('active', 'disabled'):
return json.dumps({"success": False, "error": "status 须为 active/disabled"},
ensure_ascii=False)
r = await sv.set_secret_status(sor, name=cur_name, status=new_status,
org_id=org, user_id=uid, who=uid)
if not r.get("ok"):
return json.dumps({"success": False, "error": r.get("message", "")},
ensure_ascii=False)
msgs.append(r.get("message", ""))
new_label = str(p.get('label', '') or '')
new_remark = str(p.get('remark', '') or '')
if new_label != str(row.get('label', '') or '') or new_remark != str(row.get('remark', '') or ''):
r = await sv.update_secret_meta(sor, name=cur_name, label=new_label,
remark=new_remark, org_id=org, user_id=uid, who=uid)
if not r.get("ok"):
return json.dumps({"success": False, "error": r.get("message", "")},
ensure_ascii=False)
msgs.append(r.get("message", ""))
await sor.sqlExe("COMMIT", {})
if msgs:
return json.dumps({"success": True, "message": "".join(msgs)}, ensure_ascii=False)
return json.dumps({"success": True, "message": "无变更"}, ensure_ascii=False)