a414f03a59
- Configure tailscale serve automatically for each instance on Windows userspace networking. - Add local UI buttons: start/stop/reset/delete instances (stop/start preserve volumes). - Clean shutdown: stop tailscaled and instances, notify server with instance_stopped. - Restart tailscaled on agent boot using persisted state when pre-auth key is absent. - Sync instance stopped/deleted status to dashboard (server/lib/websocket.ts). - Security: include prior authz/scoping changes across API routes, ephemeral pre-auth keys, ACL policy, internal API key. - Update SUIVI_VPN_ONDEMAND.md and docs/ONBOARDING_CLIENT.md. - Bump agent version to 0.3.5.
57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
"use server";
|
|
|
|
import { prisma } from "@/lib/prisma";
|
|
import { getServerSession } from "next-auth/next";
|
|
import { authOptions } from "@/lib/auth-config";
|
|
import { generateUniqueActivationCode } from "@/lib/activation";
|
|
import { redirect } from "next/navigation";
|
|
|
|
export async function deleteStudent(formData: FormData) {
|
|
const session = await getServerSession(authOptions);
|
|
if (!session?.user) redirect("/login");
|
|
if (!session.user.establishmentId && session.user.role !== "superadmin") redirect("/dashboard");
|
|
|
|
const id = formData.get("id") as string;
|
|
if (!id) return;
|
|
|
|
const establishmentId = session.user.establishmentId;
|
|
const student = await prisma.student.findFirst({
|
|
where: {
|
|
id,
|
|
class: establishmentId ? { establishmentId } : undefined,
|
|
},
|
|
});
|
|
if (!student) return;
|
|
|
|
await prisma.student.delete({ where: { id } });
|
|
|
|
redirect("/dashboard/students");
|
|
}
|
|
|
|
export async function generateActivationCodeAction(formData: FormData) {
|
|
const session = await getServerSession(authOptions);
|
|
if (!session?.user) redirect("/login");
|
|
if (!session.user.establishmentId && session.user.role !== "superadmin") redirect("/dashboard");
|
|
|
|
const id = formData.get("id") as string;
|
|
if (!id) return;
|
|
|
|
const establishmentId = session.user.establishmentId;
|
|
const student = await prisma.student.findFirst({
|
|
where: {
|
|
id,
|
|
class: establishmentId ? { establishmentId } : undefined,
|
|
},
|
|
});
|
|
|
|
if (!student) return;
|
|
|
|
const { code, expiresAt } = await generateUniqueActivationCode();
|
|
await prisma.student.update({
|
|
where: { id },
|
|
data: { activationCode: code, activationCodeExpiresAt: expiresAt },
|
|
});
|
|
|
|
redirect(`/dashboard/students/${id}`);
|
|
}
|