first commit
This commit is contained in:
18
app/api/domains/[domain]/route.ts
Normal file
18
app/api/domains/[domain]/route.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { auth } from "@/auth";
|
||||
import { deleteDomain } from "@/lib/mailcow";
|
||||
|
||||
// DELETE /api/domains/[domain] — super admin only
|
||||
export async function DELETE(
|
||||
_req: NextRequest,
|
||||
{ params }: { params: Promise<{ domain: string }> }
|
||||
) {
|
||||
const session = await auth();
|
||||
if (!session || session.user.role !== "SUPER_ADMIN") {
|
||||
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
||||
}
|
||||
|
||||
const { domain } = await params;
|
||||
const result = await deleteDomain(decodeURIComponent(domain));
|
||||
return NextResponse.json(result.data, { status: result.ok ? 200 : 502 });
|
||||
}
|
||||
34
app/api/domains/route.ts
Normal file
34
app/api/domains/route.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { auth } from "@/auth";
|
||||
import { getDomains, createDomain } from "@/lib/mailcow";
|
||||
import { canAccessDomain } from "@/lib/users";
|
||||
|
||||
// GET /api/domains — list domains (filtered by session)
|
||||
export async function GET() {
|
||||
const session = await auth();
|
||||
if (!session) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
|
||||
const allDomains = await getDomains();
|
||||
const userDomains = session.user.domains ?? [];
|
||||
|
||||
// Super admin sees all, domain admin only sees their domains
|
||||
const visible = allDomains.filter((d) => canAccessDomain(userDomains, d.domain_name));
|
||||
|
||||
return NextResponse.json(visible);
|
||||
}
|
||||
|
||||
// POST /api/domains — create domain (super admin only)
|
||||
export async function POST(req: NextRequest) {
|
||||
const session = await auth();
|
||||
if (!session || session.user.role !== "SUPER_ADMIN") {
|
||||
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
||||
}
|
||||
|
||||
const body = await req.json();
|
||||
const { domain, description, mailboxes, quota, maxquota } = body;
|
||||
|
||||
if (!domain) return NextResponse.json({ error: "domain gerekli" }, { status: 400 });
|
||||
|
||||
const result = await createDomain({ domain, description, mailboxes, quota, maxquota });
|
||||
return NextResponse.json(result.data, { status: result.ok ? 200 : 502 });
|
||||
}
|
||||
Reference in New Issue
Block a user