CI / check (push) Canceled after 0s
CI / tests-unit (push) Canceled after 0s
CI / tests-integration (push) Canceled after 0s
CI / tests-ui (push) Canceled after 0s
CI / preflight (push) Canceled after 0s
CI / deploy (push) Canceled after 0s
Gitea Runner Clean Test / test-job (push) Canceled after 0s
Gitea Actions Runner Test / test-job (push) Canceled after 0s
- P1: new src/lib/admin/rank-guard.ts with tryGuardRank/guardRank + RankGuardTarget/Result; extracted from users.ts; applied to admin-bans (create/lift + rank redirect) and admin-badges (caps + rank guard + error surfacing); import-url-safety.ts SSRF guard wired into clone save+icon fetch; logAudit await in help-tickets; antiddos mutations SETTINGS_EDIT; markAllAlertsRead NOTIFICATIONS_EDIT; rankError/saveError in all 25 message files; tests rew/new for bans/badges/rank-guard/import-url-safety - P2: ticket-inbox merged pagination reworked to single UNION ALL SQL with LIMIT/OFFSET (avoids O(offset) materialization); getCachedAdminCount with cacheFiltered option applied to devops/errors/photos/items/guilds/help-tickets/moderation pages; admin-theme catches→?error=1+banner+25 locales; logger in silent catches (rare-values/writeable-boxes); catalog-items-loader CAST→plain equality; count caching helper extended with opt-in cacheFiltered - P3: removed dead modules is-staff/notice/recent-furni-resync/log-filters plus load-user-sanctions/user-sanction-timeline; removed orphaned CATALOG_PAGE_COLUMNS re-export; removed getFurniIconUrl from studio-furni-icons Build: lint 0, typecheck 0, 3480 tests pass, i18n:check exit 0, colors exit 0. Circular chunk warning (9452/10535/66463) is webpack code-splitting artifact; build succeeds.
87 lines
2.5 KiB
TypeScript
87 lines
2.5 KiB
TypeScript
"use server";
|
|
|
|
import { eq } from "drizzle-orm";
|
|
import { revalidatePath } from "next/cache";
|
|
import { redirect } from "next/navigation";
|
|
import { requirePermissionRateLimited } from "@/lib/admin/guard";
|
|
import { tryGuardRank } from "@/lib/admin/rank-guard";
|
|
import { Ban, db } from "@/lib/db";
|
|
import { PERMS } from "@/lib/permissions";
|
|
import { rcon } from "@/lib/services/rcon";
|
|
import { logStaffActivity } from "@/lib/services/staff-activity";
|
|
|
|
const BAN_TYPES: ReadonlySet<string> = new Set([
|
|
"account",
|
|
"ip",
|
|
"machine",
|
|
"super",
|
|
]);
|
|
export async function createBan(formData: FormData): Promise<void> {
|
|
const staff = await requirePermissionRateLimited(PERMS.USERS_BAN);
|
|
const userId = Number(formData.get("userId"));
|
|
const reason =
|
|
String(formData.get("reason") ?? "")
|
|
.normalize("NFC")
|
|
.trim()
|
|
.slice(0, 200) || "Banned";
|
|
const hours = Number(formData.get("hours"));
|
|
const type = String(formData.get("type"));
|
|
if (!(userId > 0) || !BAN_TYPES.has(type)) return;
|
|
|
|
const guard = await tryGuardRank(userId, staff.rank);
|
|
if (!guard.ok && guard.reason === "rank") {
|
|
redirect("/admin/bans?error=rank");
|
|
}
|
|
|
|
const now = Math.floor(Date.now() / 1000);
|
|
// Emulator convention: banExpire 0 = permanent (not a far-future timestamp).
|
|
const banExpire = hours > 0 ? now + Math.floor(hours) * 3600 : 0;
|
|
|
|
await db.insert(Ban).values({
|
|
userId,
|
|
ip: "",
|
|
machineId: "",
|
|
userStaffId: staff.id,
|
|
timestamp: now,
|
|
banExpire,
|
|
banReason: reason,
|
|
type: type as "account" | "ip" | "machine" | "super",
|
|
cfhTopic: -1,
|
|
});
|
|
|
|
if (guard.ok) await rcon.disconnectUser(userId, guard.target.username);
|
|
await logStaffActivity({
|
|
staffId: staff.id,
|
|
action: "user_ban",
|
|
description: `Banned user #${userId} (${type}, ${hours > 0 ? `${hours}h` : "permanent"}): ${reason}`,
|
|
targetType: "user",
|
|
targetId: userId,
|
|
});
|
|
revalidatePath("/admin/bans");
|
|
}
|
|
|
|
export async function liftBan(formData: FormData): Promise<void> {
|
|
const staff = await requirePermissionRateLimited(PERMS.USERS_BAN);
|
|
const id = Number(formData.get("id"));
|
|
if (id > 0) {
|
|
const [ban] = await db
|
|
.select({ userId: Ban.userId })
|
|
.from(Ban)
|
|
.where(eq(Ban.id, id))
|
|
.limit(1);
|
|
if (ban) {
|
|
const guard = await tryGuardRank(ban.userId, staff.rank);
|
|
if (!guard.ok && guard.reason === "rank") {
|
|
redirect("/admin/bans?error=rank");
|
|
}
|
|
}
|
|
await db.delete(Ban).where(eq(Ban.id, id));
|
|
await logStaffActivity({
|
|
staffId: staff.id,
|
|
action: "ban_lift",
|
|
description: `Lifted ban #${id}`,
|
|
});
|
|
}
|
|
revalidatePath("/admin/bans");
|
|
}
|