Update Local Permission Assignments
This commit is contained in:
@@ -29,6 +29,7 @@ const userFormSchema = z.object({
|
||||
password: z.string().optional(),
|
||||
is_active: z.boolean(),
|
||||
is_superuser: z.boolean(),
|
||||
can_use_local_model: z.boolean(),
|
||||
})
|
||||
|
||||
type UserFormValues = z.infer<typeof userFormSchema>
|
||||
@@ -58,6 +59,7 @@ export function UserDialog({
|
||||
password: '',
|
||||
is_active: true,
|
||||
is_superuser: false,
|
||||
can_use_local_model: false,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -69,6 +71,7 @@ export function UserDialog({
|
||||
password: '',
|
||||
is_active: user.is_active,
|
||||
is_superuser: user.is_superuser,
|
||||
can_use_local_model: user.can_use_local_model,
|
||||
})
|
||||
} else {
|
||||
form.reset({
|
||||
@@ -77,6 +80,7 @@ export function UserDialog({
|
||||
password: '',
|
||||
is_active: true,
|
||||
is_superuser: false,
|
||||
can_use_local_model: false,
|
||||
})
|
||||
}
|
||||
}, [user, form])
|
||||
@@ -178,6 +182,27 @@ export function UserDialog({
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="can_use_local_model"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex flex-row items-start space-x-3 space-y-0">
|
||||
<FormControl>
|
||||
<Checkbox
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
/>
|
||||
</FormControl>
|
||||
<div className="space-y-1 leading-none">
|
||||
<FormLabel>本地模型权限</FormLabel>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
允许用户使用本地 TTS 模型
|
||||
</p>
|
||||
</div>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<DialogFooter className="flex-col sm:flex-row gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
|
||||
@@ -38,6 +38,7 @@ export function UserTable({ users, isLoading, onEdit, onDelete }: UserTableProps
|
||||
<th className="px-4 py-3 font-medium">邮箱</th>
|
||||
<th className="px-4 py-3 font-medium">状态</th>
|
||||
<th className="px-4 py-3 font-medium">角色</th>
|
||||
<th className="px-4 py-3 font-medium">权限</th>
|
||||
<th className="px-4 py-3 font-medium">创建时间</th>
|
||||
<th className="px-4 py-3 font-medium text-right">操作</th>
|
||||
</tr>
|
||||
@@ -58,6 +59,11 @@ export function UserTable({ users, isLoading, onEdit, onDelete }: UserTableProps
|
||||
{user.is_superuser ? '超级管理员' : '普通用户'}
|
||||
</Badge>
|
||||
</td>
|
||||
<td className="px-4 py-3">
|
||||
{(user.is_superuser || user.can_use_local_model) && (
|
||||
<Badge variant="secondary">本地模型</Badge>
|
||||
)}
|
||||
</td>
|
||||
<td className="px-4 py-3">
|
||||
{new Date(user.created_at).toLocaleString('zh-CN')}
|
||||
</td>
|
||||
@@ -129,6 +135,14 @@ export function UserTable({ users, isLoading, onEdit, onDelete }: UserTableProps
|
||||
{user.is_superuser ? '超级管理员' : '普通用户'}
|
||||
</Badge>
|
||||
</div>
|
||||
<div className="flex justify-between items-center">
|
||||
<span className="text-muted-foreground">权限:</span>
|
||||
{(user.is_superuser || user.can_use_local_model) ? (
|
||||
<Badge variant="secondary">本地模型</Badge>
|
||||
) : (
|
||||
<span className="text-xs text-muted-foreground">无</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">创建时间:</span>
|
||||
<span className="text-xs">{new Date(user.created_at).toLocaleString('zh-CN')}</span>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import axios from 'axios'
|
||||
import type { LoginRequest, LoginResponse, User, PasswordChangeRequest, UserPreferences, SystemSettings } from '@/types/auth'
|
||||
import type { LoginRequest, LoginResponse, User, PasswordChangeRequest, UserPreferences } from '@/types/auth'
|
||||
import type { Job, JobCreateResponse, JobListResponse, JobType } from '@/types/job'
|
||||
import type { Language, Speaker, CustomVoiceForm, VoiceDesignForm, VoiceCloneForm } from '@/types/tts'
|
||||
import type { UserCreateRequest, UserUpdateRequest, UserListResponse } from '@/types/user'
|
||||
@@ -210,14 +210,6 @@ export const authApi = {
|
||||
return response.data
|
||||
},
|
||||
|
||||
getSystemSettings: async (): Promise<SystemSettings> => {
|
||||
const response = await apiClient.get<SystemSettings>('/users/system/settings')
|
||||
return response.data
|
||||
},
|
||||
|
||||
updateSystemSettings: async (settings: { local_model_enabled: boolean }): Promise<void> => {
|
||||
await apiClient.put('/users/system/settings', settings)
|
||||
},
|
||||
}
|
||||
|
||||
export const ttsApi = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useState } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import * as z from 'zod'
|
||||
@@ -10,7 +10,6 @@ import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
@@ -38,7 +37,6 @@ export default function Settings() {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [showPasswordDialog, setShowPasswordDialog] = useState(false)
|
||||
const [isPasswordLoading, setIsPasswordLoading] = useState(false)
|
||||
const [localModelEnabled, setLocalModelEnabled] = useState(false)
|
||||
|
||||
const form = useForm<ApiKeyFormValues>({
|
||||
resolver: zodResolver(apiKeySchema),
|
||||
@@ -47,34 +45,6 @@ export default function Settings() {
|
||||
},
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (user?.is_superuser) {
|
||||
fetchSystemSettings()
|
||||
}
|
||||
}, [user])
|
||||
|
||||
const fetchSystemSettings = async () => {
|
||||
try {
|
||||
const settings = await authApi.getSystemSettings()
|
||||
setLocalModelEnabled(settings.local_model_enabled)
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch system settings:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const handleToggleLocalModel = async (enabled: boolean) => {
|
||||
try {
|
||||
await authApi.updateSystemSettings({ local_model_enabled: enabled })
|
||||
setLocalModelEnabled(enabled)
|
||||
toast.success(`本地模型已${enabled ? '启用' : '禁用'}`)
|
||||
|
||||
await refetchPreferences()
|
||||
} catch (error) {
|
||||
toast.error('更新失败,请重试')
|
||||
console.error('Failed to update system settings:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const handleBackendChange = async (value: string) => {
|
||||
try {
|
||||
await updatePreferences({ default_backend: value as 'local' | 'aliyun' })
|
||||
@@ -182,8 +152,10 @@ export default function Settings() {
|
||||
<Label htmlFor="backend-local" className="flex-1 cursor-pointer">
|
||||
<div className="font-medium text-sm sm:text-base">本地模型</div>
|
||||
<div className="text-xs sm:text-sm text-muted-foreground">
|
||||
免费使用本地 Qwen3-TTS 模型
|
||||
{!isBackendAvailable('local') && ' (管理员未启用)'}
|
||||
{!isBackendAvailable('local')
|
||||
? '请联系管理员开启使用本地模型权限'
|
||||
: '免费使用本地 Qwen3-TTS 模型'
|
||||
}
|
||||
</div>
|
||||
</Label>
|
||||
</div>
|
||||
@@ -291,33 +263,6 @@ export default function Settings() {
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{user.is_superuser && (
|
||||
<Card>
|
||||
<CardHeader className="p-4 sm:p-6">
|
||||
<CardTitle className="text-lg sm:text-xl">系统设置</CardTitle>
|
||||
<CardDescription className="text-sm">管理全局系统设置(仅管理员可见)</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="p-4 sm:p-6">
|
||||
<div className="space-y-3 sm:space-y-4">
|
||||
<div className="flex items-start sm:items-center justify-between gap-4">
|
||||
<div className="space-y-0.5 flex-1">
|
||||
<Label htmlFor="local-model-toggle" className="text-sm sm:text-base">启用本地模型</Label>
|
||||
<p className="text-xs sm:text-sm text-muted-foreground">
|
||||
允许普通用户在设置中选择并使用本地 Qwen3-TTS 模型
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
id="local-model-toggle"
|
||||
checked={localModelEnabled}
|
||||
onCheckedChange={handleToggleLocalModel}
|
||||
className="shrink-0"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
<Card>
|
||||
<CardHeader className="p-4 sm:p-6">
|
||||
<CardTitle className="text-lg sm:text-xl">账户信息</CardTitle>
|
||||
|
||||
@@ -4,6 +4,7 @@ export interface User {
|
||||
email: string
|
||||
is_active: boolean
|
||||
is_superuser: boolean
|
||||
can_use_local_model: boolean
|
||||
created_at: string
|
||||
}
|
||||
|
||||
@@ -35,7 +36,3 @@ export interface UserPreferences {
|
||||
onboarding_completed: boolean
|
||||
available_backends?: string[]
|
||||
}
|
||||
|
||||
export interface SystemSettings {
|
||||
local_model_enabled: boolean
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ export interface UserCreateRequest {
|
||||
password: string
|
||||
is_active: boolean
|
||||
is_superuser: boolean
|
||||
can_use_local_model: boolean
|
||||
}
|
||||
|
||||
export interface UserUpdateRequest {
|
||||
@@ -14,6 +15,7 @@ export interface UserUpdateRequest {
|
||||
password?: string
|
||||
is_active?: boolean
|
||||
is_superuser?: boolean
|
||||
can_use_local_model?: boolean
|
||||
}
|
||||
|
||||
export interface UserListResponse {
|
||||
|
||||
Reference in New Issue
Block a user