From 3782ec8ca0a5be8a1bf96ab30ae98b9c748163a8 Mon Sep 17 00:00:00 2001 From: wood chen Date: Thu, 20 Feb 2025 02:39:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0"=E6=8E=88=E6=9D=83=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E9=A1=B5=E9=9D=A2"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/(admin)/admin/authorizations/page.tsx | 163 ++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 src/app/(admin)/admin/authorizations/page.tsx diff --git a/src/app/(admin)/admin/authorizations/page.tsx b/src/app/(admin)/admin/authorizations/page.tsx new file mode 100644 index 0000000..8bfdac2 --- /dev/null +++ b/src/app/(admin)/admin/authorizations/page.tsx @@ -0,0 +1,163 @@ +import { redirect } from "next/navigation"; +import { Search } from "lucide-react"; + +import { prisma } from "@/lib/prisma"; +import { getCurrentUser } from "@/lib/session"; +import { Badge } from "@/components/ui/badge"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@/components/ui/card"; +import { Input } from "@/components/ui/input"; +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@/components/ui/table"; +import { AuthorizationStatusToggle } from "@/components/admin/authorization-status-toggle"; + +async function getAuthorizations(search?: string) { + const where = search + ? { + OR: [ + { + user: { + OR: [ + { username: { contains: search } }, + { email: { contains: search } }, + ], + }, + }, + { + client: { + OR: [ + { name: { contains: search } }, + { clientId: { contains: search } }, + ], + }, + }, + ], + } + : {}; + + return prisma.authorization.findMany({ + where, + include: { + user: { + select: { + username: true, + email: true, + name: true, + }, + }, + client: { + select: { + name: true, + clientId: true, + }, + }, + }, + orderBy: { + createdAt: "desc", + }, + }); +} + +export default async function AuthorizationsPage({ + searchParams, +}: { + searchParams: { search?: string }; +}) { + const user = await getCurrentUser(); + if (!user || user.role !== "ADMIN") { + redirect("/dashboard"); + } + + const authorizations = await getAuthorizations(searchParams.search); + + return ( +
+ + +
+
+ 授权管理 + 管理所有用户的授权记录 +
+
+ +
+ +
+
+
+
+ + + + + 用户 + 应用 + 授权时间 + 最后使用 + 状态 + 操作 + + + + {authorizations.map((auth) => ( + + +
+

+ {auth.user.name || auth.user.username} +

+

+ {auth.user.email} +

+
+
+ +
+

{auth.client.name}

+

+ {auth.client.clientId} +

+
+
+ + {new Date(auth.createdAt).toLocaleString()} + + + {auth.lastUsedAt + ? new Date(auth.lastUsedAt).toLocaleString() + : "从未使用"} + + + + {auth.enabled ? "已授权" : "已禁用"} + + + + + +
+ ))} +
+
+
+
+
+ ); +}