feat(secret_vault): update_secret_meta(改标签/备注,仅本人+审计;值不可改走删除重存)——管理页行内编辑用

This commit is contained in:
ymq 2026-09-18 14:36:28 +08:00
parent e6ad1cd8ed
commit 6c2a67ecb4

View File

@ -604,6 +604,28 @@ async def delete_secret(sor, *, name: str = "", secret_id: str = "",
return {"ok": True, "message": "已删除 " + row.get("name", "")}
async def update_secret_meta(sor, *, name: str, label: str = "", remark: str = "",
org_id: str = "", user_id: str = "", who: str = "") -> Dict:
"""改标签/备注(**仅本人条目**;值不可改——改值走删除重存,避免指纹/审计歧义)。
管理页2026-09-18 set_secret_status 同款 own_only + _assert_own 双防线
"""
from .audit import record_audit
row = await get_secret_row(sor, name=name, org_id=org_id, user_id=user_id,
own_only=True)
if not row or not _assert_own(row, user_id):
return {"ok": False, "message": "FAIL: 找不到该敏感信息(或不属于你本人)"}
await sor.sqlExe(
"UPDATE " + TABLE + " SET label=${l}$, remark=${r}$, updated_at=NOW() WHERE id=${i}$",
{"l": label or "", "r": remark or "", "i": row["id"]})
try:
await record_audit(org_id or user_id or "", TABLE, row["id"], "secret_meta_update",
who=who or user_id or "agent", detail="name=" + name)
except Exception:
pass
return {"ok": True, "message": name + " 元数据已更新"}
async def set_secret_status(sor, *, name: str, status: str, org_id: str = "",
user_id: str = "", who: str = "") -> Dict:
"""启用/停用active / disabled。停用后不再注入执行环境。"""