Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
黄南光
/
wiki_knowledge
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 90acd053
authored
Sep 14, 2026
by
黄南光
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
新增项目知识库
1 parent
e2b625d5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
200 additions
and
311 deletions
config.py
frontend/src/app/login/page.tsx
frontend/src/app/system/kb/page.tsx
frontend/src/components/Sidebar.tsx
frontend/src/components/system/OrgTree.tsx
frontend/src/lib/auth.ts
frontend/src/lib/oaEnums.ts
main.py
scripts/migrate_kb_paths.py
src/api/routes/kb.py
src/database/models.py
src/database/schema_sync.py
src/services/oa/enums.py
src/services/oa/kb_paths.py
src/services/oa/kb_provision.py
src/services/oa/perms.py
src/services/oa/seed.py
config.py
View file @
90acd05
...
...
@@ -46,6 +46,7 @@ BASE_DIR = os.path.abspath(os.path.dirname(__file__))
KB_ROOT_DIR
=
os
.
path
.
join
(
BASE_DIR
,
"ware"
,
"kb"
)
# 所有知识库的物理根
KB_BASE_ROOT
=
os
.
path
.
join
(
KB_ROOT_DIR
,
"base"
)
# 基础库命名空间根
KB_DEPT_ROOT
=
os
.
path
.
join
(
KB_ROOT_DIR
,
"dept"
)
# 部门库命名空间根
KB_PROJECT_ROOT
=
os
.
path
.
join
(
KB_ROOT_DIR
,
"project"
)
# 项目库命名空间根(按人协作)
COMM_KB_ROOT
=
os
.
path
.
join
(
KB_BASE_ROOT
,
"main"
)
# 内置公共基础库命名空间根
RAW_DIR
=
os
.
path
.
join
(
COMM_KB_ROOT
,
"raw"
)
# 原始文档(内置公共基础库)
WIKI_DIR
=
os
.
path
.
join
(
COMM_KB_ROOT
,
"wiki"
)
# 生成的 Wiki 页面(内置公共基础库)
...
...
@@ -62,7 +63,7 @@ OFFICE_PREVIEW_PDF_DIR = os.path.join(BASE_DIR, "ware", "preview", "pdf") # P
WARE_SKILLS_DIR
=
os
.
path
.
join
(
BASE_DIR
,
"ware"
,
"skills"
)
# 确保必要目录存在
for
_d
in
(
RAW_DIR
,
WIKI_DIR
,
METADATA_DIR
,
VLM_MD_INTERMEDIATES_DIR
,
KB_ROOT_DIR
,
KB_BASE_ROOT
,
KB_DEPT_ROOT
,
WARE_SKILLS_DIR
):
for
_d
in
(
RAW_DIR
,
WIKI_DIR
,
METADATA_DIR
,
VLM_MD_INTERMEDIATES_DIR
,
KB_ROOT_DIR
,
KB_BASE_ROOT
,
KB_DEPT_ROOT
,
KB_PROJECT_ROOT
,
WARE_SKILLS_DIR
):
os
.
makedirs
(
_d
,
exist_ok
=
True
)
...
...
frontend/src/app/login/page.tsx
View file @
90acd05
...
...
@@ -24,7 +24,7 @@ export default function LoginPage() {
setError("");
try {
await login(account.trim(), password);
router.push("/
");
router.push("/
notes"); // 登录后默认落地「知识录入」页
router.refresh();
} catch (err) {
setError(err instanceof Error ? err.message : "登录失败");
...
...
frontend/src/app/system/kb/page.tsx
View file @
90acd05
...
...
@@ -30,6 +30,7 @@ import {
listKbs,
listKbGrants,
listKbOrgTree,
provisionDeptKbs,
removeKb,
revokeKb,
updateKb,
...
...
@@ -65,15 +66,18 @@ function FieldBlock({
);
}
/** 类型标签配色(与下拉里的 TypeTag 一致):基础库=淡蓝、部门库=灰。 */
/** 类型标签配色(与下拉里的 TypeTag 一致):基础库=淡蓝、部门库=灰
、项目库=紫
。 */
const kbTypeTagCls = (kbType: string) =>
kbType === KbType.BASE
? "bg-sky-50 text-sky-600 ring-sky-200"
: "bg-slate-100 text-slate-500 ring-slate-200";
: kbType === KbType.PROJECT
? "bg-violet-50 text-violet-600 ring-violet-200"
: "bg-slate-100 text-slate-500 ring-slate-200";
const KB_TYPE_OPTIONS = [
{ value: KbType.DEPT, label: "部门库", desc: "绑定唯一 Owner 部门(叶子),本部门成员可维护,落 ware/kb/dept/<库id>/" },
{ value: KbType.BASE, label: "基础库", desc: "面向全员的基础知识(默认全员只读),可按需授权 Editor(写)/Reader(读),落 ware/kb/base/<库id>/" },
{ value: KbType.PROJECT, label: "项目库", desc: "创建者为 Owner,按人授 Editor(写)/Reader(读) 协作(类 git),落 ware/kb/project/<库id>/" },
] as const;
/**
...
...
@@ -92,7 +96,7 @@ function KbTypePicker({
disabled?: boolean;
}) {
return (
<div className="grid grid-cols-
2
gap-2.5">
<div className="grid grid-cols-
3
gap-2.5">
{KB_TYPE_OPTIONS.map((opt) => {
const active = value === opt.value;
return (
...
...
@@ -144,6 +148,7 @@ export default function KbPage() {
const [deptTree, setDeptTree] = useState<OaDept[]>([]);
const [creating, setCreating] = useState(false);
const [provisioning, setProvisioning] = useState(false);
const [grantKbTarget, setGrantKbTarget] = useState<KbInfo | null>(null);
const load = useCallback(async () => {
...
...
@@ -208,6 +213,20 @@ export default function KbPage() {
}
};
const onProvisionDept = async () => {
if (!confirm("将为每个「尚未建库」的叶子部门各自新建一个部门库(已有库的部门自动跳过),确认执行?")) return;
setProvisioning(true);
try {
const r = await provisionDeptKbs();
alert(`完成:新建 ${r.created.length} 个部门库,跳过 ${r.skipped.length} 个(已有库)。`);
await load();
} catch (e) {
alert((e as Error).message);
} finally {
setProvisioning(false);
}
};
return (
<SysPage
title="知识库配置"
...
...
@@ -215,6 +234,11 @@ export default function KbPage() {
actions={
<>
<Perm code="kb:create">
<GhostButton onClick={onProvisionDept} disabled={provisioning}>
<Database className="h-4 w-4" /> {provisioning ? "创建中…" : "一键新建部门库"}
</GhostButton>
</Perm>
<Perm code="kb:create">
<PrimaryButton onClick={() => setCreating(true)}>
<Plus className="h-4 w-4" /> 新建知识库
</PrimaryButton>
...
...
@@ -346,7 +370,7 @@ function CreateKbModal({
<Input value={name} onChange={setName} placeholder="如:产品部知识库" />
</FormRow>
<FieldBlock label="知识库类型">
<KbTypePicker value={kbType} onChange={(v) => { setKbType(v); if (v
=== "base
") setOwnerDept(null); }} />
<KbTypePicker value={kbType} onChange={(v) => { setKbType(v); if (v
!== "dept
") setOwnerDept(null); }} />
</FieldBlock>
{kbType === "dept" && (
<FieldBlock
...
...
frontend/src/components/Sidebar.tsx
View file @
90acd05
...
...
@@ -3,7 +3,7 @@
import { useEffect, useState } from "react";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { BookOpen, Database, FileText, Settings, UserRound } from "lucide-react";
import { BookOpen, Database, FileText,
NotebookPen,
Settings, UserRound } from "lucide-react";
import { cn } from "@/lib/utils";
import { fetchMe } from "@/lib/auth";
...
...
@@ -16,6 +16,7 @@ interface NavItem {
}
const NAV_ITEMS: NavItem[] = [
{ href: "/notes", label: "知识录入", icon: NotebookPen },
{ href: "/", label: "Wiki 原始文件", icon: FileText },
{ href: "/wiki-repo", label: "Wiki 知识库", icon: BookOpen },
{ href: "/rag", label: "RAG 工作台", icon: Database },
...
...
frontend/src/components/system/OrgTree.tsx
View file @
90acd05
...
...
@@ -122,10 +122,11 @@ export interface KbTreeNode {
children: KbTreeNode[];
}
/** 依据每个库的 deptIdPath 组织链构建 架构>中心>部门 的树;base
库
单列在最前。 */
/** 依据每个库的 deptIdPath 组织链构建 架构>中心>部门 的树;base
/project 库(无部门)
单列在最前。 */
export function buildKbTree(kbs: KbInfo[]): { base: KbInfo[]; tree: KbTreeNode[] } {
const base = kbs.filter((k) => k.kbType === "base");
const dept = kbs.filter((k) => k.kbType !== "base");
// base(基础库)与 project(项目库)都不挂在组织树上,作为扁平叶子排在最前
const base = kbs.filter((k) => k.kbType !== "dept");
const dept = kbs.filter((k) => k.kbType === "dept");
const roots: KbTreeNode[] = [];
const byKey = new Map<string, KbTreeNode>();
...
...
@@ -241,9 +242,9 @@ function KbCheckNode({
// 从根上消除「基础库旁挂缩进对不齐」的问题。
// ============================================================
/** 库的展示名:
base 用库名,dept 用组织路径(无则退化库名)
。 */
/** 库的展示名:
dept 用组织路径(无则退化库名),base/project 用库名
。 */
export function kbLabel(k: KbInfo): string {
return k.kbType === "
base" ? k.kbName : k.deptPath ||
k.kbName;
return k.kbType === "
dept" ? k.deptPath || k.kbName :
k.kbName;
}
const ACCESS_TAG: Record<string, { label: string; cls: string }> = {
...
...
@@ -265,17 +266,20 @@ function AccessTag({ access }: { access?: string | null }) {
);
}
/** 库类型标签:基础库=淡蓝、部门库=灰(跟在库名后,与权限标签并列右对齐)。 */
/** 库类型标签:基础库=淡蓝、
项目库=紫、
部门库=灰(跟在库名后,与权限标签并列右对齐)。 */
function TypeTag({ kbType }: { kbType?: string }) {
if (!kbType) return null;
const isBase = kbType === "base";
const meta =
kbType === "base"
? { label: "基础库", cls: "bg-sky-50 text-sky-600 ring-sky-200" }
: kbType === "project"
? { label: "项目库", cls: "bg-violet-50 text-violet-600 ring-violet-200" }
: { label: "部门库", cls: "bg-slate-100 text-slate-500 ring-slate-200" };
return (
<span
className={`shrink-0 inline-flex w-[44px] items-center justify-center rounded-full py-[1px] text-[10px] font-medium ring-1 ring-inset ${
isBase ? "bg-sky-50 text-sky-600 ring-sky-200" : "bg-slate-100 text-slate-500 ring-slate-200"
}`}
className={`shrink-0 inline-flex w-[44px] items-center justify-center rounded-full py-[1px] text-[10px] font-medium ring-1 ring-inset ${meta.cls}`}
>
{
isBase ? "基础库" : "部门库"
}
{
meta.label
}
</span>
);
}
...
...
frontend/src/lib/auth.ts
View file @
90acd05
...
...
@@ -515,6 +515,12 @@ export const listKbOrgTree = () => apiJson<{ items: OaDept[] }>("/kb/org-tree");
/** 新建知识库:库名 + 类型;部门库须绑定唯一 Owner 部门(deptId,叶子)。base 库不绑定。 */
export const createKb = (kbName: string, kbType: string = "dept", deptId?: string) =>
apiJson<{ id: string }>("/kb", { method: "POST", body: JSON.stringify({ kbName, kbType, deptId }) });
/** 一键为所有未建库的叶子部门批量新建部门库(已绑定的自动跳过)。 */
export const provisionDeptKbs = () =>
apiJson<{
created: { deptId: string; deptName: string; kbId: string }[];
skipped: { deptId: string; deptName: string; reason: string }[];
}>("/kb/provision-dept", { method: "POST" });
export const updateKb = (
id: string,
body: { kbName?: string; kbType?: string; deptId?: string; status?: string }
...
...
@@ -530,6 +536,81 @@ export const revokeKb = (id: string, grantId: string) =>
/** 删除知识库(逻辑删除,库内有文件会被后端安全拦截)。 */
export
const
removeKb
=
(
id
:
string
)
=>
apiJson
(
`/kb/
${
id
}
`
,
{
method
:
"DELETE"
});
// ============ 项目库(project:用户自建 + 按人协作,类 git)============
export
interface
ProjectKb
{
id
:
string
;
kbName
:
string
;
access
:
"owner"
|
"editor"
|
"reader"
;
isOwner
:
boolean
;
}
export
interface
ProjectCollaborator
{
grantId
:
string
;
userId
:
string
;
userName
:
string
;
access
:
"editor"
|
"reader"
;
}
/** 新建自己的项目库。 */
export
const
createProjectKb
=
(
kbName
:
string
)
=>
apiJson
<
{
id
:
string
}
>
(
"/kb/project"
,
{
method
:
"POST"
,
body
:
JSON
.
stringify
({
kbName
})
});
/** 我能访问的项目库(自建 owner + 被授协作)。 */
export
const
myProjectKbs
=
()
=>
apiJson
<
{
items
:
ProjectKb
[]
}
>
(
"/kb/project/mine"
);
/** 搜索用户供添加协作者(受 kb:project:manage 保护,仅返回选人字段)。 */
export
const
searchProjectUsers
=
(
q
:
string
)
=>
apiJson
<
{
items
:
{
id
:
string
;
name
:
string
;
username
:
string
}[]
}
>
(
`/kb/project/user-search?q=
${
encodeURIComponent
(
q
)}
`
);
/** 列出项目库协作者。 */
export
const
listCollaborators
=
(
kbId
:
string
)
=>
apiJson
<
{
items
:
ProjectCollaborator
[]
}
>
(
`/kb/
${
kbId
}
/collaborators`
);
/** 按人添加/更新协作者(editor=读写 / reader=只读)。 */
export
const
addCollaborator
=
(
kbId
:
string
,
userId
:
string
,
access
:
"editor"
|
"reader"
)
=>
apiJson
(
`/kb/
${
kbId
}
/collaborator`
,
{
method
:
"POST"
,
body
:
JSON
.
stringify
({
userId
,
access
})
});
/** 移除协作者。 */
export
const
removeCollaborator
=
(
kbId
:
string
,
userId
:
string
)
=>
apiJson
(
`/kb/
${
kbId
}
/collaborator/
${
userId
}
`
,
{
method
:
"DELETE"
});
// ============ 采集/速记笔记 ============
export
interface
NoteItem
{
id
:
string
;
title
:
string
;
content
:
string
;
category
:
string
;
tags
:
string
[];
status
:
string
;
source
:
string
;
promotedKbId
:
string
|
null
;
promotedFileId
:
string
|
null
;
createdAt
:
string
|
null
;
updatedAt
:
string
|
null
;
}
export
interface
NoteInput
{
title
?:
string
;
content
?:
string
;
category
?:
string
;
tags
?:
string
[];
status
?:
string
;
source
?:
string
;
}
export
const
listNotes
=
(
q
:
{
category
?:
string
;
status
?:
string
;
keyword
?:
string
}
=
{})
=>
{
const
p
=
new
URLSearchParams
();
if
(
q
.
category
)
p
.
set
(
"category"
,
q
.
category
);
if
(
q
.
status
)
p
.
set
(
"status"
,
q
.
status
);
if
(
q
.
keyword
)
p
.
set
(
"keyword"
,
q
.
keyword
);
const
qs
=
p
.
toString
();
return
apiJson
<
{
total
:
number
;
items
:
NoteItem
[]
}
>
(
`/notes
${
qs
?
`?
${
qs
}
`
:
""
}
`
);
};
export
const
createNote
=
(
body
:
NoteInput
)
=>
apiJson
<
{
item
:
NoteItem
}
>
(
"/notes"
,
{
method
:
"POST"
,
body
:
JSON
.
stringify
(
body
)
});
export
const
updateNote
=
(
id
:
string
,
body
:
NoteInput
)
=>
apiJson
<
{
item
:
NoteItem
}
>
(
`/notes/
${
id
}
`
,
{
method
:
"PATCH"
,
body
:
JSON
.
stringify
(
body
)
});
export
const
deleteNote
=
(
id
:
string
)
=>
apiJson
(
`/notes/
${
id
}
`
,
{
method
:
"DELETE"
});
/** 把笔记沉淀(直写)到指定项目库,生成一个 wiki 页。 */
export
const
promoteNote
=
(
id
:
string
,
kbId
:
string
)
=>
apiJson
<
{
kbId
:
string
;
fileId
:
string
;
pagePath
:
string
}
>
(
`/notes/
${
id
}
/promote`
,
{
method
:
"POST"
,
body
:
JSON
.
stringify
({
kbId
}),
});
// ============ 技能管理 ============
export
interface
SkillItem
{
id
:
string
;
...
...
frontend/src/lib/oaEnums.ts
View file @
90acd05
...
...
@@ -44,10 +44,11 @@ export const DataScopeLabel: Record<number, string> = {
5
:
"仅本人"
,
};
export
const
KbType
=
{
BASE
:
"base"
,
DEPT
:
"dept"
}
as
const
;
export
const
KbType
=
{
BASE
:
"base"
,
DEPT
:
"dept"
,
PROJECT
:
"project"
}
as
const
;
export
const
KbTypeLabel
:
Record
<
string
,
string
>
=
{
base
:
"基础库"
,
dept
:
"部门库"
,
project
:
"项目库"
,
};
// 知识库权限三层模型:owner(绑定部门归属,由 kb.dept_id 承载,只作有效级别)
...
...
main.py
View file @
90acd05
...
...
@@ -32,6 +32,7 @@ from src.api.routes.sessions import router as sessions_router
from
src.api.routes.profile
import
router
as
profile_router
from
src.api.routes.oa
import
router
as
oa_router
from
src.api.routes.kb
import
router
as
kb_router
from
src.api.routes.notes
import
router
as
notes_router
from
src.api.routes.skills
import
router
as
skills_router
from
src.rag.api.routes
import
router
as
rag_router
...
...
@@ -158,6 +159,7 @@ app.include_router(sessions_router)
app
.
include_router
(
profile_router
)
app
.
include_router
(
oa_router
)
app
.
include_router
(
kb_router
)
app
.
include_router
(
notes_router
)
app
.
include_router
(
skills_router
)
app
.
include_router
(
rag_router
)
...
...
scripts/migrate_kb_paths.py
deleted
100644 → 0
View file @
e2b625d
"""知识库物理路径规整:把存量库搬到规范布局下。
规范布局(与 config.py / kb_paths.py 一致):
- 内置公共基础库 → ware/kb/base/main/{raw,wiki}
- 其余基础库 → ware/kb/base/<库id>/{raw,wiki}
- 部门库 → ware/kb/dept/<库id>/{raw,wiki}
存量里有三类偏差需要纠正:
1. 内置公共基础库还落在历史目录 ware/kb/base/comm(更早还有 ware/kb/comm);
2. 大量库的 root_dir 尾段用的是**绑定部门的 dept_id**,而不是库自身的 id;
3. 更早期的库没有 base/dept 这层,直接是 ware/kb/<uuid>。
搬迁三件事一起做,缺一不可:
- 磁盘目录 rename;
- DB 的 wiki_kb_info.root_dir、wiki_files.raw_path、wiki_file_pages.page_path 前缀改写;
- **页面正文里的路径改写**——index.md 的 `path:` 字段与 log.md 的摄入/摄出留痕里嵌了
项目根相对路径,不改就会指向不存在的位置。
已软删的库(del_flag=1)默认原地不动:它们既不可恢复也不参与检索,搬迁只有风险没有收益。
需要一并规整时加 --include-deleted。
用法:
python -m scripts.migrate_kb_paths # 只打印计划(dry-run,默认)
python -m scripts.migrate_kb_paths --apply # 实际执行
python -m scripts.migrate_kb_paths --apply --include-deleted
"""
from
__future__
import
annotations
import
argparse
import
asyncio
import
logging
import
os
import
shutil
import
sys
from
sqlalchemy
import
select
sys
.
path
.
insert
(
0
,
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
".."
)))
from
config
import
BASE_DIR
# noqa: E402
from
src.database.models
import
WikiFile
,
WikiFilePage
,
WikiKbInfo
# noqa: E402
from
src.database.session
import
AsyncSessionLocal
# noqa: E402
from
src.services.oa
import
enums
# noqa: E402
from
src.services.oa.kb_provision
import
BASE_KB_ROOT
,
LEGACY_BASE_KB_ROOTS
# noqa: E402
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
"
%(asctime)
s
%(levelname)
s
%(message)
s"
)
logger
=
logging
.
getLogger
(
"migrate_kb_paths"
)
# 只改写这些扩展名的正文(wiki 页面与留痕都是 markdown)
_TEXT_SUFFIXES
=
(
".md"
,)
def
expected_root
(
kb
:
WikiKbInfo
)
->
str
:
"""该库应有的 root_dir(项目根相对,POSIX 风格)。"""
if
(
kb
.
root_dir
or
""
)
in
LEGACY_BASE_KB_ROOTS
or
kb
.
root_dir
==
BASE_KB_ROOT
:
# 内置公共基础库:认历史 root_dir,不按 id 命名
return
BASE_KB_ROOT
bucket
=
"base"
if
kb
.
kb_type
==
enums
.
KB_BASE
else
"dept"
return
f
"ware/kb/{bucket}/{kb.id}"
def
_abs
(
rel
:
str
)
->
str
:
return
os
.
path
.
join
(
BASE_DIR
,
rel
.
replace
(
"/"
,
os
.
sep
))
def
_has_files
(
path
:
str
)
->
bool
:
"""目录树里是否存在任何文件(只有空子目录不算有内容)。"""
for
_dirpath
,
_dirnames
,
filenames
in
os
.
walk
(
path
):
if
filenames
:
return
True
return
False
def
move_dir
(
old_rel
:
str
,
new_rel
:
str
)
->
str
:
"""把 old_rel 目录搬到 new_rel。返回一句话结果说明。
目标已存在但**不含任何文件**(config 启动时 makedirs 出来的 raw/wiki 空壳)时先删掉再搬;
目标已有文件则拒绝,避免把两个库的内容混在一起。
"""
old_abs
,
new_abs
=
_abs
(
old_rel
),
_abs
(
new_rel
)
if
not
os
.
path
.
isdir
(
old_abs
):
os
.
makedirs
(
new_abs
,
exist_ok
=
True
)
return
"旧目录不存在,仅建新目录"
if
os
.
path
.
isdir
(
new_abs
):
if
_has_files
(
new_abs
):
raise
RuntimeError
(
f
"目标目录已存在且含文件,拒绝合并: {new_rel}"
)
shutil
.
rmtree
(
new_abs
)
os
.
makedirs
(
os
.
path
.
dirname
(
new_abs
),
exist_ok
=
True
)
shutil
.
move
(
old_abs
,
new_abs
)
return
"已搬迁"
def
rewrite_texts
(
root_rel
:
str
,
old_rel
:
str
,
new_rel
:
str
)
->
int
:
"""改写 root_rel 目录下所有 markdown 里出现的 old_rel → new_rel。返回改动文件数。
路径在正文里以项目根相对形式出现(如 index.md 的 `path: ware/kb/dept/<id>/wiki/x.md`),
直接做字符串替换即可;old_rel 含 uuid,不会误伤其它内容。
"""
changed
=
0
for
dirpath
,
_dirnames
,
filenames
in
os
.
walk
(
_abs
(
root_rel
)):
for
name
in
filenames
:
if
not
name
.
endswith
(
_TEXT_SUFFIXES
):
continue
path
=
os
.
path
.
join
(
dirpath
,
name
)
try
:
with
open
(
path
,
encoding
=
"utf-8"
)
as
f
:
text
=
f
.
read
()
except
(
UnicodeDecodeError
,
OSError
)
as
exc
:
logger
.
warning
(
" 正文读取失败,跳过:
%
s (
%
s)"
,
path
,
exc
)
continue
if
old_rel
not
in
text
:
continue
with
open
(
path
,
"w"
,
encoding
=
"utf-8"
)
as
f
:
f
.
write
(
text
.
replace
(
old_rel
,
new_rel
))
changed
+=
1
return
changed
async
def
_rewrite_db_paths
(
session
,
old_rel
:
str
,
new_rel
:
str
)
->
tuple
[
int
,
int
]:
"""改写 DB 里以 old_rel 打头的 raw_path / page_path。返回 (文件数, 页面数)。"""
files
=
(
await
session
.
execute
(
select
(
WikiFile
)
.
where
(
WikiFile
.
raw_path
.
like
(
f
"{old_rel}/
%
"
))
)
)
.
scalars
()
.
all
()
for
f
in
files
:
f
.
raw_path
=
new_rel
+
f
.
raw_path
[
len
(
old_rel
):]
pages
=
(
await
session
.
execute
(
select
(
WikiFilePage
)
.
where
(
WikiFilePage
.
page_path
.
like
(
f
"{old_rel}/
%
"
))
)
)
.
scalars
()
.
all
()
for
p
in
pages
:
p
.
page_path
=
new_rel
+
p
.
page_path
[
len
(
old_rel
):]
return
len
(
files
),
len
(
pages
)
async
def
migrate
(
apply
:
bool
,
include_deleted
:
bool
)
->
dict
:
planned
=
migrated
=
skipped
=
failed
=
0
# 先把要处理的库读成纯数据:每个库各用独立事务搬迁,一个失败不牵连其它,
# 也避免 rollback 让共享 session 里的 ORM 对象过期(属性访问会触发同步 IO 而报 MissingGreenlet)。
async
with
AsyncSessionLocal
()
as
session
:
stmt
=
select
(
WikiKbInfo
)
if
not
include_deleted
:
stmt
=
stmt
.
where
(
WikiKbInfo
.
del_flag
==
enums
.
DEL_NORMAL
)
rows
=
(
await
session
.
execute
(
stmt
.
order_by
(
WikiKbInfo
.
kb_type
)))
.
scalars
()
.
all
()
kbs
=
[
{
"id"
:
kb
.
id
,
"kb_type"
:
kb
.
kb_type
,
"kb_name"
:
kb
.
kb_name
,
"old"
:
(
kb
.
root_dir
or
""
)
.
replace
(
"
\\
"
,
"/"
),
"new"
:
expected_root
(
kb
),
}
for
kb
in
rows
]
logger
.
info
(
"待检查知识库
%
d 个(include_deleted=
%
s)"
,
len
(
kbs
),
include_deleted
)
# 目标路径撞车就立刻停手,别搬到一半
targets
:
dict
[
str
,
str
]
=
{}
for
kb
in
kbs
:
if
kb
[
"new"
]
in
targets
:
raise
RuntimeError
(
f
"目标路径冲突: {kb['new']} 同时被 {targets[kb['new']]} 与 {kb['id']} 占用"
)
targets
[
kb
[
"new"
]]
=
kb
[
"id"
]
for
kb
in
kbs
:
old_rel
,
new_rel
=
kb
[
"old"
],
kb
[
"new"
]
if
old_rel
==
new_rel
:
skipped
+=
1
continue
planned
+=
1
exists
=
os
.
path
.
isdir
(
_abs
(
old_rel
))
logger
.
info
(
"[
%
s]
%
s
\n
%
s →
%
s
%
s"
,
kb
[
"kb_type"
],
kb
[
"kb_name"
],
old_rel
or
"(空)"
,
new_rel
,
""
if
exists
else
" (磁盘无旧目录)"
,
)
if
not
apply
:
continue
# 顺序:先搬磁盘再改 DB。磁盘失败则 DB 不动,两边仍一致;
# 磁盘成功而 DB 失败时重跑即可自愈——DB 里仍是旧路径,而旧目录已不在,
# 走「旧目录不存在」分支不会破坏已搬好的内容,随后补上 DB 更新。
try
:
note
=
move_dir
(
old_rel
,
new_rel
)
touched
=
rewrite_texts
(
new_rel
,
old_rel
,
new_rel
)
if
old_rel
else
0
async
with
AsyncSessionLocal
()
as
session
:
n_files
,
n_pages
=
await
_rewrite_db_paths
(
session
,
old_rel
,
new_rel
)
record
=
await
session
.
get
(
WikiKbInfo
,
kb
[
"id"
])
if
record
is
not
None
:
record
.
root_dir
=
new_rel
await
session
.
commit
()
migrated
+=
1
logger
.
info
(
"
%
s;正文改写
%
d 个文件,DB raw_path
%
d 条 / page_path
%
d 条"
,
note
,
touched
,
n_files
,
n_pages
,
)
except
Exception
as
exc
:
# noqa: BLE001
failed
+=
1
logger
.
error
(
" 失败,该库保持原状:
%
s"
,
exc
)
result
=
{
"planned"
:
planned
,
"migrated"
:
migrated
,
"unchanged"
:
skipped
,
"failed"
:
failed
}
logger
.
info
(
"完成:
%
s"
,
result
)
if
not
apply
and
planned
:
logger
.
info
(
"以上仅为计划(dry-run)。确认无误后加 --apply 执行。"
)
return
result
def
main
()
->
None
:
parser
=
argparse
.
ArgumentParser
(
description
=
"知识库物理路径规整"
)
parser
.
add_argument
(
"--apply"
,
action
=
"store_true"
,
help
=
"实际执行(默认只打印计划)"
)
parser
.
add_argument
(
"--include-deleted"
,
action
=
"store_true"
,
help
=
"连已软删的库一起规整"
)
args
=
parser
.
parse_args
()
asyncio
.
run
(
migrate
(
apply
=
args
.
apply
,
include_deleted
=
args
.
include_deleted
))
if
__name__
==
"__main__"
:
main
()
src/api/routes/kb.py
View file @
90acd05
This diff is collapsed.
Click to expand it.
src/database/models.py
View file @
90acd05
...
...
@@ -352,7 +352,7 @@ class WikiOaPost(AuditByMixin, Base):
class
WikiOaUser
(
AuditByMixin
,
Base
):
"""用户/员工:账号=手机号,权限只经角色,岗位经 user_post 关联。
取代旧 wiki_users。
"""
"""用户/员工:账号=手机号,权限只经角色,岗位经 user_post 关联。"""
__tablename__
=
"wiki_oa_user"
__table_args__
=
(
...
...
@@ -535,7 +535,7 @@ class WikiOaOperLog(AuditByMixin, Base):
class
WikiKbInfo
(
AuditByMixin
,
Base
):
"""知识库注册:公共基础库 / 部门库 /
个人
库;root_dir 为物理目录(便于迁移)。"""
"""知识库注册:公共基础库 / 部门库 /
项目
库;root_dir 为物理目录(便于迁移)。"""
__tablename__
=
"wiki_kb_info"
__table_args__
=
(
...
...
@@ -546,9 +546,9 @@ class WikiKbInfo(AuditByMixin, Base):
)
id
=
Column
(
String
(
36
),
primary_key
=
True
,
default
=
uuid_str
,
comment
=
"知识库主键 UUID"
)
kb_type
=
Column
(
String
(
20
),
nullable
=
False
,
comment
=
"base=公共基础库 / dept=部门库 / p
ersonal=个人
库"
)
kb_type
=
Column
(
String
(
20
),
nullable
=
False
,
comment
=
"base=公共基础库 / dept=部门库 / p
roject=项目
库"
)
kb_name
=
Column
(
String
(
100
),
nullable
=
False
,
comment
=
"知识库名称"
)
owner_user_id
=
Column
(
String
(
36
),
nullable
=
True
,
comment
=
"
个人库归属用户 wiki_oa_user.id
"
)
owner_user_id
=
Column
(
String
(
36
),
nullable
=
True
,
comment
=
"
项目库创建者 wiki_oa_user.id(owner)
"
)
dept_id
=
Column
(
String
(
36
),
nullable
=
True
,
comment
=
"部门库归属部门 wiki_oa_dept.id"
)
root_dir
=
Column
(
String
(
300
),
nullable
=
False
,
comment
=
"物理目录(命名空间根,便于隔离迁移)"
)
status
=
Column
(
String
(
20
),
nullable
=
False
,
default
=
"active"
,
comment
=
"active/disabled"
)
...
...
@@ -749,3 +749,33 @@ class WikiSessionMessage(AuditByMixin, Base):
duration_ms
=
Column
(
Integer
,
nullable
=
False
,
default
=
0
,
comment
=
"该轮回答总耗时毫秒,供前端重放显示秒数"
)
created_at
=
Column
(
DateTime
,
default
=
datetime
.
now
,
comment
=
"创建时间"
)
class
WikiNote
(
AuditByMixin
,
Base
):
"""采集/速记笔记:低门槛捕获用户脑海中的项目知识,带分类,可沉淀到项目库。
- 私有:仅 user_id 本人可见/可编辑(后端强制隔离,不靠前端)。
- 沉淀:promote 到自己有写权限的**项目库**(kb_type=project),生成一个 wiki 页;
promoted_kb_id/promoted_file_id 记录去向,避免重复沉淀。
"""
__tablename__
=
"wiki_notes"
__table_args__
=
(
Index
(
"idx_wiki_notes_user_updated"
,
"user_id"
,
"updated_at"
),
Index
(
"idx_wiki_notes_user_category"
,
"user_id"
,
"category"
),
{
"comment"
:
"采集/速记笔记(私有,可沉淀到项目库)"
},
)
id
=
Column
(
String
(
36
),
primary_key
=
True
,
default
=
uuid_str
,
comment
=
"笔记主键 UUID"
)
user_id
=
Column
(
String
(
36
),
nullable
=
False
,
comment
=
"归属用户 wiki_oa_user.id,隔离键"
)
title
=
Column
(
String
(
200
),
nullable
=
True
,
comment
=
"标题(可选)"
)
content
=
Column
(
LongText
,
nullable
=
True
,
comment
=
"正文(Markdown)"
)
category
=
Column
(
String
(
32
),
nullable
=
False
,
default
=
"other"
,
comment
=
"类型:project/lesson/sop/term/idea/pitfall/reference/meeting/other"
)
tags
=
Column
(
Text
,
nullable
=
True
,
comment
=
"标签 JSON 数组串,如 [
\"
甲方
\"
,
\"
报价
\"
]"
)
status
=
Column
(
String
(
20
),
nullable
=
False
,
default
=
"draft"
,
comment
=
"状态:draft=草稿 / pending=待整理 / archived=已归档"
)
source
=
Column
(
String
(
255
),
nullable
=
True
,
comment
=
"来源(可选,如会议名/链接)"
)
promoted_kb_id
=
Column
(
String
(
36
),
nullable
=
True
,
comment
=
"已沉淀到的项目库 wiki_kb_info.id(空=未沉淀)"
)
promoted_file_id
=
Column
(
String
(
36
),
nullable
=
True
,
comment
=
"沉淀生成的 wiki_files.id(空=未沉淀)"
)
del_flag
=
Column
(
Integer
,
nullable
=
False
,
default
=
0
,
comment
=
"逻辑删除 0正常/1已删"
)
created_at
=
Column
(
DateTime
,
default
=
datetime
.
now
,
comment
=
"创建时间"
)
updated_at
=
Column
(
DateTime
,
default
=
datetime
.
now
,
onupdate
=
datetime
.
now
,
comment
=
"更新时间"
)
src/database/schema_sync.py
View file @
90acd05
...
...
@@ -19,10 +19,6 @@ _AUDIT_COLUMNS: list[tuple[str, str]] = [
(
"updated_by"
,
"ADD COLUMN updated_by VARCHAR(64) NOT NULL DEFAULT 'system' COMMENT '修改人,无则 system'"
),
]
# 非 ORM 的历史 wiki_ 表(未在 models.py 定义,但也统一补审计列)。
# 严格只列 wiki_ 前缀的本项目遗留表,绝不触碰同库其它应用的表(ai_*/wecom_* 等)。
_EXTRA_AUDIT_TABLES
:
list
[
str
]
=
[
"wiki_positions"
,
"wiki_users"
]
logger
=
logging
.
getLogger
(
__name__
)
_synced
=
False
...
...
@@ -341,8 +337,8 @@ async def ensure_wiki_schema() -> None:
for
table
,
specs
in
_COLUMN_SPECS
.
items
():
await
_ensure_columns
(
conn
,
table
,
specs
)
# 审计人字段:给所有 ORM 表
+ 历史 wiki_ 表
统一补 created_by/updated_by(默认 system)
for
table_name
in
list
(
Base
.
metadata
.
tables
.
keys
())
+
_EXTRA_AUDIT_TABLES
:
# 审计人字段:给所有 ORM 表统一补 created_by/updated_by(默认 system)
for
table_name
in
Base
.
metadata
.
tables
.
keys
()
:
try
:
await
_ensure_columns
(
conn
,
table_name
,
_AUDIT_COLUMNS
)
except
Exception
as
exc
:
# 单表失败(如表不存在)不阻断整体
...
...
src/services/oa/enums.py
View file @
90acd05
...
...
@@ -41,11 +41,11 @@ SCOPE_DEPT_AND_SUB = 4 # 本部门及以下
SCOPE_SELF
=
5
# 仅本人
DATA_SCOPES
=
(
SCOPE_ALL
,
SCOPE_CUSTOM
,
SCOPE_DEPT
,
SCOPE_DEPT_AND_SUB
,
SCOPE_SELF
)
# ---- 知识库类型(
仅两类,且
创建后不可修改)----
KB_BASE
=
"base"
# 基础库(内置公共基础库 + 其它面向全员的基础库,落 ware/kb/base/)
KB_DEPT
=
"dept"
# 部门库(按部门授权,落 ware/kb/dept/)
KB_P
ERSONAL
=
"personal"
# 个人库(休眠概念,无创建入口;perms 仍保留其只读判定分支
)
KB_TYPES
=
(
KB_BASE
,
KB_DEPT
)
# ---- 知识库类型(创建后不可修改)----
KB_BASE
=
"base"
# 基础库(内置公共基础库 + 其它面向全员的基础库,落 ware/kb/base/)
KB_DEPT
=
"dept"
# 部门库(按部门授权,落 ware/kb/dept/)
KB_P
ROJECT
=
"project"
# 项目库(个人/团队按人协作,类 git:owner=创建者,协作者按人授 editor/reader,落 ware/kb/project/
)
KB_TYPES
=
(
KB_BASE
,
KB_DEPT
,
KB_PROJECT
)
# ---- 知识库权限三层模型(Owner / Editor / Reader)----
# owner=所有者:部门库的唯一归属部门(wiki_kb_info.dept_id,叶子、1:1),隐式读写;
...
...
src/services/oa/kb_paths.py
View file @
90acd05
...
...
@@ -17,7 +17,7 @@ from __future__ import annotations
import
os
from
config
import
BASE_DIR
,
RAW_DIR
,
WIKI_DIR
,
KB_BASE_ROOT
,
KB_DEPT_ROOT
from
config
import
BASE_DIR
,
RAW_DIR
,
WIKI_DIR
,
KB_BASE_ROOT
,
KB_DEPT_ROOT
,
KB_PROJECT_ROOT
from
src.database.models
import
WikiKbInfo
from
src.services.oa
import
enums
...
...
@@ -59,11 +59,16 @@ def kb_root_rel(kb_id: str, kb_type: str = enums.KB_DEPT) -> str:
- 基础库 → ware/kb/base/<kb_id>/{raw,wiki}
- 部门库 → ware/kb/dept/<kb_id>/{raw,wiki}
以**库自身 id**(不是 dept_id)划分物理命名空间(纯 ASCII、彼此隔离)。
- 项目库 → ware/kb/project/<kb_id>/{raw,wiki}
以**库自身 id**(不是 dept_id/owner_user_id)划分物理命名空间(纯 ASCII、彼此隔离)。
内置公共基础库例外,用固定 ware/kb/base/main。
"""
base
=
KB_BASE_ROOT
if
kb_type
==
enums
.
KB_BASE
else
KB_DEPT_ROOT
return
_rel
(
os
.
path
.
join
(
base
,
kb_id
))
root
=
{
enums
.
KB_BASE
:
KB_BASE_ROOT
,
enums
.
KB_DEPT
:
KB_DEPT_ROOT
,
enums
.
KB_PROJECT
:
KB_PROJECT_ROOT
,
}
.
get
(
kb_type
,
KB_DEPT_ROOT
)
return
_rel
(
os
.
path
.
join
(
root
,
kb_id
))
def
rebase_wiki_rel
(
rel_path
:
str
,
kb
:
WikiKbInfo
)
->
str
:
...
...
src/services/oa/kb_provision.py
View file @
90acd05
...
...
@@ -20,10 +20,6 @@ logger = logging.getLogger(__name__)
BASE_KB_NAME
=
"公共基础库"
BASE_KB_ROOT
=
"ware/kb/base/main"
# 相对项目根;内置公共基础库固定落 ware/kb/base/main/{raw,wiki}
# 内置公共基础库的历史 root_dir。老库升级到 BASE_KB_ROOT 时用于认领,
# 否则 ensure_base_kb 找不到它会**再建一个**公共基础库出来。见 scripts/migrate_kb_paths.py。
LEGACY_BASE_KB_ROOTS
=
(
"ware/kb/base/comm"
,
"ware/kb/comm"
)
def
is_builtin_kb
(
kb
:
WikiKbInfo
|
None
)
->
bool
:
"""是否为系统内置基础库(落 ware/kb/base/main 的那一个)。
...
...
@@ -51,36 +47,10 @@ async def get_base_kb(session) -> WikiKbInfo | None:
)
.
scalars
()
.
first
()
async
def
_claim_legacy_base_kb
(
session
)
->
WikiKbInfo
|
None
:
"""把历史 root_dir 的内置公共库认领为新布局(只改 DB 指向,不搬磁盘)。
磁盘目录由 `scripts/migrate_kb_paths.py` 搬迁;这里只保证**先启动服务、后跑迁移**
的情况下不会凭空多出第二个「公共基础库」。已跑过迁移则本函数查不到旧库,直接跳过。
"""
legacy
=
(
await
session
.
execute
(
select
(
WikiKbInfo
)
.
where
(
WikiKbInfo
.
kb_type
==
enums
.
KB_BASE
,
WikiKbInfo
.
root_dir
.
in_
(
LEGACY_BASE_KB_ROOTS
),
WikiKbInfo
.
del_flag
==
enums
.
DEL_NORMAL
,
)
)
)
.
scalars
()
.
first
()
if
legacy
is
None
:
return
None
logger
.
warning
(
"[KB] 内置公共基础库仍是旧布局
%
s,已认领为
%
s;磁盘目录请跑 scripts/migrate_kb_paths.py 搬迁"
,
legacy
.
root_dir
,
BASE_KB_ROOT
,
)
legacy
.
root_dir
=
BASE_KB_ROOT
await
session
.
commit
()
return
legacy
async
def
ensure_base_kb
()
->
str
:
"""幂等确保 base 库存在,返回其 id。启动时调用。"""
async
with
AsyncSessionLocal
()
as
session
:
base
=
await
get_base_kb
(
session
)
or
await
_claim_legacy_base_kb
(
session
)
base
=
await
get_base_kb
(
session
)
if
base
is
None
:
base
=
WikiKbInfo
(
kb_type
=
enums
.
KB_BASE
,
...
...
src/services/oa/perms.py
View file @
90acd05
...
...
@@ -329,8 +329,9 @@ async def resolve_kb_access(user: WikiOaUser | None, kb: WikiKbInfo) -> str | No
return
None
if
user
.
is_superadmin
:
return
enums
.
KB_ACCESS_OWNER
if
kb
.
kb_type
==
enums
.
KB_PERSONAL
:
return
enums
.
KB_ACCESS_OWNER
if
kb
.
owner_user_id
==
user
.
id
else
None
# 项目库:创建者=owner;否则**不短路**,继续按 wiki_kb_grant(grantee_type=user)裁协作者 editor/reader
if
kb
.
kb_type
==
enums
.
KB_PROJECT
and
kb
.
owner_user_id
==
user
.
id
:
return
enums
.
KB_ACCESS_OWNER
scope
=
await
resolve_data_scope
(
user
)
managed_dept_ids
=
set
(
scope
.
dept_ids
)
...
...
@@ -370,37 +371,37 @@ async def resolve_readable_kbs_with_access(user: WikiOaUser) -> list[tuple[WikiK
可读来源(三层模型):
- 部门库**绑定部门 dept_id** 命中(向上继承:dept_id ∈ 用户祖先链;向下管辖:dept_id ∈ 管辖
子树)→ 级别 owner(读写);
- 经 wiki_kb_grant(editor/reader,授节点=授其整棵子树
)显式授予的 base/dept
库,级别取最高;
-
个人库:owner 可见(休眠概念,当前无创建入口)
。
- 经 wiki_kb_grant(editor/reader,授节点=授其整棵子树
/ 或 grantee_type=user 点对点)显式授予的
库,级别取最高;
-
项目库:自己创建的 owner 可见;被授协作的按 grant 级别可见
。
- 超级管理员(scope.is_all):直接可见全部 base + dept 库,级别 owner。
- 超级管理员(scope.is_all):直接可见全部 base + dept
+ project
库,级别 owner。
"""
scope
=
await
resolve_data_scope
(
user
)
async
with
AsyncSessionLocal
()
as
session
:
result
:
dict
[
str
,
tuple
[
WikiKbInfo
,
str
]]
=
{}
#
个人库(owner 级别)
personal
=
(
#
项目库:自己创建的(owner 级别);被授协作的项目库由下方 user_kb_access_map 一并纳入
own_projects
=
(
await
session
.
execute
(
select
(
WikiKbInfo
)
.
where
(
WikiKbInfo
.
del_flag
==
enums
.
DEL_NORMAL
,
WikiKbInfo
.
status
==
enums
.
STATUS_ACTIVE
,
WikiKbInfo
.
kb_type
==
enums
.
KB_P
ERSONAL
,
WikiKbInfo
.
kb_type
==
enums
.
KB_P
ROJECT
,
WikiKbInfo
.
owner_user_id
==
user
.
id
,
)
)
)
.
scalars
()
.
all
()
for
kb
in
personal
:
for
kb
in
own_projects
:
result
[
kb
.
id
]
=
(
kb
,
enums
.
KB_ACCESS_OWNER
)
# 超级管理员:无条件纳入全部 base + dept 库,级别 owner
# 超级管理员:无条件纳入全部 base + dept
+ project
库,级别 owner
if
scope
.
is_all
:
all_kbs
=
(
await
session
.
execute
(
select
(
WikiKbInfo
)
.
where
(
WikiKbInfo
.
del_flag
==
enums
.
DEL_NORMAL
,
WikiKbInfo
.
status
==
enums
.
STATUS_ACTIVE
,
WikiKbInfo
.
kb_type
.
in_
([
enums
.
KB_BASE
,
enums
.
KB_DEPT
]),
WikiKbInfo
.
kb_type
.
in_
([
enums
.
KB_BASE
,
enums
.
KB_DEPT
,
enums
.
KB_PROJECT
]),
)
)
)
.
scalars
()
.
all
()
...
...
src/services/oa/seed.py
View file @
90acd05
...
...
@@ -94,7 +94,7 @@ _SOURCES: list[tuple] = [
(
"kbperm"
,
None
,
"知识库数据权限"
,
enums
.
SOURCE_DIR
,
None
,
None
,
"shield"
,
300
),
(
"kb_base_write"
,
"kbperm"
,
"基础库写入"
,
enums
.
SOURCE_API
,
"kb:base:write"
,
None
,
None
,
11
),
(
"kb_dept_read"
,
"kbperm"
,
"部门库读取"
,
enums
.
SOURCE_API
,
"kb:dept:read"
,
None
,
None
,
12
),
(
"kb_p
ersonal_manage"
,
"kbperm"
,
"个人库管理"
,
enums
.
SOURCE_API
,
"kb:personal
:manage"
,
None
,
None
,
13
),
(
"kb_p
roject_manage"
,
"kbperm"
,
"项目库管理"
,
enums
.
SOURCE_API
,
"kb:project
:manage"
,
None
,
None
,
13
),
]
# 内置角色:(role_code, role_name, data_scope, order, perms | "ALL", remark)
...
...
@@ -109,7 +109,7 @@ _ROLES: list[tuple] = [
"wiki:query:use"
,
"wiki:repo:view"
,
"wiki:repo:read"
,
"wiki:repo:download"
,
"rag:use"
,
"wiki:profile:view"
,
"kb:list"
,
"kb:create"
,
"kb:grant"
,
"kb:revoke"
,
"kb:remove"
,
"kb:dept:read"
,
"kb:p
ersonal
:manage"
,
"wiki:session:own"
,
"oa:profile:changePwd"
,
"kb:p
roject
:manage"
,
"wiki:session:own"
,
"oa:profile:changePwd"
,
],
"面向中心级负责人:数据范围=本部门及以下,系统按其所在部门自动向上定位所属中心,"
"覆盖该中心整棵子树的部门库(与其挂在中心节点还是某子部门无关);对 Owner 库具备全套读写操作。"
),
(
enums
.
ROLE_DEPT_LEAD
,
"部门负责人"
,
enums
.
SCOPE_DEPT
,
3
,
[
...
...
@@ -120,14 +120,14 @@ _ROLES: list[tuple] = [
"wiki:query:use"
,
"wiki:repo:view"
,
"wiki:repo:read"
,
"wiki:repo:download"
,
"rag:use"
,
"wiki:profile:view"
,
"kb:list"
,
"kb:create"
,
"kb:grant"
,
"kb:revoke"
,
"kb:dept:read"
,
"kb:p
ersonal
:manage"
,
"wiki:session:own"
,
"oa:profile:changePwd"
,
"kb:p
roject
:manage"
,
"wiki:session:own"
,
"oa:profile:changePwd"
,
],
"面向部门负责人:数据范围限本部门,对 Owner 库具备全套读写操作与本部门成员查看权限。"
),
(
enums
.
ROLE_STAFF
,
"普通员工"
,
enums
.
SCOPE_SELF
,
4
,
[
"wiki:file:list"
,
"wiki:file:upload"
,
"wiki:file:ingest"
,
"wiki:file:batchIngest"
,
"wiki:file:cancelIngest"
,
"wiki:file:download"
,
"wiki:file:batchDownload"
,
"wiki:query:use"
,
"wiki:repo:view"
,
"wiki:repo:read"
,
"wiki:repo:download"
,
"rag:use"
,
"wiki:profile:view"
,
"kb:p
ersonal
:manage"
,
"kb:dept:read"
,
"wiki:session:own"
,
"oa:profile:changePwd"
,
"kb:p
roject
:manage"
,
"kb:dept:read"
,
"wiki:session:own"
,
"oa:profile:changePwd"
,
],
"面向普通员工:能上传/摄入 Owner 库、查看下载文件、使用问答、管理个人库与画像;"
"摄出/删除等按钮不授予(由负责人操作)。对 Guest 库仅可读,写操作接口会拒绝。"
),
(
enums
.
ROLE_GUEST
,
"只读访客"
,
enums
.
SCOPE_SELF
,
5
,
[
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment