From d7bea26e90b03e2866e92b57a0e8c30d5dcdc1a0 Mon Sep 17 00:00:00 2001 From: Jack Carter <128555021+SunsetDrifter@users.noreply.github.com> Date: Tue, 15 Sep 2026 18:42:10 +0200 Subject: [PATCH] Fix group and resource order in resource group audit events --- .../activity/ActivityDescription.test.tsx | 68 +++++++++++++++++++ src/modules/activity/ActivityDescription.tsx | 8 +-- 2 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 src/modules/activity/ActivityDescription.test.tsx diff --git a/src/modules/activity/ActivityDescription.test.tsx b/src/modules/activity/ActivityDescription.test.tsx new file mode 100644 index 000000000..23869eea7 --- /dev/null +++ b/src/modules/activity/ActivityDescription.test.tsx @@ -0,0 +1,68 @@ +import { cleanup, render } from "@testing-library/react"; +import React from "react"; +import { afterEach, describe, expect, it, vi } from "vitest"; +import { ActivityEvent } from "@/interfaces/ActivityEvent"; +import ActivityDescription from "@/modules/activity/ActivityDescription"; + +// The component imports @utils/netbird, which reads config.json at module load. +vi.mock("@utils/config", () => ({ + default: () => ({ apiOrigin: "http://localhost", redirectURI: "/" }), +})); + +// Management emits resource.group.add / resource.group.delete with the group as the +// event target: meta.name is the group, meta.resource_name is the network resource +// (management/server/types/group.go, Group.EventMetaResource). The description must +// read the keys in that orientation. + +const baseEvent: Omit = { + id: "ev1", + timestamp: "2026-09-15T10:00:00Z", + initiator_id: "u1", + initiator_email: "admin@example.com", + initiator_name: "Admin", + target_id: "g1", + meta: { + id: "g1", + name: "infra-admins", + resource_id: "r1", + resource_name: "office-lan", + resource_type: "subnet", + }, +}; + +const textOf = (container: HTMLElement) => + container.textContent?.replace(/\s+/g, " ").trim(); + +afterEach(cleanup); + +describe("ActivityDescription resource group events", () => { + it("names the group and the resource in the right slots when a resource is added to a group", () => { + const { container } = render( + , + ); + expect(textOf(container)).toBe( + "Group infra-admins added to resource office-lan", + ); + }); + + it("names the group and the resource in the right slots when a resource is removed from a group", () => { + const { container } = render( + , + ); + expect(textOf(container)).toBe( + "Group infra-admins removed from resource office-lan", + ); + }); +}); diff --git a/src/modules/activity/ActivityDescription.tsx b/src/modules/activity/ActivityDescription.tsx index 26e911829..0e80d49c0 100644 --- a/src/modules/activity/ActivityDescription.tsx +++ b/src/modules/activity/ActivityDescription.tsx @@ -680,16 +680,16 @@ export default function ActivityDescription({ event }: Props) { if (event.activity_code == "resource.group.add") return (
- Group {m.resource_name} added to resource{" "} - {m.name} + Group {m.name} added to resource{" "} + {m.resource_name}
); if (event.activity_code == "resource.group.delete") return (
- Group {m.resource_name} removed from resource{" "} - {m.name} + Group {m.name} removed from resource{" "} + {m.resource_name}
);