08b6e58b8e
Deploy Vault CMS / deploy (push) Successful in 2m23s
- Upgrade next 16.0.3 -> 16.3.5 and react/react-dom 19.2.0 -> 19.3.0 (CVE-2025-55182 / CVE-2025-66478 unauthenticated RCE), next-auth -> 4.24.15 - Require admin role on /api/users, /api/courses and /api/enrollments, which were unauthenticated - Replace ALLOWED_ADMINS checks that allowed any signed-in user when the variable was empty with the role-based requireAdmin - Sanitize upload filenames, restrict thumbnail extensions, store edited thumbnails in UPLOADS_DIR, tighten traversal checks in file routes - Dockerfile: Node 22, pinned pnpm, non-root user, critical audit gate - Compose: read-only rootfs, dropped caps, no-new-privileges, Postgres password from env - Exclude .env from Docker build context; add security headers - Deploy with git reset --hard instead of git pull - Remove stale package-lock.json Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
101 lines
3.2 KiB
TypeScript
101 lines
3.2 KiB
TypeScript
// app/api/admin/manage-playlist-courses/route.ts
|
|
// Assign or remove a playlist from additional courses
|
|
import { NextResponse } from 'next/server';
|
|
import { prisma } from '@/lib/prisma';
|
|
import { requireAdmin } from '@/lib/admin-check';
|
|
|
|
// GET: Get all courses a playlist is assigned to
|
|
export async function GET(req: Request) {
|
|
try {
|
|
await requireAdmin();
|
|
const { searchParams } = new URL(req.url);
|
|
const playlistId = searchParams.get('playlistId');
|
|
|
|
if (!playlistId) return NextResponse.json({ error: 'playlistId required' }, { status: 400 });
|
|
|
|
const playlist = await prisma.playlist.findUnique({
|
|
where: { id: playlistId },
|
|
include: {
|
|
course: true,
|
|
courses: {
|
|
include: { course: true },
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!playlist) return NextResponse.json({ error: 'Playlist not found' }, { status: 404 });
|
|
|
|
// Return primary course + all additional courses
|
|
const allCourses = [
|
|
playlist.course,
|
|
...playlist.courses.map(cp => cp.course),
|
|
];
|
|
|
|
return NextResponse.json({ playlist, allCourses });
|
|
} catch (err: any) {
|
|
console.error(err);
|
|
return NextResponse.json({ error: err?.message ?? 'server' }, { status: err?.status ?? 500 });
|
|
}
|
|
}
|
|
|
|
// POST: Assign playlist to an additional course
|
|
export async function POST(req: Request) {
|
|
try {
|
|
await requireAdmin();
|
|
const { playlistId, courseId } = await req.json();
|
|
|
|
if (!playlistId || !courseId) return NextResponse.json({ error: 'missing fields' }, { status: 400 });
|
|
|
|
// Check if already assigned
|
|
const existing = await prisma.coursePlaylist.findFirst({
|
|
where: { playlistId, courseId },
|
|
});
|
|
|
|
if (existing) return NextResponse.json({ error: 'Already assigned' }, { status: 400 });
|
|
|
|
const assignment = await prisma.coursePlaylist.create({
|
|
data: { playlistId, courseId },
|
|
include: { course: true },
|
|
});
|
|
|
|
return NextResponse.json({ assignment });
|
|
} catch (err: any) {
|
|
console.error(err);
|
|
return NextResponse.json({ error: err?.message ?? 'server' }, { status: err?.status ?? 500 });
|
|
}
|
|
}
|
|
|
|
// DELETE: Remove playlist from a course
|
|
export async function DELETE(req: Request) {
|
|
try {
|
|
await requireAdmin();
|
|
const { searchParams } = new URL(req.url);
|
|
const playlistId = searchParams.get('playlistId');
|
|
const courseId = searchParams.get('courseId');
|
|
|
|
if (!playlistId || !courseId) return NextResponse.json({ error: 'missing fields' }, { status: 400 });
|
|
|
|
// Don't allow deleting the primary course assignment
|
|
const playlist = await prisma.playlist.findUnique({
|
|
where: { id: playlistId },
|
|
});
|
|
|
|
if (!playlist) return NextResponse.json({ error: 'Playlist not found' }, { status: 404 });
|
|
|
|
if (playlist.courseId === courseId) {
|
|
return NextResponse.json({ error: 'Cannot remove primary course' }, { status: 400 });
|
|
}
|
|
|
|
await prisma.coursePlaylist.delete({
|
|
where: {
|
|
courseId_playlistId: { playlistId, courseId },
|
|
},
|
|
});
|
|
|
|
return NextResponse.json({ success: true });
|
|
} catch (err: any) {
|
|
console.error(err);
|
|
return NextResponse.json({ error: err?.message ?? 'server' }, { status: err?.status ?? 500 });
|
|
}
|
|
}
|