feat: 业务链条发布审核流程 + 编辑器去除岗位职责输入框
- 发布改为可选「确认审核 / 直接发布」:链条编辑页与圆桌「业务链条」弹窗行为一致;审核中可撤回 - 管理员在业务链条列表新增「待审核」筛选,审核发布后进入公共库 - 后端 roundtable_chains 新增 pending_review 字段(启动期自动补列)与 scope=pending 筛选;新增审核流程测试 - 编辑器席位去掉「岗位职责」输入框(保存时存量值原样保留)
This commit is contained in:
1 parent
40d06b781a
commit
8c3d6a02fc
9 files changed
+462
-81
No files matched your search
@@ -6,7 +6,7 @@ following this order. Bound to the requesting user (not the browser), so it
|
||||
follows the account across devices/sessions — same model as roundtable drafts.
|
||||
|
||||
Routes (prefix ``/api/roundtable-chains``):
|
||||
GET "" list chains (``scope=mine``默认 / ``public`` / ``all`` 仅管理员)
|
||||
GET "" list chains (``scope=mine``默认 / ``public`` / ``pending`` / ``all`` 后两者仅管理员)
|
||||
POST "" create a chain
|
||||
GET "/{chain_id}" one chain
|
||||
PUT "/{chain_id}" partial update (title / description / seats)
|
||||
@@ -96,6 +96,9 @@ class ChainResponse(BaseModel):
|
||||
is_public: bool = False
|
||||
# 启停状态:True = 启用(可选入研讨);False = 停用。缺省 True。
|
||||
enabled: bool = True
|
||||
# 「待审核」标记:True = owner 已提交审核(等待管理员在「待审核」筛选里发布);
|
||||
# 管理员发布时随 is_public=True 一起清回 False。缺省 False。
|
||||
pending_review: bool = False
|
||||
# 是否当前用户所有(仅本人可编辑 / 删除 / 发布;公共筛选里别人的链条 is_mine=False)。
|
||||
is_mine: bool = True
|
||||
# 配置者(owner)的 user_id 及解析后的可读用户名(email)。owner_name 由路由层
|
||||
@@ -140,6 +143,9 @@ class ChainUpdateRequest(BaseModel):
|
||||
is_public: bool | None = None
|
||||
# 启停开关(True 启用 / False 停用);仅 owner / 管理员可改。omit 不改。
|
||||
enabled: bool | None = None
|
||||
# 「待审核」开关(True = 提交审核,owner 在编辑器发起;False = 清除,管理员发布时
|
||||
# 随 is_public=True 一起提交)。omit 不改。
|
||||
pending_review: bool | None = None
|
||||
|
||||
|
||||
# ── helpers ──────────────────────────────────────────────────────────────
|
||||
@@ -303,13 +309,15 @@ async def list_chains(request: Request, scope: str = "mine") -> ChainListRespons
|
||||
``scope`` 查询参数(筛选):
|
||||
- ``mine``(默认):仅当前用户自己的链条;
|
||||
- ``public``:所有**已发布**的公共链条(任何账号均可查看 / 选入研讨);
|
||||
- ``pending``:所有**待审核**(``pending_review=True``)链条(**仅管理员**;
|
||||
非管理员请求 ``pending`` 退化为 ``mine``);
|
||||
- ``all``:所有账号的全部链条(**仅管理员**;非管理员请求 ``all`` 退化为 ``mine``)。
|
||||
其余值按 ``mine`` 处理。
|
||||
"""
|
||||
is_admin = _is_admin(request)
|
||||
normalized_scope = scope if scope in ("mine", "public", "all") else "mine"
|
||||
# 非管理员请求 all → 退化为 mine,绝不越权。
|
||||
if normalized_scope == "all" and not is_admin:
|
||||
normalized_scope = scope if scope in ("mine", "public", "pending", "all") else "mine"
|
||||
# 非管理员请求 pending / all → 退化为 mine,绝不越权。
|
||||
if normalized_scope in ("pending", "all") and not is_admin:
|
||||
normalized_scope = "mine"
|
||||
store = _get_store(request)
|
||||
user_id = _current_user_id(request)
|
||||
|
||||
+6
@@ -69,6 +69,12 @@ class RoundtableChainRow(Base):
|
||||
enabled: Mapped[bool] = mapped_column(
|
||||
Boolean, nullable=False, default=True, server_default="1"
|
||||
)
|
||||
# 「待审核」标记:True = owner 已在编辑器提交审核(发布前需管理员在「待审核」筛选里确认
|
||||
# 发布);管理员发布时置回 False 并同时置 ``is_public=True``。缺省 False,存量链条不受影响。
|
||||
# 索引以支持管理端「待审核」列表筛选。
|
||||
pending_review: Mapped[bool] = mapped_column(
|
||||
Boolean, nullable=False, default=False, server_default="0", index=True
|
||||
)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
BeijingDateTime(), nullable=False, default=lambda: datetime.now(UTC)
|
||||
)
|
||||
|
||||
+10
@@ -64,6 +64,8 @@ class RoundtableChainRepository:
|
||||
"is_public": bool(getattr(row, "is_public", False)),
|
||||
# 启停状态:缺省 True(存量行 / 补列前视为启用)。
|
||||
"enabled": bool(getattr(row, "enabled", True)),
|
||||
# 「待审核」标记:True = owner 已提交审核、等待管理员发布;发布时清回 False。
|
||||
"pending_review": bool(getattr(row, "pending_review", False)),
|
||||
"is_mine": (current_user_id is None) or (row.user_id == current_user_id),
|
||||
# 配置者(owner)的 user_id;路由层据此解析成可读用户名(owner_name)。
|
||||
"owner_id": row.user_id,
|
||||
@@ -79,12 +81,16 @@ class RoundtableChainRepository:
|
||||
``scope``:
|
||||
- ``"mine"``(默认):仅当前用户自己的链条;
|
||||
- ``"public"``:所有**已发布**(``is_public=True``)链条,含本人发布的;
|
||||
- ``"pending"``:所有**待审核**(``pending_review=True``)链条,**仅管理员**(由路由层
|
||||
校验后传 ``is_admin=True``;非管理员误传则按 ``"mine"`` 退化,绝不越权);
|
||||
- ``"all"``:所有账号的全部链条(**仅管理员**,由路由层校验后传 ``is_admin=True``;
|
||||
非管理员误传则按 ``"mine"`` 退化,绝不越权)。
|
||||
其余值按 ``"mine"`` 处理。``is_mine`` 标记每条是否本人所有,供前端判断可否编辑。
|
||||
"""
|
||||
if scope == "public":
|
||||
cond = RoundtableChainRow.is_public.is_(True)
|
||||
elif scope == "pending" and is_admin:
|
||||
cond = RoundtableChainRow.pending_review.is_(True)
|
||||
elif scope == "all" and is_admin:
|
||||
cond = None
|
||||
else:
|
||||
@@ -125,6 +131,7 @@ class RoundtableChainRepository:
|
||||
gather_first=bool(data.get("gather_first") or False),
|
||||
is_public=bool(data.get("is_public") or False),
|
||||
enabled=True if data.get("enabled") is None else bool(data.get("enabled")),
|
||||
pending_review=bool(data.get("pending_review") or False),
|
||||
created_at=now,
|
||||
updated_at=now,
|
||||
)
|
||||
@@ -149,6 +156,7 @@ class RoundtableChainRepository:
|
||||
gather_first=_UNSET,
|
||||
is_public=_UNSET,
|
||||
enabled=_UNSET,
|
||||
pending_review=_UNSET,
|
||||
is_admin: bool = False,
|
||||
) -> dict[str, Any] | None:
|
||||
async with self._sf() as session:
|
||||
@@ -176,6 +184,8 @@ class RoundtableChainRepository:
|
||||
row.is_public = bool(is_public)
|
||||
if enabled is not _UNSET and enabled is not None:
|
||||
row.enabled = bool(enabled)
|
||||
if pending_review is not _UNSET and pending_review is not None:
|
||||
row.pending_review = bool(pending_review)
|
||||
row.updated_at = datetime.now(UTC)
|
||||
await session.commit()
|
||||
await session.refresh(row)
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
"""业务链条「发布审核」流程测试。
|
||||
|
||||
覆盖:
|
||||
- store:``pending_review`` 随 create(缺省 False)/ update 持久化;
|
||||
- store:``scope="pending"`` 仅管理员返回全部待审核链条;非管理员按 ``mine`` 退化;
|
||||
- 完整审核流:owner 提交审核 → 管理员在 pending 列表看到 → 发布(``is_public=True`` +
|
||||
``pending_review=False``)后从 pending 列表消失、进入 public 列表。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
|
||||
|
||||
|
||||
async def _make_repo():
|
||||
from deerflow.persistence.base import Base
|
||||
from deerflow.persistence.roundtable_chains.model import RoundtableChainRow # noqa: F401 注册表
|
||||
from deerflow.persistence.roundtable_chains.sql import RoundtableChainRepository
|
||||
|
||||
engine = create_async_engine("sqlite+aiosqlite:///:memory:")
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
sf = async_sessionmaker(engine, expire_on_commit=False)
|
||||
return RoundtableChainRepository(sf), engine
|
||||
|
||||
|
||||
_SEATS = [
|
||||
{"agent_id": "a", "name": "情报收集", "description": ""},
|
||||
{"agent_id": "b", "name": "环境评估", "description": ""},
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pending_review_flag_roundtrip():
|
||||
repo, engine = await _make_repo()
|
||||
try:
|
||||
row = await repo.create_chain("u1", {"id": "c1", "title": "链", "seats": _SEATS})
|
||||
# 缺省 False。
|
||||
assert row["pending_review"] is False
|
||||
|
||||
# owner 提交审核 → True。
|
||||
updated = await repo.update_chain("c1", "u1", pending_review=True)
|
||||
assert updated is not None and updated["pending_review"] is True
|
||||
|
||||
# 撤回 / 管理员发布清回 → False。
|
||||
updated = await repo.update_chain("c1", "u1", pending_review=False)
|
||||
assert updated is not None and updated["pending_review"] is False
|
||||
finally:
|
||||
await engine.dispose()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_scope_pending_lists_all_users_pending_for_admin():
|
||||
repo, engine = await _make_repo()
|
||||
try:
|
||||
await repo.create_chain("u1", {"id": "c1", "title": "U1 待审", "seats": _SEATS})
|
||||
await repo.create_chain("u1", {"id": "c2", "title": "U1 草稿", "seats": _SEATS})
|
||||
await repo.create_chain("u2", {"id": "c3", "title": "U2 待审", "seats": _SEATS})
|
||||
await repo.update_chain("c1", "u1", pending_review=True)
|
||||
await repo.update_chain("c3", "u2", pending_review=True)
|
||||
|
||||
# 管理员 pending → 只含两条待审核链条(跨账号)。
|
||||
rows = await repo.list_chains("admin", scope="pending", is_admin=True)
|
||||
assert {r["id"] for r in rows} == {"c1", "c3"}
|
||||
|
||||
# 非管理员误传 pending(is_admin=False)→ 退化为 mine:只见自己的(c1/c2),
|
||||
# 绝不越权看到他人待审核链条。
|
||||
rows = await repo.list_chains("u1", scope="pending", is_admin=False)
|
||||
assert {r["id"] for r in rows} == {"c1", "c2"}
|
||||
finally:
|
||||
await engine.dispose()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_full_review_flow_owner_submit_admin_publish():
|
||||
repo, engine = await _make_repo()
|
||||
try:
|
||||
await repo.create_chain("u1", {"id": "c1", "title": "走审核的链", "seats": _SEATS})
|
||||
|
||||
# ① owner 提交审核。
|
||||
await repo.update_chain("c1", "u1", pending_review=True)
|
||||
|
||||
# ② 管理员在「待审核」列表看到。
|
||||
pending = await repo.list_chains("admin", scope="pending", is_admin=True)
|
||||
assert [r["id"] for r in pending] == ["c1"]
|
||||
|
||||
# ③ 管理员审核发布:is_public=True + 清除待审核标记。
|
||||
published = await repo.update_chain(
|
||||
"c1", "admin", is_public=True, pending_review=False, is_admin=True
|
||||
)
|
||||
assert published is not None
|
||||
assert published["is_public"] is True
|
||||
assert published["pending_review"] is False
|
||||
# owner 不变。
|
||||
assert published["owner_id"] == "u1"
|
||||
|
||||
# ④ 发布后:pending 列表为空,public 列表可见(任何账号)。
|
||||
assert await repo.list_chains("admin", scope="pending", is_admin=True) == []
|
||||
public = await repo.list_chains("u2", scope="public")
|
||||
assert [r["id"] for r in public] == ["c1"]
|
||||
finally:
|
||||
await engine.dispose()
|
||||
Reference in new issue
Block a user