Files
dataroom/features/access-notifications/lib/report-denied-access-attempt.ts
zeekay 98f0da7fa5 ci: amd64-only build (matches hanzo runner pool topology)
hanzo-build-linux-amd64 is the only ARC runner pool installed on
hanzo-k8s today (arm64 pool is paused until DigitalOcean ships
arm64 droplets, per ~/work/hanzo/.github/RUNNERS.md). The arm64
job was waiting on spark-hanzoai-arm64 — not provisioned in this
cluster — so every build sat in queue forever and the amd64 leg
got cancelled.

Set platforms: linux/amd64 on the reusable build call to skip
arm64 entirely. Re-add arm64 if/when DO ships arm64 droplets and
the spark runner pool comes back online.
2026-06-07 11:38:49 -07:00

85 lines
2.3 KiB
TypeScript

import { Link } from "@prisma/client";
import prisma from "@/lib/prisma";
import { sendBlockedEmailAttemptNotification } from "./send-blocked-email-attempt";
export async function reportDeniedAccessAttempt(
link: Partial<Link>,
email: string,
accessType: "global" | "allow" | "deny" = "global",
) {
if (!link || !link.teamId) return;
// Get all admin and manager emails
const users = await prisma.userTeam.findMany({
where: {
role: { in: ["ADMIN", "MANAGER"] },
status: "ACTIVE",
teamId: link.teamId,
},
select: {
user: { select: { email: true } },
},
});
const adminManagerEmails = users
.map((u) => u.user?.email)
.filter((e): e is string => !!e);
// Get resource info and owner email
let resourceType: "dataroom" | "document" = "dataroom";
let resourceName = "Dataroom";
let ownerEmail: string | undefined;
if (link.documentId) {
resourceType = "document";
const document = await prisma.document.findUnique({
where: { id: link.documentId },
select: { name: true, ownerId: true },
});
resourceName = document?.name || "Document";
if (document?.ownerId) {
const owner = await prisma.userTeam.findUnique({
where: {
userId_teamId: {
userId: document.ownerId,
teamId: link.teamId,
},
status: "ACTIVE",
},
select: { user: { select: { email: true } } },
});
ownerEmail = owner?.user?.email || undefined;
}
} else if (link.dataroomId) {
const dataroom = await prisma.dataroom.findUnique({
where: { id: link.dataroomId },
select: { name: true },
});
resourceName = dataroom?.name || "Dataroom";
}
// Combine all recipients and remove duplicates
const allRecipients = [...adminManagerEmails];
if (ownerEmail && !allRecipients.includes(ownerEmail)) {
allRecipients.push(ownerEmail);
}
// Send email to all recipients
if (allRecipients.length > 0) {
const [to, ...cc] = allRecipients;
await sendBlockedEmailAttemptNotification({
to,
cc: cc.length > 0 ? cc : undefined,
blockedEmail: email,
linkName: link.name || `Link #${link.id?.slice(-5)}`,
resourceName,
resourceType,
timestamp: new Date().toLocaleString(),
accessType,
});
}
}