Skip to content

Commit c0f5ce4

Browse files
nipunn1313Convex, Inc.
authored andcommitted
Limit audit log to 90 days in the UI. (#42276)
Block access beyond 90 days in past from the UI selector with appropriate tooltips. GitOrigin-RevId: d8d8c3ea086fddd041e03bace4b040abb81498ea
1 parent 8bc165b commit c0f5ce4

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

npm-packages/dashboard-common/src/features/history/components/HistoryView.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,21 @@ function History() {
4242
const team = useCurrentTeam();
4343
const { startDate, endDate, setDate } = useDateFilters(router);
4444
const entitlements = useTeamEntitlements(team?.id);
45-
const auditLogsEnabled =
46-
entitlements && entitlements.auditLogRetentionDays !== 0;
45+
const auditLogRetentionDays = entitlements?.auditLogRetentionDays ?? 0;
46+
const auditLogsEnabled = auditLogRetentionDays !== 0;
4747

4848
// Current day
4949
const maxEndDate = endOfToday();
5050

51-
const minStartDate = startOfDay(new Date(2023, 0, 1));
51+
const minStartDate = startOfDay(
52+
auditLogRetentionDays === -1
53+
? new Date(2023, 0, 1)
54+
: Date.now() - auditLogRetentionDays * 24 * 60 * 60 * 1000,
55+
);
56+
const beforeMinDateTooltip =
57+
auditLogRetentionDays === -1
58+
? null
59+
: `Deployment history is preserved for ${auditLogRetentionDays} days.`;
5260

5361
const filters: DeploymentAuditLogFilters = {
5462
minDate: startDate.getTime(),
@@ -69,6 +77,7 @@ function History() {
6977
maxDate={maxEndDate}
7078
date={{ from: startDate, to: endDate }}
7179
setDate={setDate}
80+
beforeMinDateTooltip={beforeMinDateTooltip}
7281
/>
7382
<HistoryList filters={filters} />
7483
</>

npm-packages/dashboard/src/components/teamSettings/AuditLog.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ jest.mock("api/auditLog", () => ({
2929

3030
jest.mock("api/teams", () => ({
3131
useTeamMembers: () => [],
32+
useTeamEntitlements: () => ({
33+
auditLogRetentionDays: 90,
34+
}),
3235
}));
3336

3437
describe("AuditLog", () => {

npm-packages/dashboard/src/components/teamSettings/AuditLog.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { LoadingTransition } from "@ui/Loading";
44
import { useDateFilters } from "@common/elements/DateRangePicker";
55
import { useTeamAuditLog } from "api/auditLog";
66
import { useProjects } from "api/projects";
7-
import { useTeamMembers } from "api/teams";
7+
import { useTeamEntitlements, useTeamMembers } from "api/teams";
88
import { AuditLogAction, Team } from "generatedApi";
99
import { useRouter } from "next/router";
1010
import { AuditLogContent } from "./AuditLogContent";
@@ -13,6 +13,8 @@ import { AuditLogToolbar } from "./AuditLogToolbar";
1313
export function AuditLog({ team }: { team: Team }) {
1414
const projects = useProjects(team.id);
1515
const members = useTeamMembers(team.id);
16+
const auditLogRetentionDays =
17+
useTeamEntitlements(team?.id)?.auditLogRetentionDays ?? 0;
1618

1719
const router = useRouter();
1820

@@ -73,6 +75,7 @@ export function AuditLog({ team }: { team: Team }) {
7375
selectedEndDay={endDate}
7476
setDate={setDate}
7577
members={members}
78+
auditLogRetentionDays={auditLogRetentionDays}
7679
/>
7780
)}
7881
<LoadingTransition>

npm-packages/dashboard/src/components/teamSettings/AuditLogToolbar.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export function AuditLogToolbar({
6363
selectedEndDay,
6464
members,
6565
setDate,
66+
auditLogRetentionDays,
6667
}: {
6768
selectedMember: string;
6869
setSelectedMember: (member: string) => void;
@@ -72,8 +73,17 @@ export function AuditLogToolbar({
7273
selectedEndDay: Date;
7374
members: MemberResponse[];
7475
setDate: (date: DateRange) => void;
76+
auditLogRetentionDays: number;
7577
}) {
76-
const minStartDate = startOfDay(new Date("2024-06-05"));
78+
const minStartDate = startOfDay(
79+
auditLogRetentionDays === -1
80+
? new Date(2024, 6, 5)
81+
: Date.now() - auditLogRetentionDays * 24 * 60 * 60 * 1000,
82+
);
83+
const beforeMinDateTooltip =
84+
auditLogRetentionDays === -1
85+
? null
86+
: `Deployment history is preserved for ${auditLogRetentionDays} days.`;
7787
const maxEndDate = endOfToday();
7888

7989
const startDate =
@@ -86,6 +96,7 @@ export function AuditLogToolbar({
8696
maxDate={maxEndDate}
8797
date={{ from: startDate, to: selectedEndDay }}
8898
setDate={setDate}
99+
beforeMinDateTooltip={beforeMinDateTooltip}
89100
/>
90101
<Combobox
91102
options={[

0 commit comments

Comments
 (0)