Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+31
@@ -0,0 +1,31 @@
|
||||
// @vitest-environment node
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("~/services/admin/admin-identity.server", () => ({
|
||||
requireAdminIdentityPermission: vi.fn(),
|
||||
}));
|
||||
|
||||
import { requireAdminIdentityPermission } from "~/services/admin/admin-identity.server";
|
||||
import { loader } from "./dialer";
|
||||
|
||||
describe("admin telephony dialer route", () => {
|
||||
it("keeps the dedicated dialer URL permission-gated and reachable", async () => {
|
||||
const request = new Request(
|
||||
"https://admin.hivegrid.de/sales/calls/dialer"
|
||||
);
|
||||
const response = await loader({
|
||||
request,
|
||||
params: {},
|
||||
context: {},
|
||||
} as never);
|
||||
|
||||
expect(requireAdminIdentityPermission).toHaveBeenCalledWith(
|
||||
request,
|
||||
"admin_sales.phone.call"
|
||||
);
|
||||
expect(response.status).toBe(302);
|
||||
expect(response.headers.get("location")).toBe(
|
||||
"https://admin.hivegrid.de/sales/calls#dialer"
|
||||
);
|
||||
});
|
||||
});
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
import type { LoaderFunctionArgs } from "react-router";
|
||||
|
||||
import { requireAdminIdentityPermission } from "~/services/admin/admin-identity.server";
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
|
||||
export async function loader({ request }: LoaderFunctionArgs) {
|
||||
await requireAdminIdentityPermission(request, "admin_sales.phone.call");
|
||||
return Response.redirect(
|
||||
new URL(
|
||||
`${adminPath("sales/calls", { mode: "host-aware" })}#dialer`,
|
||||
request.url
|
||||
),
|
||||
302
|
||||
);
|
||||
}
|
||||
|
||||
export default function AdminTelephonyDialerRoute(): null {
|
||||
return null;
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
// @vitest-environment node
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
getPlayback: vi.fn(),
|
||||
readPlayback: vi.fn(),
|
||||
writeAudit: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("@hivegrid/db/admin-telephony-recordings.server", () => ({
|
||||
getAdminCallRecordingPlayback: mocks.getPlayback,
|
||||
}));
|
||||
vi.mock("@hivegrid/db/admin-sales-core.server", () => ({
|
||||
writeAdminSalesAudit: mocks.writeAudit,
|
||||
}));
|
||||
vi.mock("~/services/admin/admin-telephony-recording-playback.server", () => ({
|
||||
readAdminCallRecordingPlayback: mocks.readPlayback,
|
||||
}));
|
||||
vi.mock("~/services/admin/admin-telephony-connections.server", () => ({
|
||||
runAsAdminTelephonyOperator: async (
|
||||
_request: Request,
|
||||
permission: readonly string[],
|
||||
operation: (context: unknown) => Promise<unknown>
|
||||
) => {
|
||||
expect(permission).toEqual([
|
||||
"admin_sales.phone.recording",
|
||||
"admin_sales.communication.read_all",
|
||||
]);
|
||||
return operation({
|
||||
adminUserId: "admin_1",
|
||||
canReadAllCommunication: false,
|
||||
actor: (reason: string) => ({
|
||||
adminUserId: "admin_1",
|
||||
email: "admin@example.test",
|
||||
reason,
|
||||
}),
|
||||
});
|
||||
},
|
||||
}));
|
||||
vi.mock("~/utils/db.server", () => ({ db: { marker: "db" } }));
|
||||
|
||||
import { loader } from "./$recordingId";
|
||||
|
||||
describe("admin call recording route", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
mocks.getPlayback.mockResolvedValue({
|
||||
id: "recording_1",
|
||||
adminUserId: "admin_1",
|
||||
callSessionId: "call_1",
|
||||
});
|
||||
mocks.readPlayback.mockResolvedValue(
|
||||
Uint8Array.from(Buffer.from("audio"))
|
||||
);
|
||||
mocks.writeAudit.mockResolvedValue(undefined);
|
||||
});
|
||||
|
||||
it("returns a no-store audio response and audits successful playback", async () => {
|
||||
const response = await loader({
|
||||
request: new Request(
|
||||
"http://admin.localhost:3000/sales/calls/recordings/recording_1"
|
||||
),
|
||||
params: { recordingId: "recording_1" },
|
||||
context: {},
|
||||
} as never);
|
||||
|
||||
expect(response).toBeInstanceOf(Response);
|
||||
expect((response as Response).headers.get("cache-control")).toBe(
|
||||
"private, no-store"
|
||||
);
|
||||
expect((response as Response).headers.get("content-type")).toBe(
|
||||
"audio/mpeg"
|
||||
);
|
||||
expect(await (response as Response).text()).toBe("audio");
|
||||
expect(mocks.writeAudit).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
expect.objectContaining({
|
||||
action: "admin.sales.telephony.recording.played",
|
||||
targetId: "recording_1",
|
||||
after: expect.objectContaining({
|
||||
dataOwnerAdminUserId: "admin_1",
|
||||
foreignAccess: false,
|
||||
}),
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("returns 404 when no clean owner-bound recording exists", async () => {
|
||||
mocks.getPlayback.mockResolvedValue(null);
|
||||
await expect(
|
||||
loader({
|
||||
request: new Request(
|
||||
"http://admin.localhost:3000/sales/calls/recordings/missing"
|
||||
),
|
||||
params: { recordingId: "missing" },
|
||||
context: {},
|
||||
} as never)
|
||||
).rejects.toMatchObject({ status: 404 });
|
||||
expect(mocks.readPlayback).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
import {
|
||||
getAdminCallRecordingPlayback,
|
||||
} from "@hivegrid/db/admin-telephony-recordings.server";
|
||||
import { writeAdminSalesAudit } from "@hivegrid/db/admin-sales-core.server";
|
||||
import type { LoaderFunctionArgs } from "react-router";
|
||||
|
||||
import { runAsAdminTelephonyOperator } from "~/services/admin/admin-telephony-connections.server";
|
||||
import { readAdminCallRecordingPlayback } from "~/services/admin/admin-telephony-recording-playback.server";
|
||||
import { db } from "~/utils/db.server";
|
||||
import { NOT_FOUND_ENVELOPE } from "~/utils/errors.server";
|
||||
|
||||
export async function loader({ params, request }: LoaderFunctionArgs) {
|
||||
const recordingId = params.recordingId;
|
||||
if (!recordingId) {
|
||||
throw Response.json(NOT_FOUND_ENVELOPE, { status: 404 });
|
||||
}
|
||||
try {
|
||||
return await runAsAdminTelephonyOperator(
|
||||
request,
|
||||
[
|
||||
"admin_sales.phone.recording",
|
||||
"admin_sales.communication.read_all",
|
||||
],
|
||||
async (context) => {
|
||||
const recording = await getAdminCallRecordingPlayback(db, {
|
||||
adminUserId: context.adminUserId,
|
||||
recordingId,
|
||||
canReadAllCommunication: context.canReadAllCommunication,
|
||||
});
|
||||
if (!recording) {
|
||||
throw Response.json(NOT_FOUND_ENVELOPE, { status: 404 });
|
||||
}
|
||||
const bytes = await readAdminCallRecordingPlayback({
|
||||
recording,
|
||||
signal: request.signal,
|
||||
});
|
||||
await writeAdminSalesAudit(db, {
|
||||
actor: context.actor("Anrufaufzeichnung abgespielt"),
|
||||
action: "admin.sales.telephony.recording.played",
|
||||
targetType: "AdminCallRecording",
|
||||
targetId: recording.id,
|
||||
after: {
|
||||
callSessionId: recording.callSessionId,
|
||||
dataOwnerAdminUserId: recording.adminUserId,
|
||||
foreignAccess:
|
||||
recording.adminUserId !== context.adminUserId,
|
||||
},
|
||||
});
|
||||
return new Response(Uint8Array.from(bytes).buffer, {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Cache-Control": "private, no-store",
|
||||
"Content-Disposition": `inline; filename="call-${recording.callSessionId}.mp3"`,
|
||||
"Content-Length": String(bytes.byteLength),
|
||||
"Content-Type": "audio/mpeg",
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
if (error instanceof Response) throw error;
|
||||
throw Response.json(NOT_FOUND_ENVELOPE, { status: 404 });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user