feat(system): consolidate system admin and settings into one Settings panel
Replace the standalone /platform/system/* routes with a single
"系统设置" section inside the canonical Settings modal. The previous
SystemLayout.vue / SystemAdmins.vue surfaces are removed and their
functionality (system admin roster, global settings) is hosted directly
in SystemSettings.vue under the standard `.section-header` /
`.settings-group` skeleton. Legacy URLs redirect to the modal section
so external bookmarks don't 404.
Backend:
- SystemSettingService.Reset + repo.Delete: drop the DB override for a
key so the 3-tier resolver falls back to ENV / built-in default.
Idempotent (resetting a never-persisted key returns nil); emits an
audit row only on real deletions, invalidates the local cache, and
publishes to peers via the existing pubsub channel.
- TenantService.BulkSetStorageQuota: overwrite every tenant's
storage_quota in one statement. Powers POST /system/admin/tenants/
apply-default-storage-quota; bypasses the per-tenant whitelist on
PUT /tenants/:id which intentionally forbids storage_quota edits.
- AuditAction{SystemAdminPromoted,SystemAdminRevoked} constants and
emitAdminAudit() in SystemHandler — promote / revoke now leave an
audit trail with TenantID=0 and {target_email,target_username,
idempotent|changed} in details.
- SystemSetting.LastModifiedByName: derived per-request display label
(username, email fallback) so the UI shows "wizardchen" instead of
a UUID prefix without storing a denormalised column.
Frontend:
- SystemSettings.vue rewritten against the Settings modal skeleton with
auto-persisting controls (switch/select @change, input/inputnumber
@blur, tag-input + per-delta popconfirm for SSRF whitelist and admin
roster). auth.registration_mode change goes through an inline
popconfirm; cancel rolls back. Reset / bulk-apply also inline
popconfirms — no dialog modal for these per-row affordances.
- Priority hint panel surfaces the DB > ENV > default resolver order
so operators can reason about "I set the env but it doesn't show up".
- Router: /platform/system, /platform/system/settings, /platform/system/
admins are now compatibility redirects to /platform/settings?section=
system-global.
- Settings modal sized 900x700 → 1080x780 and content-wrapper 600 → 760
so the wider tables (members, system settings) breathe; <1100px
viewport still flexes to the screen.
- i18n: system.globalSettings.* keys for title / description / loading /
empty / badges / priority hint / per-key labels / reset / bulkApply /
admins (label, placeholder, save messages, popconfirm copy) across
zh-CN, en-US, ko-KR, ru-RU.
Misc:
- internal/utils/filesize.go doc: clarify MAX_FILE_SIZE_MB is a
deploy-time-only knob (nginx + docreader + frontend each cache the
env at startup); a SystemAdmin UI override would mislead operators
because nginx would still 413. Until all four layers can hot-reload
the limit in lockstep, this stays env-only.
- internal/utils/security.go: SSRF whitelist parser/runtime now drives
off SystemSettingService for live updates; ENV remains the fallback
for never-overridden deployments.
This commit is contained in:
@@ -284,8 +284,8 @@ const navItems = computed(() => {
|
||||
{ key: 'parser', icon: 'file-search', label: t('settings.parserEngine') },
|
||||
{ key: 'storage', icon: 'cloud', label: t('settings.storageEngine') },
|
||||
{ key: 'mcp', icon: 'tools', label: t('settings.mcpService') },
|
||||
{ key: 'system', icon: 'info-circle', label: t('settings.systemSettings') },
|
||||
{ key: 'system-global', icon: 'server', label: '全局设置' },
|
||||
{ key: 'system', icon: 'info-circle', label: t('settings.versionInfo') },
|
||||
{ key: 'system-global', icon: 'server', label: '系统设置' },
|
||||
{ key: 'userprofile', icon: 'user', label: t('userProfile.title') },
|
||||
{ key: 'tenant', icon: 'user-circle', label: t('settings.tenantInfo') },
|
||||
{ key: 'members', icon: 'usergroup', label: t('tenantMember.title') },
|
||||
@@ -376,7 +376,8 @@ const handleClose = () => {
|
||||
uiStore.closeSettings()
|
||||
// 如果当前路由是设置页,返回上一页
|
||||
if (route.path === '/platform/settings') {
|
||||
if (route.query.section === 'system-global') {
|
||||
const sec = route.query.section
|
||||
if (sec === 'system-global') {
|
||||
router.push('/platform/knowledge-bases')
|
||||
} else {
|
||||
router.back()
|
||||
@@ -480,8 +481,13 @@ onUnmounted(() => {
|
||||
.settings-modal {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
max-width: 900px;
|
||||
height: 700px;
|
||||
// 1080×780 trades a touch of small-screen real estate for noticeably
|
||||
// less cramped tables (member list, system settings rows). Outer
|
||||
// padding is 20px so 1080 + 40 = 1120, comfortably within typical
|
||||
// laptops (1280+). Below 1100px viewport the `width: 100%` kicks in
|
||||
// and the modal shrinks to fit minus the 20px padding.
|
||||
max-width: 1080px;
|
||||
height: 780px;
|
||||
background: var(--td-bg-color-container);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 6px 28px rgba(15, 23, 42, 0.08);
|
||||
@@ -668,7 +674,13 @@ onUnmounted(() => {
|
||||
}
|
||||
|
||||
.content-wrapper {
|
||||
max-width: 600px;
|
||||
// Bumped from 600 to 760 when the modal grew from 900→1080 (see
|
||||
// .settings-modal). Without this, single-column panes (General,
|
||||
// Tenant, API key, …) leave a wide right-hand gutter inside the
|
||||
// wider modal. 760 keeps comfortable reading-width on long
|
||||
// descriptions without the form fields stretching to the full
|
||||
// panel width — which would look stranger than a small gutter.
|
||||
max-width: 760px;
|
||||
padding: 40px 48px;
|
||||
|
||||
/* 成员 / 审计表格列多,600px 会把操作列挤到贴边;铺满右侧内容列更稳。 */
|
||||
|
||||
@@ -1,259 +0,0 @@
|
||||
<template>
|
||||
<!--
|
||||
SystemAdmins — list & manage the platform-wide system administrators.
|
||||
Grants/revokes via the /api/v1/system/admin/{promote,revoke,list}
|
||||
endpoints (server-side guarded by RequireSystemAdmin middleware).
|
||||
|
||||
P0 milestone scope is deliberately minimal:
|
||||
- Paginated list of current system admins
|
||||
- Promote a user by email
|
||||
- Revoke an existing admin (with last-admin & self-revoke server guards)
|
||||
|
||||
Future milestones can layer richer UX on top — search, audit-log
|
||||
drawer, bulk operations — but the API surface and gating are stable.
|
||||
-->
|
||||
<div class="system-admins">
|
||||
<div class="page-header">
|
||||
<div>
|
||||
<h1 class="page-title">系统管理员</h1>
|
||||
<p class="page-desc">
|
||||
系统管理员独立于租户角色,拥有平台级管理权限(管理其他系统管理员、全局设置、内置模型等)。
|
||||
</p>
|
||||
</div>
|
||||
<t-button theme="primary" @click="openPromoteDialog">
|
||||
<template #icon><t-icon name="add" /></template>
|
||||
提升用户为系统管理员
|
||||
</t-button>
|
||||
</div>
|
||||
|
||||
<t-card class="admins-card" :bordered="false">
|
||||
<t-table
|
||||
row-key="id"
|
||||
:data="admins"
|
||||
:columns="columns"
|
||||
:loading="loading"
|
||||
size="medium"
|
||||
hover
|
||||
stripe
|
||||
>
|
||||
<template #status="{ row }">
|
||||
<t-tag v-if="row.is_active" theme="success" variant="light">
|
||||
活跃
|
||||
</t-tag>
|
||||
<t-tag v-else theme="warning" variant="light">已停用</t-tag>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<t-button
|
||||
theme="danger"
|
||||
variant="text"
|
||||
size="small"
|
||||
:disabled="row.id === currentUserId"
|
||||
@click="confirmRevoke(row)"
|
||||
>
|
||||
撤销权限
|
||||
</t-button>
|
||||
</template>
|
||||
</t-table>
|
||||
|
||||
<div class="pagination-bar" v-if="total > 0">
|
||||
<t-pagination
|
||||
v-model="page"
|
||||
v-model:page-size="pageSize"
|
||||
:total="total"
|
||||
:page-size-options="[20, 50, 100]"
|
||||
@change="loadAdmins"
|
||||
/>
|
||||
</div>
|
||||
</t-card>
|
||||
|
||||
<!-- Promote dialog -->
|
||||
<t-dialog
|
||||
v-model:visible="promoteDialogVisible"
|
||||
header="提升用户为系统管理员"
|
||||
:confirm-btn="{ content: '确认提升', loading: promoting }"
|
||||
@confirm="submitPromote"
|
||||
@close="resetPromoteDialog"
|
||||
>
|
||||
<p class="dialog-hint">
|
||||
请输入要提升的用户的 ID。该用户必须已经在系统中注册过;操作幂等,已是管理员的用户不会被重复提升。
|
||||
</p>
|
||||
<t-input
|
||||
v-model="promoteUserId"
|
||||
placeholder="用户 ID(UUID 形式)"
|
||||
:disabled="promoting"
|
||||
clearable
|
||||
/>
|
||||
</t-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, computed } from 'vue'
|
||||
import { MessagePlugin, DialogPlugin } from 'tdesign-vue-next'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import {
|
||||
listSystemAdmins,
|
||||
promoteUserToSystemAdmin,
|
||||
revokeSystemAdmin,
|
||||
type SystemAdminUser,
|
||||
} from '@/api/system'
|
||||
|
||||
const authStore = useAuthStore()
|
||||
const currentUserId = computed(() => authStore.currentUserId)
|
||||
|
||||
const admins = ref<SystemAdminUser[]>([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(20)
|
||||
const loading = ref(false)
|
||||
|
||||
const promoteDialogVisible = ref(false)
|
||||
const promoteUserId = ref('')
|
||||
const promoting = ref(false)
|
||||
|
||||
// Columns are defined as a computed (vs a static const) so future
|
||||
// localization/translation can hook in without component refactor.
|
||||
const columns = [
|
||||
{ colKey: 'username', title: '用户名', width: 180 },
|
||||
{ colKey: 'email', title: '邮箱', width: 280 },
|
||||
{ colKey: 'status', title: '状态', width: 100 },
|
||||
{ colKey: 'created_at', title: '注册时间', width: 200 },
|
||||
{ colKey: 'actions', title: '操作', width: 120, align: 'right' as const },
|
||||
]
|
||||
|
||||
async function loadAdmins() {
|
||||
loading.value = true
|
||||
try {
|
||||
const offset = (page.value - 1) * pageSize.value
|
||||
// listSystemAdmins resolves to ListSystemAdminsResponse directly —
|
||||
// utils/request.ts already unwraps axios's response.data wrapper at
|
||||
// the interceptor layer (see line 97), so an extra `.data` here
|
||||
// would explode at runtime as "Cannot read property 'admins' of
|
||||
// undefined" and surface as the generic load-failed toast.
|
||||
const res = await listSystemAdmins({ offset, limit: pageSize.value })
|
||||
admins.value = res.admins ?? []
|
||||
total.value = res.total ?? 0
|
||||
} catch (err) {
|
||||
// Surface a toast and bail — keeping prior list so the user isn't
|
||||
// left staring at an empty table on a transient failure.
|
||||
MessagePlugin.error('加载系统管理员列表失败')
|
||||
console.error('listSystemAdmins failed:', err)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function openPromoteDialog() {
|
||||
promoteUserId.value = ''
|
||||
promoteDialogVisible.value = true
|
||||
}
|
||||
|
||||
function resetPromoteDialog() {
|
||||
promoteUserId.value = ''
|
||||
promoting.value = false
|
||||
}
|
||||
|
||||
async function submitPromote() {
|
||||
const uid = promoteUserId.value.trim()
|
||||
if (!uid) {
|
||||
MessagePlugin.warning('请输入用户 ID')
|
||||
return
|
||||
}
|
||||
promoting.value = true
|
||||
try {
|
||||
await promoteUserToSystemAdmin(uid)
|
||||
MessagePlugin.success('已提升为系统管理员')
|
||||
promoteDialogVisible.value = false
|
||||
await loadAdmins()
|
||||
} catch (err: any) {
|
||||
// utils/request.ts 把后端的 {error: "..."} 提升到了顶层 message
|
||||
// 字段(line 197-213),同时保留原始 data 字段。我们优先读 message
|
||||
// —— 它已经是后端的 human-readable 错误文案,覆盖了 user-not-found
|
||||
// / 自我撤销等业务错误场景。
|
||||
const msg = err?.message || err?.error || '提升失败,请检查用户 ID 后重试'
|
||||
MessagePlugin.error(msg)
|
||||
} finally {
|
||||
promoting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function confirmRevoke(row: SystemAdminUser) {
|
||||
// Confirmation dialog is mandatory — revoking is destructive and
|
||||
// the server's last-admin / self-revoke guards return 400 with a
|
||||
// human-readable message which we re-surface in submitRevoke.
|
||||
const confirmDialog = DialogPlugin.confirm({
|
||||
header: '撤销系统管理员权限',
|
||||
body: `确定要撤销用户 "${row.username}" (${row.email}) 的系统管理员权限吗?`,
|
||||
confirmBtn: { content: '确认撤销', theme: 'danger' },
|
||||
cancelBtn: '取消',
|
||||
onConfirm: async () => {
|
||||
await submitRevoke(row.id)
|
||||
confirmDialog.destroy()
|
||||
},
|
||||
onClose: () => confirmDialog.destroy(),
|
||||
})
|
||||
}
|
||||
|
||||
async function submitRevoke(userId: string) {
|
||||
try {
|
||||
await revokeSystemAdmin(userId)
|
||||
MessagePlugin.success('已撤销系统管理员权限')
|
||||
await loadAdmins()
|
||||
} catch (err: any) {
|
||||
// 同 submitPromote 的注释 —— 后端 last-admin / self-revoke 保护
|
||||
// 走 400 + {error: "..."},被拦截器抬到 err.message。
|
||||
const msg = err?.message || err?.error || '撤销失败'
|
||||
MessagePlugin.error(msg)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadAdmins()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.system-admins {
|
||||
max-width: 1100px;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 24px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
margin: 0 0 6px;
|
||||
font-size: 22px;
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-primary, #000);
|
||||
}
|
||||
|
||||
.page-desc {
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
color: var(--td-text-color-secondary, #666);
|
||||
max-width: 720px;
|
||||
}
|
||||
|
||||
.admins-card {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.pagination-bar {
|
||||
margin-top: 16px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.dialog-hint {
|
||||
margin: 0 0 12px;
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-secondary, #666);
|
||||
line-height: 1.6;
|
||||
}
|
||||
</style>
|
||||
@@ -1,127 +0,0 @@
|
||||
<template>
|
||||
<!--
|
||||
SystemLayout — top-level shell for the platform-wide administration
|
||||
area (/platform/system/*). Gated by meta.requiresSystemAdmin in the
|
||||
router; reaching this component means the caller is an authenticated
|
||||
SystemAdmin.
|
||||
|
||||
Sidebar is intentionally simple: global system settings live inside
|
||||
the standard Settings modal, while this routed area keeps workflows
|
||||
that need a table-oriented management surface.
|
||||
-->
|
||||
<div class="system-layout">
|
||||
<aside class="system-sidebar">
|
||||
<div class="system-sidebar-header">
|
||||
<h2 class="system-sidebar-title">系统管理</h2>
|
||||
<div class="system-sidebar-subtitle">SystemAdmin</div>
|
||||
</div>
|
||||
<nav class="system-nav">
|
||||
<router-link
|
||||
v-for="item in navItems"
|
||||
:key="item.name"
|
||||
:to="{ name: item.name }"
|
||||
v-slot="{ isActive, navigate }"
|
||||
custom
|
||||
>
|
||||
<div
|
||||
:class="['system-nav-item', { active: isActive }]"
|
||||
@click="navigate"
|
||||
>
|
||||
<t-icon :name="item.icon" class="system-nav-icon" />
|
||||
<span class="system-nav-label">{{ item.label }}</span>
|
||||
</div>
|
||||
</router-link>
|
||||
</nav>
|
||||
</aside>
|
||||
<main class="system-content">
|
||||
<router-view />
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
// Nav items are declared here (not in a separate config file) because
|
||||
// the list is short and tightly coupled to which child routes exist.
|
||||
// When a new child route is added in router/index.ts under /platform/system,
|
||||
// add a matching entry here.
|
||||
const navItems = [
|
||||
{ name: 'systemAdmins', label: '系统管理员', icon: 'user-shield' },
|
||||
]
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.system-layout {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
background: var(--td-bg-color-page, #f5f5f5);
|
||||
}
|
||||
|
||||
.system-sidebar {
|
||||
width: 240px;
|
||||
flex-shrink: 0;
|
||||
background: var(--td-bg-color-container, #fff);
|
||||
border-right: 1px solid var(--td-border-level-1-color, #e7e7e7);
|
||||
padding: 20px 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.system-sidebar-header {
|
||||
padding: 0 12px 12px;
|
||||
border-bottom: 1px solid var(--td-border-level-1-color, #e7e7e7);
|
||||
}
|
||||
|
||||
.system-sidebar-title {
|
||||
margin: 0;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-primary, #000);
|
||||
}
|
||||
|
||||
.system-sidebar-subtitle {
|
||||
font-size: 11px;
|
||||
color: var(--td-text-color-placeholder, #999);
|
||||
margin-top: 4px;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.system-nav {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.system-nav-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 8px 12px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
color: var(--td-text-color-primary, #333);
|
||||
transition: background-color 0.15s;
|
||||
}
|
||||
|
||||
.system-nav-item:hover {
|
||||
background: var(--td-bg-color-component-hover, #f3f3f3);
|
||||
}
|
||||
|
||||
.system-nav-item.active {
|
||||
background: var(--td-brand-color-light, #e0eaff);
|
||||
color: var(--td-brand-color, #0052d9);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.system-nav-icon {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.system-content {
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
padding: 24px 32px;
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user