Local Build and Deploy / deploy (push) Successful in 56s
Replace leftover requireStaff gates with module PERMS, drop hardcoded room rank thresholds, and expand contract tests so admin mutations cannot regress to dashboard-only checks. Co-authored-by: Cursor <[email protected]>
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
"use server";
|
|
|
|
import { revalidatePath } from "next/cache";
|
|
import { requirePermission } from "@/lib/admin/guard";
|
|
import { PERMS } from "@/lib/permissions";
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
function parseIp(formData: FormData): string {
|
|
return String(formData.get("ipAddress") ?? "")
|
|
.normalize("NFC")
|
|
.trim()
|
|
.slice(0, 255);
|
|
}
|
|
|
|
function parseAsn(formData: FormData): string | null {
|
|
const asn = String(formData.get("asn") ?? "")
|
|
.normalize("NFC")
|
|
.trim()
|
|
.slice(0, 255);
|
|
return asn || null;
|
|
}
|
|
|
|
export async function addWhitelist(formData: FormData): Promise<void> {
|
|
await requirePermission(PERMS.SETTINGS_EDIT);
|
|
const ipAddress = parseIp(formData);
|
|
if (!ipAddress) return;
|
|
const asn = parseAsn(formData);
|
|
await prisma.websiteIpWhitelist.create({
|
|
data: { ipAddress, asn, whitelistAsn: asn != null },
|
|
});
|
|
revalidatePath("/admin/ip");
|
|
}
|
|
|
|
export async function deleteWhitelist(formData: FormData): Promise<void> {
|
|
await requirePermission(PERMS.SETTINGS_EDIT);
|
|
const raw = String(formData.get("id") ?? "")
|
|
.normalize("NFC")
|
|
.trim();
|
|
if (!raw) return;
|
|
await prisma.websiteIpWhitelist.delete({ where: { id: BigInt(raw) } });
|
|
revalidatePath("/admin/ip");
|
|
}
|
|
|
|
export async function addBlacklist(formData: FormData): Promise<void> {
|
|
await requirePermission(PERMS.SETTINGS_EDIT);
|
|
const ipAddress = parseIp(formData);
|
|
if (!ipAddress) return;
|
|
const asn = parseAsn(formData);
|
|
await prisma.websiteIpBlacklist.create({
|
|
data: { ipAddress, asn, blacklistAsn: asn != null },
|
|
});
|
|
revalidatePath("/admin/ip");
|
|
}
|
|
|
|
export async function deleteBlacklist(formData: FormData): Promise<void> {
|
|
await requirePermission(PERMS.SETTINGS_EDIT);
|
|
const raw = String(formData.get("id") ?? "")
|
|
.normalize("NFC")
|
|
.trim();
|
|
if (!raw) return;
|
|
await prisma.websiteIpBlacklist.delete({ where: { id: BigInt(raw) } });
|
|
revalidatePath("/admin/ip");
|
|
}
|