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