feat: restructure notification services

This commit is contained in:
fawney19
2026-05-22 01:45:46 +08:00
parent d5e64d6ad9
commit 504c1ccb37
28 changed files with 1941 additions and 460 deletions
@@ -11,6 +11,9 @@ const authStoreMock = vi.hoisted(() => ({
}))
const routerPushMock = vi.hoisted(() => vi.fn())
const routeMock = vi.hoisted(() => ({
query: {},
}))
const toastMocks = vi.hoisted(() => ({
success: vi.fn(),
warning: vi.fn(),
@@ -27,6 +30,7 @@ const oauthApiMocks = vi.hoisted(() => ({
}))
vi.mock('vue-router', () => ({
useRoute: () => routeMock,
useRouter: () => ({
push: routerPushMock,
}),
@@ -157,6 +161,7 @@ beforeEach(() => {
authStoreMock.error = ''
authStoreMock.canAccessAdmin = false
authStoreMock.login.mockReset()
routeMock.query = {}
routerPushMock.mockReset()
toastMocks.success.mockReset()
toastMocks.warning.mockReset()
@@ -247,7 +247,7 @@
额度提醒
</Label>
<p class="mt-1 text-xs text-muted-foreground">
余额低于阈值时通过重要通知发送提醒
余额低于阈值时通过通知服务发送提醒
</p>
</div>
<Switch v-model="quotaAlert.enabled" />
@@ -14,7 +14,16 @@ const endpointMocks = vi.hoisted(() => ({
getAwsRegions: vi.fn(),
}))
vi.mock('@/api/endpoints', () => endpointMocks)
vi.mock('@/api/endpoints', async () => {
const actual = await vi.importActual<typeof import('@/api/endpoints/provider_oauth')>(
'@/api/endpoints/provider_oauth',
)
return {
...endpointMocks,
normalizeBatchImportCredentials: actual.normalizeBatchImportCredentials,
}
})
vi.mock('@/components/ui', async () => {
const { defineComponent, h } = await import('vue')
@@ -358,7 +367,7 @@ describe('OAuthAccountDialog Grok import', () => {
expect(endpointMocks.startBatchImportOAuthTask).toHaveBeenCalledWith(
'provider-1',
'sso-1\nsso-2',
'["sso-1","sso-2"]',
undefined,
)
expect(endpointMocks.importProviderRefreshToken).not.toHaveBeenCalled()
@@ -214,6 +214,9 @@
</div>
<div class="rounded-lg border border-border bg-muted/30 p-3">
<div class="mb-3 text-xs font-semibold text-muted-foreground">
功能权限
</div>
<div class="flex items-center justify-between gap-3">
<Label class="text-sm font-medium">敏感信息保护</Label>
<Switch v-model="form.chat_pii_redaction_enabled" />
@@ -225,6 +228,15 @@
:disabled="!form.chat_pii_redaction_enabled"
/>
</div>
<div class="mt-3 flex items-center justify-between gap-3 border-t border-border/60 pt-3">
<div>
<Label class="text-sm font-medium">通知推送服务</Label>
<p class="mt-1 text-xs text-muted-foreground">
允许用户配置自己的第三方推送渠道
</p>
</div>
<Switch v-model="form.notification_push_service_enabled" />
</div>
</div>
</div>
</form>
@@ -271,6 +283,8 @@ import { log } from '@/utils/logger'
import { parseNumberInput } from '@/utils/form'
import {
mergeChatPiiRedactionFeatureSettings,
mergeNotificationPushServiceFeatureSettings,
readNotificationPushServiceFeatureSettings,
readChatPiiRedactionFeatureSettings,
} from '@/utils/featureSettings'
import {
@@ -323,6 +337,7 @@ const form = ref({
group_ids: [] as string[],
chat_pii_redaction_enabled: false,
chat_pii_redaction_placeholder_notice: true,
notification_push_service_enabled: false,
})
const groupOptions = computed(() => (props.groups || []).map((group) => ({
@@ -348,6 +363,7 @@ function resetForm() {
group_ids: [],
chat_pii_redaction_enabled: false,
chat_pii_redaction_placeholder_notice: true,
notification_push_service_enabled: false,
}
}
@@ -355,6 +371,7 @@ function loadUserData() {
if (!props.user) return
formNonce.value = createFieldNonce()
const redactionFeature = readChatPiiRedactionFeatureSettings(props.user.feature_settings)
const notificationPushFeature = readNotificationPushServiceFeatureSettings(props.user.feature_settings)
// 创建数组副本,避免与 props 数据共享引用
form.value = {
username: props.user.username,
@@ -368,6 +385,7 @@ function loadUserData() {
group_ids: props.user.group_ids ? [...props.user.group_ids] : [],
chat_pii_redaction_enabled: redactionFeature.enabled,
chat_pii_redaction_placeholder_notice: redactionFeature.inject_model_instruction,
notification_push_service_enabled: notificationPushFeature.enabled,
}
}
@@ -442,10 +460,7 @@ async function handleSubmit() {
unlimited: form.value.unlimited,
role: form.value.role,
group_ids: [...form.value.group_ids],
feature_settings: mergeChatPiiRedactionFeatureSettings(props.user?.feature_settings, {
enabled: form.value.chat_pii_redaction_enabled,
inject_model_instruction: form.value.chat_pii_redaction_placeholder_notice,
}),
feature_settings: buildFeatureSettingsPayload(),
}
if (isEditMode.value && props.user?.id) {
@@ -472,6 +487,16 @@ async function handleSubmit() {
}
}
function buildFeatureSettingsPayload(): Record<string, unknown> | null {
const withRedaction = mergeChatPiiRedactionFeatureSettings(props.user?.feature_settings, {
enabled: form.value.chat_pii_redaction_enabled,
inject_model_instruction: form.value.chat_pii_redaction_placeholder_notice,
})
return mergeNotificationPushServiceFeatureSettings(withRedaction, {
enabled: form.value.notification_push_service_enabled,
})
}
// 设置保存状态(供父组件调用)
function setSaving(value: boolean) {
saving.value = value