@allbluecn/admin-app 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/components/admin/developer-log.tsx +2 -2
- package/src/components/knowledge/public/kp-crud-page.tsx +208 -0
- package/src/components/market/market-app-form.tsx +1 -1
- package/src/components/user/settings-profile.tsx +1 -1
- package/src/components/user/user-create-dialog.tsx +1 -1
- package/src/components/user/user-detail/user-detail-dialogs.tsx +3 -3
- package/src/paraglide/messages/_index.js +0 -2
- package/src/routes/_nav/knowledge-public/bookmarks/route.lazy.tsx +36 -111
- package/src/routes/_nav/knowledge-public/compliance/route.lazy.tsx +29 -105
- package/src/routes/_nav/knowledge-public/legal/route.lazy.tsx +30 -108
- package/src/routes/_nav/monitoring/errors/route.lazy.tsx +1 -1
- package/src/routes/_nav/monitoring/logs/route.lazy.tsx +1 -1
- package/src/routes/_nav/monitoring/metrics/route.lazy.tsx +1 -1
- package/src/routes/_nav/permissions/route.lazy.tsx +1 -1
- package/src/routes/_nav/sso/route.lazy.tsx +1 -1
- package/src/server/knowledge/public/kp-factory.ts +134 -0
- package/src/server/serverFns/knowledge/public/bookmarks/create.ts +23 -25
- package/src/server/serverFns/knowledge/public/bookmarks/delete.ts +2 -14
- package/src/server/serverFns/knowledge/public/bookmarks/detail.ts +2 -11
- package/src/server/serverFns/knowledge/public/bookmarks/list.ts +32 -38
- package/src/server/serverFns/knowledge/public/bookmarks/update.ts +23 -22
- package/src/server/serverFns/knowledge/public/compliance/create.ts +10 -15
- package/src/server/serverFns/knowledge/public/compliance/delete.ts +2 -14
- package/src/server/serverFns/knowledge/public/compliance/detail.ts +2 -11
- package/src/server/serverFns/knowledge/public/compliance/list.ts +24 -31
- package/src/server/serverFns/knowledge/public/compliance/update.ts +22 -22
- package/src/server/serverFns/knowledge/public/legal/create.ts +11 -15
- package/src/server/serverFns/knowledge/public/legal/delete.ts +2 -14
- package/src/server/serverFns/knowledge/public/legal/detail.ts +2 -11
- package/src/server/serverFns/knowledge/public/legal/list.ts +24 -32
- package/src/server/serverFns/knowledge/public/legal/update.ts +20 -22
- package/src/paraglide/messages/common_button_cancel.js +0 -29
- package/src/paraglide/messages/common_dependency_table_pagination_total.js +0 -29
|
@@ -15,16 +15,12 @@
|
|
|
15
15
|
// You should have received a copy of the GNU Affero General Public License
|
|
16
16
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
17
|
|
|
18
|
-
import { createLazyFileRoute
|
|
18
|
+
import { createLazyFileRoute } from '@tanstack/react-router'
|
|
19
19
|
import { m } from '@/paraglide/messages.js'
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { DataTable, type AdminColumnDef } from '@/components/data-table/data-table'
|
|
20
|
+
import { PencilIcon, Trash2Icon } from 'lucide-react'
|
|
21
|
+
import { type AdminColumnDef } from '@/components/data-table/data-table'
|
|
23
22
|
import { Button } from '@/components/ui/button'
|
|
24
|
-
import { Input } from '@/components/ui/input'
|
|
25
23
|
import { Badge } from '@/components/ui/badge'
|
|
26
|
-
import { ConfirmDialog } from '@/components/confirm-dialog'
|
|
27
|
-
import { toast } from '@/components/ui/toast'
|
|
28
24
|
import { RoutePending } from '@/components/admin/route-pending'
|
|
29
25
|
import { formatDate } from '@/lib/format-date'
|
|
30
26
|
import {
|
|
@@ -32,6 +28,7 @@ import {
|
|
|
32
28
|
type ComplianceRow,
|
|
33
29
|
} from '@/components/knowledge/public/compliance-form-dialog'
|
|
34
30
|
import { adminDeleteComplianceFn } from '@/server/serverFns/knowledge/public/compliance/delete'
|
|
31
|
+
import { KpCrudShell, useKpCrud } from '@/components/knowledge/public/kp-crud-page'
|
|
35
32
|
|
|
36
33
|
export const Route = createLazyFileRoute('/_nav/knowledge-public/compliance')({
|
|
37
34
|
pendingComponent: RoutePending,
|
|
@@ -44,53 +41,15 @@ function CompliancePage() {
|
|
|
44
41
|
const { items: rawItems, total } = Route.useLoaderData()
|
|
45
42
|
const items = rawItems as ComplianceRow[]
|
|
46
43
|
const { search } = Route.useSearch()
|
|
47
|
-
const navigate = useNavigate()
|
|
48
|
-
const router = useRouter()
|
|
49
44
|
const locale = Route.useRouteContext().locale
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
setSearchInput(search ?? '')
|
|
59
|
-
}, [search])
|
|
60
|
-
|
|
61
|
-
function refresh() {
|
|
62
|
-
router.invalidate()
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function applySearch() {
|
|
66
|
-
navigate({
|
|
67
|
-
to: '/knowledge-public/compliance',
|
|
68
|
-
search: (s) => ({ ...s, search: searchInput.trim() || undefined }),
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function openCreate() {
|
|
73
|
-
setEditing(null)
|
|
74
|
-
setFormOpen(true)
|
|
75
|
-
}
|
|
76
|
-
function openEdit(row: ComplianceRow) {
|
|
77
|
-
setEditing(row)
|
|
78
|
-
setFormOpen(true)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function confirmDelete() {
|
|
82
|
-
if (!deleting) return
|
|
83
|
-
startDelete(async () => {
|
|
84
|
-
try {
|
|
85
|
-
await adminDeleteComplianceFn({ data: { id: deleting.id } })
|
|
86
|
-
toast.success(m.common_knowledgePublic_compliance_deleted())
|
|
87
|
-
setDeleting(null)
|
|
88
|
-
refresh()
|
|
89
|
-
} catch (err) {
|
|
90
|
-
toast.error(err instanceof Error ? err.message : m.common_common_deleteFailed())
|
|
91
|
-
}
|
|
92
|
-
})
|
|
93
|
-
}
|
|
45
|
+
// S34:状态机与页面 chrome 收敛到共享骨架,页面只保留列定义与域内对话框
|
|
46
|
+
const crud = useKpCrud<ComplianceRow>({
|
|
47
|
+
routePath: '/knowledge-public/compliance',
|
|
48
|
+
search,
|
|
49
|
+
deleteFn: (row) => adminDeleteComplianceFn({ data: { id: row.id } }),
|
|
50
|
+
deleteSuccessToast: m.common_knowledgePublic_compliance_deleted(),
|
|
51
|
+
})
|
|
52
|
+
const { openEdit, setDeleting } = crud
|
|
94
53
|
|
|
95
54
|
const columns: AdminColumnDef<ComplianceRow>[] = [
|
|
96
55
|
{
|
|
@@ -174,57 +133,22 @@ function CompliancePage() {
|
|
|
174
133
|
]
|
|
175
134
|
|
|
176
135
|
return (
|
|
177
|
-
<
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setSearchInput(e.target.value)}
|
|
195
|
-
onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
196
|
-
if (e.key === 'Enter') applySearch()
|
|
197
|
-
}}
|
|
198
|
-
placeholder={m.common_knowledgePublic_compliance_placeholder()}
|
|
199
|
-
className="pl-8"
|
|
200
|
-
/>
|
|
201
|
-
</div>
|
|
202
|
-
<Button variant="outline" onClick={applySearch}>
|
|
203
|
-
{m.common_common_search()}
|
|
204
|
-
</Button>
|
|
205
|
-
</div>
|
|
206
|
-
|
|
207
|
-
<DataTable columns={columns} data={items} />
|
|
208
|
-
|
|
209
|
-
<ComplianceFormDialog
|
|
210
|
-
open={formOpen}
|
|
211
|
-
onOpenChange={setFormOpen}
|
|
212
|
-
item={editing}
|
|
213
|
-
onSuccess={refresh}
|
|
214
|
-
/>
|
|
215
|
-
|
|
216
|
-
<ConfirmDialog
|
|
217
|
-
open={!!deleting}
|
|
218
|
-
onOpenChange={(o: boolean) => !o && setDeleting(null)}
|
|
219
|
-
title={m.common_knowledgePublic_compliance_deleteConfirmTitle()}
|
|
220
|
-
description={m.common_knowledgePublic_compliance_deleteConfirmDesc({ title: deleting?.title ?? '' })}
|
|
221
|
-
cancelLabel={m.common_common_cancel()}
|
|
222
|
-
confirmLabel={deletePending ? m.common_common_deleting() : m.common_common_delete()}
|
|
223
|
-
confirmClassName="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
|
224
|
-
confirmDisabled={deletePending}
|
|
225
|
-
cancelDisabled={deletePending}
|
|
226
|
-
onConfirm={confirmDelete}
|
|
227
|
-
/>
|
|
228
|
-
</div>
|
|
136
|
+
<KpCrudShell
|
|
137
|
+
title={m.common_knowledgePublic_compliance_title()}
|
|
138
|
+
subtitle={m.common_knowledgePublic_compliance_subtitle({ total })}
|
|
139
|
+
createLabel={m.common_common_create()}
|
|
140
|
+
searchPlaceholder={m.common_knowledgePublic_compliance_placeholder()}
|
|
141
|
+
total={total}
|
|
142
|
+
items={items}
|
|
143
|
+
columns={columns}
|
|
144
|
+
crud={crud}
|
|
145
|
+
deleteConfirmTitle={m.common_knowledgePublic_compliance_deleteConfirmTitle()}
|
|
146
|
+
deleteConfirmDescription={m.common_knowledgePublic_compliance_deleteConfirmDesc({
|
|
147
|
+
title: crud.deleting?.title ?? '',
|
|
148
|
+
})}
|
|
149
|
+
renderFormDialog={({ open, editing, onOpenChange, onSuccess }) => (
|
|
150
|
+
<ComplianceFormDialog open={open} onOpenChange={onOpenChange} item={editing} onSuccess={onSuccess} />
|
|
151
|
+
)}
|
|
152
|
+
/>
|
|
229
153
|
)
|
|
230
154
|
}
|
|
@@ -15,20 +15,17 @@
|
|
|
15
15
|
// You should have received a copy of the GNU Affero General Public License
|
|
16
16
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
17
|
|
|
18
|
-
import { createLazyFileRoute
|
|
18
|
+
import { createLazyFileRoute } from '@tanstack/react-router'
|
|
19
19
|
import { m } from '@/paraglide/messages.js'
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { DataTable, type AdminColumnDef } from '@/components/data-table/data-table'
|
|
20
|
+
import { PencilIcon, Trash2Icon } from 'lucide-react'
|
|
21
|
+
import { type AdminColumnDef } from '@/components/data-table/data-table'
|
|
23
22
|
import { Button } from '@/components/ui/button'
|
|
24
|
-
import { Input } from '@/components/ui/input'
|
|
25
23
|
import { Badge } from '@/components/ui/badge'
|
|
26
|
-
import { ConfirmDialog } from '@/components/confirm-dialog'
|
|
27
|
-
import { toast } from '@/components/ui/toast'
|
|
28
24
|
import { RoutePending } from '@/components/admin/route-pending'
|
|
29
25
|
import { formatDate } from '@/lib/format-date'
|
|
30
26
|
import { LegalFormDialog, type LegalRow } from '@/components/knowledge/public/legal-form-dialog'
|
|
31
27
|
import { adminDeleteLegalFn } from '@/server/serverFns/knowledge/public/legal/delete'
|
|
28
|
+
import { KpCrudShell, useKpCrud } from '@/components/knowledge/public/kp-crud-page'
|
|
32
29
|
|
|
33
30
|
export const Route = createLazyFileRoute('/_nav/knowledge-public/legal')({
|
|
34
31
|
pendingComponent: RoutePending,
|
|
@@ -41,55 +38,15 @@ function LegalPage() {
|
|
|
41
38
|
const { items: rawItems, total } = Route.useLoaderData()
|
|
42
39
|
const items = rawItems as LegalRow[]
|
|
43
40
|
const { search } = Route.useSearch()
|
|
44
|
-
const navigate = useNavigate()
|
|
45
|
-
const router = useRouter()
|
|
46
41
|
const locale = Route.useRouteContext().locale
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
setSearchInput(search ?? '')
|
|
56
|
-
}, [search])
|
|
57
|
-
|
|
58
|
-
function refresh() {
|
|
59
|
-
router.invalidate()
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function applySearch() {
|
|
63
|
-
navigate({
|
|
64
|
-
to: '/knowledge-public/legal',
|
|
65
|
-
search: (s) => ({ ...s, search: searchInput.trim() || undefined }),
|
|
66
|
-
})
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function openCreate() {
|
|
70
|
-
setEditing(null)
|
|
71
|
-
setFormOpen(true)
|
|
72
|
-
}
|
|
73
|
-
function openEdit(row: LegalRow) {
|
|
74
|
-
setEditing(row)
|
|
75
|
-
setFormOpen(true)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function confirmDelete() {
|
|
79
|
-
if (!deleting) return
|
|
80
|
-
startDelete(async () => {
|
|
81
|
-
try {
|
|
82
|
-
await adminDeleteLegalFn({ data: { id: deleting.id } })
|
|
83
|
-
// 传被删条目标题的专用文案;此前 name 参数误传「司法辖区」字段标签,
|
|
84
|
-
// 提示形如「已删除 司法辖区」,与实际删除对象无关
|
|
85
|
-
toast.success(m.common_knowledgePublic_legal_deleted())
|
|
86
|
-
setDeleting(null)
|
|
87
|
-
refresh()
|
|
88
|
-
} catch (err) {
|
|
89
|
-
toast.error(err instanceof Error ? err.message : m.common_common_deleteFailed())
|
|
90
|
-
}
|
|
91
|
-
})
|
|
92
|
-
}
|
|
42
|
+
// S34:状态机与页面 chrome 收敛到共享骨架,页面只保留列定义与域内对话框
|
|
43
|
+
const crud = useKpCrud<LegalRow>({
|
|
44
|
+
routePath: '/knowledge-public/legal',
|
|
45
|
+
search,
|
|
46
|
+
deleteFn: (row) => adminDeleteLegalFn({ data: { id: row.id } }),
|
|
47
|
+
deleteSuccessToast: m.common_knowledgePublic_legal_deleted(),
|
|
48
|
+
})
|
|
49
|
+
const { openEdit, setDeleting } = crud
|
|
93
50
|
|
|
94
51
|
const columns: AdminColumnDef<LegalRow>[] = [
|
|
95
52
|
{
|
|
@@ -173,57 +130,22 @@ function LegalPage() {
|
|
|
173
130
|
]
|
|
174
131
|
|
|
175
132
|
return (
|
|
176
|
-
<
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setSearchInput(e.target.value)}
|
|
194
|
-
onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
195
|
-
if (e.key === 'Enter') applySearch()
|
|
196
|
-
}}
|
|
197
|
-
placeholder={m.common_knowledgePublic_legal_placeholder()}
|
|
198
|
-
className="pl-8"
|
|
199
|
-
/>
|
|
200
|
-
</div>
|
|
201
|
-
<Button variant="outline" onClick={applySearch}>
|
|
202
|
-
{m.common_common_search()}
|
|
203
|
-
</Button>
|
|
204
|
-
</div>
|
|
205
|
-
|
|
206
|
-
<DataTable columns={columns} data={items} />
|
|
207
|
-
|
|
208
|
-
<LegalFormDialog
|
|
209
|
-
open={formOpen}
|
|
210
|
-
onOpenChange={setFormOpen}
|
|
211
|
-
item={editing}
|
|
212
|
-
onSuccess={refresh}
|
|
213
|
-
/>
|
|
214
|
-
|
|
215
|
-
<ConfirmDialog
|
|
216
|
-
open={!!deleting}
|
|
217
|
-
onOpenChange={(o: boolean) => !o && setDeleting(null)}
|
|
218
|
-
title={m.common_knowledgePublic_legal_deleteConfirmTitle()}
|
|
219
|
-
description={m.common_knowledgePublic_legal_deleteConfirmDesc({ title: deleting?.title ?? '' })}
|
|
220
|
-
cancelLabel={m.common_common_cancel()}
|
|
221
|
-
confirmLabel={deletePending ? m.common_common_deleting() : m.common_common_delete()}
|
|
222
|
-
confirmClassName="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
|
223
|
-
confirmDisabled={deletePending}
|
|
224
|
-
cancelDisabled={deletePending}
|
|
225
|
-
onConfirm={confirmDelete}
|
|
226
|
-
/>
|
|
227
|
-
</div>
|
|
133
|
+
<KpCrudShell
|
|
134
|
+
title={m.common_knowledgePublic_legal_title()}
|
|
135
|
+
subtitle={m.common_knowledgePublic_legal_subtitle({ total })}
|
|
136
|
+
createLabel={m.common_common_create()}
|
|
137
|
+
searchPlaceholder={m.common_knowledgePublic_legal_placeholder()}
|
|
138
|
+
total={total}
|
|
139
|
+
items={items}
|
|
140
|
+
columns={columns}
|
|
141
|
+
crud={crud}
|
|
142
|
+
deleteConfirmTitle={m.common_knowledgePublic_legal_deleteConfirmTitle()}
|
|
143
|
+
deleteConfirmDescription={m.common_knowledgePublic_legal_deleteConfirmDesc({
|
|
144
|
+
title: crud.deleting?.title ?? '',
|
|
145
|
+
})}
|
|
146
|
+
renderFormDialog={({ open, editing, onOpenChange, onSuccess }) => (
|
|
147
|
+
<LegalFormDialog open={open} onOpenChange={onOpenChange} item={editing} onSuccess={onSuccess} />
|
|
148
|
+
)}
|
|
149
|
+
/>
|
|
228
150
|
)
|
|
229
|
-
}
|
|
151
|
+
}
|
|
@@ -76,7 +76,7 @@ function MonitoringErrors() {
|
|
|
76
76
|
onOpenChange={setConfirmResetOpen}
|
|
77
77
|
title={m.common_monitoring_errors_clearConfirm_title()}
|
|
78
78
|
description={m.common_monitoring_errors_clearConfirm_description()}
|
|
79
|
-
cancelLabel={m.
|
|
79
|
+
cancelLabel={m.common_common_cancel()}
|
|
80
80
|
confirmLabel={m.common_button_confirm()}
|
|
81
81
|
confirmVariant="destructive"
|
|
82
82
|
onConfirm={() => void handleReset()}
|
|
@@ -166,7 +166,7 @@ function MonitoringLogs() {
|
|
|
166
166
|
onOpenChange={setConfirmClearOpen}
|
|
167
167
|
title={m.common_monitoring_logs_clearConfirm_title()}
|
|
168
168
|
description={m.common_monitoring_logs_clearConfirm_description()}
|
|
169
|
-
cancelLabel={m.
|
|
169
|
+
cancelLabel={m.common_common_cancel()}
|
|
170
170
|
confirmLabel={m.common_button_confirm()}
|
|
171
171
|
confirmVariant="destructive"
|
|
172
172
|
onConfirm={() => void handleClearOld()}
|
|
@@ -81,7 +81,7 @@ function MonitoringMetrics() {
|
|
|
81
81
|
onOpenChange={setConfirmResetOpen}
|
|
82
82
|
title={m.common_monitoring_metrics_clearConfirm_title()}
|
|
83
83
|
description={m.common_monitoring_metrics_clearConfirm_description()}
|
|
84
|
-
cancelLabel={m.
|
|
84
|
+
cancelLabel={m.common_common_cancel()}
|
|
85
85
|
confirmLabel={m.common_button_confirm()}
|
|
86
86
|
confirmVariant="destructive"
|
|
87
87
|
onConfirm={() => void handleReset()}
|
|
@@ -225,7 +225,7 @@ function PermissionsPage(): React.ReactElement {
|
|
|
225
225
|
}}
|
|
226
226
|
title={m.enterprise_permissions_delete_confirm_title({ name: deletingRole?.name ?? '' })}
|
|
227
227
|
description={m.enterprise_permissions_delete_confirm_description()}
|
|
228
|
-
cancelLabel={m.
|
|
228
|
+
cancelLabel={m.common_common_cancel()}
|
|
229
229
|
confirmLabel={m.common_button_confirm()}
|
|
230
230
|
confirmVariant="destructive"
|
|
231
231
|
confirmDisabled={deleting}
|
|
@@ -168,7 +168,7 @@ function SsoConfigPage(): React.ReactElement {
|
|
|
168
168
|
}}
|
|
169
169
|
title={m.enterprise_sso_delete_confirm_title({ name: deletingProvider?.name ?? '' })}
|
|
170
170
|
description={m.enterprise_sso_delete_confirm_description()}
|
|
171
|
-
cancelLabel={m.
|
|
171
|
+
cancelLabel={m.common_common_cancel()}
|
|
172
172
|
confirmLabel={m.common_button_confirm()}
|
|
173
173
|
confirmVariant="destructive"
|
|
174
174
|
confirmDisabled={operating}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
// AllBlue - 理想之海
|
|
3
|
+
// Copyright (C) 2026 AllBlue Contributors
|
|
4
|
+
//
|
|
5
|
+
// This program is free software: you can redistribute it and/or modify
|
|
6
|
+
// it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
// (at your option) any later version.
|
|
9
|
+
//
|
|
10
|
+
// This program is distributed in the hope that it will be useful,
|
|
11
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
// GNU Affero General Public License for more details.
|
|
14
|
+
//
|
|
15
|
+
// You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
// S35(审计 A10 建议):knowledge-public 三域管理 serverFn 泛型工厂。
|
|
19
|
+
// bookmarks/compliance/legal 五类操作(create/update/delete/list/detail)骨架
|
|
20
|
+
// 完全同构(requireAdmin → 委托模型操作),差异仅在域 schema 与 data 映射——
|
|
21
|
+
// 收敛为本工厂后,各域文件退化为「域 schema + 工厂调用」,文件路径与 fn 名
|
|
22
|
+
// 不变(客户端 import 零改动)。
|
|
23
|
+
//
|
|
24
|
+
// 纯净性合规:本文件不是 serverFn 文件(无 createServerFn),值导出不受
|
|
25
|
+
// serverFn 纯净性口径约束;createServerFn 调用仍留在各域文件。
|
|
26
|
+
// delegate 用最小 any 面类型:prisma 泛型 delegate 与结构化最小面不可比,
|
|
27
|
+
// 真实类型安全由各域调用处的 prisma.<model> 具体参数与 select/where 白名单承担。
|
|
28
|
+
|
|
29
|
+
import { getPrisma } from '@allbluecn/database/get-prisma'
|
|
30
|
+
import { requireAdmin } from '@/server/auth-helpers'
|
|
31
|
+
|
|
32
|
+
/** 三域模型 delegate 的最小调用面(any 化理由见文件头) */
|
|
33
|
+
export type KpDelegate = Record<string, any>
|
|
34
|
+
|
|
35
|
+
type GetDelegate = (prisma: Awaited<ReturnType<typeof getPrisma>>) => KpDelegate
|
|
36
|
+
|
|
37
|
+
// ── delete:软删(isDeleted),P2025 转「未找到」──────────────────────────
|
|
38
|
+
|
|
39
|
+
export function kpDeleteHandler(getDelegate: GetDelegate) {
|
|
40
|
+
return async ({ data }: { data: { id: string } }) => {
|
|
41
|
+
const prisma = await getPrisma()
|
|
42
|
+
await requireAdmin()
|
|
43
|
+
// 直接软删,不存在由 P2025 转错误(省一次 findUnique 往返)
|
|
44
|
+
try {
|
|
45
|
+
await getDelegate(prisma).update({ where: { id: data.id }, data: { isDeleted: true } })
|
|
46
|
+
} catch (e) {
|
|
47
|
+
if ((e as { code?: string }).code === 'P2025') throw new Error('未找到')
|
|
48
|
+
throw e
|
|
49
|
+
}
|
|
50
|
+
return { success: true }
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ── detail:公开可见 + 未软删 ──────────────────────────────────────────────
|
|
55
|
+
|
|
56
|
+
export function kpDetailHandler(getDelegate: GetDelegate) {
|
|
57
|
+
return async ({ data }: { data: { id: string } }) => {
|
|
58
|
+
const prisma = await getPrisma()
|
|
59
|
+
await requireAdmin()
|
|
60
|
+
const item = await getDelegate(prisma).findFirst({
|
|
61
|
+
where: { id: data.id, visibility: 'public', isDeleted: false },
|
|
62
|
+
})
|
|
63
|
+
if (!item) throw new Error('未找到')
|
|
64
|
+
return item
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// ── create:requireAdmin + 域 buildData(canonicalId 等域逻辑在回调内)────
|
|
69
|
+
|
|
70
|
+
export function kpCreateHandler<TData>(opts: {
|
|
71
|
+
getDelegate: GetDelegate
|
|
72
|
+
buildData: (data: TData, userId: string) => Record<string, unknown>
|
|
73
|
+
select?: Record<string, boolean>
|
|
74
|
+
}) {
|
|
75
|
+
return async ({ data }: { data: TData }) => {
|
|
76
|
+
const prisma = await getPrisma()
|
|
77
|
+
const session = await requireAdmin()
|
|
78
|
+
const userId = session.user?.id
|
|
79
|
+
if (!userId) throw new Error('Unauthorized')
|
|
80
|
+
return opts.getDelegate(prisma).create({
|
|
81
|
+
data: opts.buildData(data, userId),
|
|
82
|
+
select: opts.select ?? { id: true },
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// ── update:findUnique 存在性 + 域 buildUpdateData(canonicalId 回退等在回调内)──
|
|
88
|
+
|
|
89
|
+
export function kpUpdateHandler<TData extends { id: string }>(opts: {
|
|
90
|
+
getDelegate: GetDelegate
|
|
91
|
+
buildUpdateData: (data: TData, existing: Record<string, any>) => Record<string, unknown>
|
|
92
|
+
select?: Record<string, boolean>
|
|
93
|
+
}) {
|
|
94
|
+
return async ({ data }: { data: TData }) => {
|
|
95
|
+
const prisma = await getPrisma()
|
|
96
|
+
await requireAdmin()
|
|
97
|
+
const { id, ...rest } = data
|
|
98
|
+
const existing = await opts.getDelegate(prisma).findUnique({ where: { id } })
|
|
99
|
+
if (!existing) throw new Error('未找到')
|
|
100
|
+
void rest
|
|
101
|
+
const updateData = opts.buildUpdateData(data, existing)
|
|
102
|
+
return opts.getDelegate(prisma).update({ where: { id }, data: updateData, select: opts.select ?? { id: true } })
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// ── list:public + 未软删基线 + 域过滤(search OR 等)+ 分页 ────────────────
|
|
107
|
+
|
|
108
|
+
export function kpListHandler<TData extends { page: number; pageSize: number }>(opts: {
|
|
109
|
+
getDelegate: GetDelegate
|
|
110
|
+
/** 基线(visibility/isDeleted)之外的域条件,含 search 的 OR 子句 */
|
|
111
|
+
buildWhere: (data: TData) => Record<string, unknown>
|
|
112
|
+
select: Record<string, any>
|
|
113
|
+
orderBy?: Record<string, 'asc' | 'desc'>
|
|
114
|
+
/** 行后处理(如 bookmarks 的 category join → categoryIcon 拍平) */
|
|
115
|
+
postProcess?: (items: any[]) => unknown[]
|
|
116
|
+
}) {
|
|
117
|
+
return async ({ data }: { data: TData }) => {
|
|
118
|
+
const prisma = await getPrisma()
|
|
119
|
+
await requireAdmin()
|
|
120
|
+
const where = { visibility: 'public', isDeleted: false, ...opts.buildWhere(data) }
|
|
121
|
+
const [items, total] = await Promise.all([
|
|
122
|
+
opts.getDelegate(prisma).findMany({
|
|
123
|
+
where,
|
|
124
|
+
select: opts.select,
|
|
125
|
+
orderBy: opts.orderBy ?? { createdAt: 'desc' },
|
|
126
|
+
skip: (data.page - 1) * data.pageSize,
|
|
127
|
+
take: data.pageSize,
|
|
128
|
+
}),
|
|
129
|
+
opts.getDelegate(prisma).count({ where }),
|
|
130
|
+
])
|
|
131
|
+
const rows = opts.postProcess ? opts.postProcess(items) : items
|
|
132
|
+
return { items: rows, total, page: data.page, pageSize: data.pageSize }
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
|
|
18
18
|
import { createServerFn } from '@tanstack/react-start'
|
|
19
19
|
import { z } from 'zod'
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
20
|
+
import { bookmarkCanonicalId } from '@/server/knowledge/public/canonical-id'
|
|
21
|
+
import { parseGithubUrl } from '@/server/knowledge/public/canonical-id'
|
|
22
|
+
import { kpCreateHandler } from '@/server/knowledge/public/kp-factory'
|
|
23
23
|
|
|
24
24
|
const createSchema = z.object({
|
|
25
25
|
title: z.string().min(1).max(200),
|
|
@@ -37,26 +37,24 @@ const createSchema = z.object({
|
|
|
37
37
|
|
|
38
38
|
export const adminCreateBookmarkFn = createServerFn({ method: 'POST' })
|
|
39
39
|
.validator(createSchema)
|
|
40
|
-
.handler(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
githubRepo: gh?.repo ?? null,
|
|
40
|
+
.handler(
|
|
41
|
+
kpCreateHandler<z.infer<typeof createSchema>>({
|
|
42
|
+
getDelegate: (prisma) => prisma.websiteBookmark,
|
|
43
|
+
buildData: (data, userId) => {
|
|
44
|
+
const gh = parseGithubUrl(data.url)
|
|
45
|
+
return {
|
|
46
|
+
canonicalId: bookmarkCanonicalId(data.url),
|
|
47
|
+
title: data.title,
|
|
48
|
+
url: data.url,
|
|
49
|
+
categoryId: data.categoryId || null,
|
|
50
|
+
summary: data.summary || null,
|
|
51
|
+
tags: data.tags,
|
|
52
|
+
visibility: 'public',
|
|
53
|
+
userId,
|
|
54
|
+
isGithub: !!gh,
|
|
55
|
+
githubOwner: gh?.owner ?? null,
|
|
56
|
+
githubRepo: gh?.repo ?? null,
|
|
57
|
+
}
|
|
59
58
|
},
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
})
|
|
59
|
+
}),
|
|
60
|
+
)
|
|
@@ -17,20 +17,8 @@
|
|
|
17
17
|
|
|
18
18
|
import { createServerFn } from '@tanstack/react-start'
|
|
19
19
|
import { z } from 'zod'
|
|
20
|
-
import {
|
|
21
|
-
import { requireAdmin } from '@/server/auth-helpers'
|
|
20
|
+
import { kpDeleteHandler } from '@/server/knowledge/public/kp-factory'
|
|
22
21
|
|
|
23
22
|
export const adminDeleteBookmarkFn = createServerFn({ method: 'POST' })
|
|
24
23
|
.validator(z.object({ id: z.string() }))
|
|
25
|
-
.handler(
|
|
26
|
-
const prisma = await getPrisma()
|
|
27
|
-
await requireAdmin()
|
|
28
|
-
// 直接软删,不存在由 P2025 转错误(省一次 findUnique 往返)
|
|
29
|
-
try {
|
|
30
|
-
await prisma.websiteBookmark.update({ where: { id: data.id }, data: { isDeleted: true } })
|
|
31
|
-
} catch (e) {
|
|
32
|
-
if ((e as { code?: string }).code === 'P2025') throw new Error('未找到')
|
|
33
|
-
throw e
|
|
34
|
-
}
|
|
35
|
-
return { success: true }
|
|
36
|
-
})
|
|
24
|
+
.handler(kpDeleteHandler((prisma) => prisma.websiteBookmark))
|
|
@@ -17,17 +17,8 @@
|
|
|
17
17
|
|
|
18
18
|
import { createServerFn } from '@tanstack/react-start'
|
|
19
19
|
import { z } from 'zod'
|
|
20
|
-
import {
|
|
21
|
-
import { requireAdmin } from '@/server/auth-helpers'
|
|
20
|
+
import { kpDetailHandler } from '@/server/knowledge/public/kp-factory'
|
|
22
21
|
|
|
23
22
|
export const adminGetBookmarkDetailFn = createServerFn({ method: 'GET' })
|
|
24
23
|
.validator(z.object({ id: z.string() }))
|
|
25
|
-
.handler(
|
|
26
|
-
const prisma = await getPrisma()
|
|
27
|
-
await requireAdmin()
|
|
28
|
-
const item = await prisma.websiteBookmark.findFirst({
|
|
29
|
-
where: { id: data.id, visibility: 'public', isDeleted: false },
|
|
30
|
-
})
|
|
31
|
-
if (!item) throw new Error('未找到')
|
|
32
|
-
return item
|
|
33
|
-
})
|
|
24
|
+
.handler(kpDetailHandler((prisma) => prisma.websiteBookmark))
|