User Role (#69)

* fix: window.DisableAnimatedMan as boolean

* chore: auto-fix linting and formatting issues

* feat: user role

* feat: use user agent_secret

* feat: hide setting when user role is not admin

* feat: new waf api

* chore: auto-fix linting and formatting issues

* fix: admin settings page

* feat: online-user setting

* fix: pagination

---------

Co-authored-by: hamster1963 <hamster1963@users.noreply.github.com>
This commit is contained in:
仓鼠
2024-12-22 23:17:20 +08:00
committed by GitHub
co-authored by hamster1963
parent 5ad915c973
commit 7fdac38291
15 changed files with 703 additions and 36 deletions
+15 -2
View File
@@ -21,6 +21,7 @@ import {
SelectValue,
} from "@/components/ui/select"
import { Textarea } from "@/components/ui/textarea"
import { useAuth } from "@/hooks/useAuth"
import useSetting from "@/hooks/useSetting"
import { asOptionalField } from "@/lib/utils"
import { nezhaLang, settingCoverageTypes } from "@/types"
@@ -28,6 +29,7 @@ import { zodResolver } from "@hookform/resolvers/zod"
import { useEffect } from "react"
import { useForm } from "react-hook-form"
import { useTranslation } from "react-i18next"
import { useNavigate } from "react-router-dom"
import { toast } from "sonner"
import { z } from "zod"
@@ -52,6 +54,17 @@ const settingFormSchema = z.object({
export default function SettingsPage() {
const { t, i18n } = useTranslation()
const { data: config, mutate } = useSetting()
const { profile } = useAuth()
const navigate = useNavigate()
const isAdmin = profile?.role === 0
console.log(isAdmin)
if (!isAdmin) {
console.log("redirect")
navigate("/dashboard/settings/waf")
}
const form = useForm<z.infer<typeof settingFormSchema>>({
resolver: zodResolver(settingFormSchema),
@@ -62,7 +75,7 @@ export default function SettingsPage() {
site_name: config.site_name || "",
user_template:
config.user_template ||
Object.keys(config.frontend_templates.filter((t) => !t.is_admin) || {})[0] ||
Object.keys(config.frontend_templates?.filter((t) => !t.is_admin) || {})[0] ||
"user-dist",
}
: {
@@ -173,7 +186,7 @@ export default function SettingsPage() {
</FormControl>
<SelectContent>
{(
config?.frontend_templates.filter(
config?.frontend_templates?.filter(
(t) => !t.is_admin,
) || []
).map((template) => (