fix(customers): 业务员角色隐藏商户导出功能

前端隐藏导出按钮,并在导出接口校验超管权限,防止绕过。
This commit is contained in:
2026-07-13 17:48:22 +08:00
parent 2c1612544b
commit c54ec4355d
3 changed files with 19 additions and 7 deletions
@@ -15,11 +15,14 @@ export function CustomerToolbar({
defaultStart, defaultStart,
defaultEnd, defaultEnd,
exportHref, exportHref,
canExport = true,
}: { }: {
defaultKeyword?: string; defaultKeyword?: string;
defaultStart?: string; defaultStart?: string;
defaultEnd?: string; defaultEnd?: string;
exportHref: string; exportHref: string;
/** 业务员角色不展示导出 */
canExport?: boolean;
}) { }) {
const router = useRouter(); const router = useRouter();
const fileRef = useRef<HTMLInputElement>(null); const fileRef = useRef<HTMLInputElement>(null);
@@ -109,12 +112,14 @@ export function CustomerToolbar({
下载模板 下载模板
</Button> </Button>
</a> </a>
<a href={exportHref}> {canExport && (
<Button variant="outline"> <a href={exportHref}>
<Download className="h-4 w-4" /> <Button variant="outline">
导出 <Download className="h-4 w-4" />
</Button> 导出
</a> </Button>
</a>
)}
<Link href="/customers/new"> <Link href="/customers/new">
<Button> <Button>
<Plus className="h-4 w-4" /> <Plus className="h-4 w-4" />
@@ -2,13 +2,19 @@ import { NextRequest, NextResponse } from "next/server";
import * as XLSX from "xlsx"; import * as XLSX from "xlsx";
import { prisma } from "@/lib/prisma"; import { prisma } from "@/lib/prisma";
import { auth } from "@/lib/auth"; import { auth } from "@/lib/auth";
import { isSuperAdmin } from "@/lib/acl";
import { fmtDate } from "@/lib/utils"; import { fmtDate } from "@/lib/utils";
import { buildCustomerWhere, EXCEL_COLUMNS } from "../query"; import { buildCustomerWhere, EXCEL_COLUMNS } from "../query";
export async function GET(req: NextRequest) { export async function GET(req: NextRequest) {
if (!(await auth())) { const session = await auth();
if (!session) {
return NextResponse.json({ error: "未登录" }, { status: 401 }); return NextResponse.json({ error: "未登录" }, { status: 401 });
} }
// 业务员不可导出
if (!isSuperAdmin(session.user?.roles)) {
return NextResponse.json({ error: "无权限" }, { status: 403 });
}
const sp = req.nextUrl.searchParams; const sp = req.nextUrl.searchParams;
const where = buildCustomerWhere({ const where = buildCustomerWhere({
+1
View File
@@ -56,6 +56,7 @@ export default async function CustomersPage({
defaultStart={sp.start} defaultStart={sp.start}
defaultEnd={sp.end} defaultEnd={sp.end}
exportHref={`/customers/export?${exportQs.toString()}`} exportHref={`/customers/export?${exportQs.toString()}`}
canExport={superAdmin}
/> />
<Card className="overflow-hidden"> <Card className="overflow-hidden">