@@ -45,6 +45,7 @@ from ..schemas import clamp_limit, decode_cursor, encode_cursor, ok
|
||||
from ..serializers import item_out, tags_of
|
||||
from ..services.knowledge import create_draft_from_source, find_doc_by_source
|
||||
from ..services.knowledge_index import reindex_document, search_knowledge
|
||||
from ..services.notify import notify, workspace_admins
|
||||
from .attachments import count_for_items, list_for_item
|
||||
|
||||
router = APIRouter(prefix="/workspaces/{ws_id}", tags=["知识库"])
|
||||
@@ -1025,6 +1026,17 @@ async def create_knowledge(body: KnowledgeIn, ctx: MemberDep, session: SessionDe
|
||||
await session.flush()
|
||||
await _log(session, item, ctx.user.id, "knowledge_created", {"generated_by": "human"})
|
||||
await _set_tags_for(session, ws_id, item, body.tag_names)
|
||||
# 知识是团队资产:新建草稿先告诉能发布的人,别让草稿在列表里躺到没人发现。
|
||||
await notify(
|
||||
session,
|
||||
ws_id=ws_id,
|
||||
user_ids=await workspace_admins(session, ws_id),
|
||||
kind="knowledge_draft_created",
|
||||
item_id=item.id,
|
||||
title=f"新的知识草稿:{item.title}",
|
||||
body=f"{ctx.user.nickname or '同事'} 新建了一条知识,核对后可以发布。",
|
||||
actor_id=ctx.user.id,
|
||||
)
|
||||
await audit_record(
|
||||
session,
|
||||
workspace_id=ws_id,
|
||||
@@ -1204,6 +1216,42 @@ async def change_status(
|
||||
target_id=str(item.id),
|
||||
payload={"to": to_status},
|
||||
)
|
||||
# 知识的状态变化要让相关的人知道:提交审议找管理员核对,
|
||||
# 发布/归档则回告作者——否则作者不知道自己的草稿已经被团队采纳。
|
||||
actor_name = ctx.user.nickname or "同事"
|
||||
if body.action == "submit_review":
|
||||
await notify(
|
||||
session,
|
||||
ws_id=ws_id,
|
||||
user_ids=await workspace_admins(session, ws_id),
|
||||
kind="knowledge_review_requested",
|
||||
item_id=item.id,
|
||||
title=f"待核对:{item.title}",
|
||||
body=f"{actor_name} 提交了一份知识,核对后可以发布。",
|
||||
actor_id=ctx.user.id,
|
||||
)
|
||||
elif body.action == "publish":
|
||||
await notify(
|
||||
session,
|
||||
ws_id=ws_id,
|
||||
user_ids=(doc.author_id,),
|
||||
kind="knowledge_published",
|
||||
item_id=item.id,
|
||||
title=f"「{item.title}」已发布",
|
||||
body=f"{actor_name} 发布了这份知识,现在可以被团队检索到。",
|
||||
actor_id=ctx.user.id,
|
||||
)
|
||||
elif body.action == "archive":
|
||||
await notify(
|
||||
session,
|
||||
ws_id=ws_id,
|
||||
user_ids=(doc.author_id,),
|
||||
kind="knowledge_archived",
|
||||
item_id=item.id,
|
||||
title=f"「{item.title}」已归档",
|
||||
body=f"{actor_name} 把它归档了,检索不再返回它。",
|
||||
actor_id=ctx.user.id,
|
||||
)
|
||||
await session.flush()
|
||||
if body.action == "publish":
|
||||
# 发布后立刻建索引:检索只认 published,不在这里建就要等定时任务,
|
||||
@@ -1270,6 +1318,16 @@ async def promote_to_knowledge(
|
||||
await _log(
|
||||
session, doc_item, ctx.user.id, "knowledge_created", {"source_item_id": str(source.id)}
|
||||
)
|
||||
await notify(
|
||||
session,
|
||||
ws_id=ws_id,
|
||||
user_ids=await workspace_admins(session, ws_id),
|
||||
kind="knowledge_draft_created",
|
||||
item_id=doc_item.id,
|
||||
title=f"从事项沉淀了知识:{doc_item.title}",
|
||||
body=f"{ctx.user.nickname or '同事'} 把「{source.title}」沉淀成草稿,核对后可以发布。",
|
||||
actor_id=ctx.user.id,
|
||||
)
|
||||
await audit_record(
|
||||
session,
|
||||
workspace_id=ws_id,
|
||||
|
||||
Reference in New Issue
Block a user