Skip to content

fix: audit log not showing folder downloads#2121

Open
shubsolos19 wants to merge 1 commit intomfts:mainfrom
shubsolos19:fix/audit-log-folder-download
Open

fix: audit log not showing folder downloads#2121
shubsolos19 wants to merge 1 commit intomfts:mainfrom
shubsolos19:fix/audit-log-folder-download

Conversation

@shubsolos19
Copy link

@shubsolos19 shubsolos19 commented Mar 21, 2026

Fixes #1910

Problem

Folder downloads were not appearing in the dataroom audit log.

Root Cause

dataroom-folder.ts correctly creates View records with
viewType: "DOCUMENT_VIEW" and downloadType: "FOLDER",
but the audit log API (views/index.ts) only queried for
viewType: "DATAROOM_VIEW", so folder downloads were
silently excluded from the audit log.

Fix

Updated the Prisma query in views/index.ts to use an OR
condition that includes DOCUMENT_VIEW records where
downloadType is FOLDER or BULK.

No schema changes required — DownloadType.FOLDER already
exists in the Prisma schema.

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved view tracking accuracy for datarooms by expanding the scope of views included in reports. View counts now comprehensively capture additional view types alongside standard dataroom views, providing more complete usage analytics.

@shubsolos19 shubsolos19 requested a review from mfts as a code owner March 21, 2026 07:21
@vercel
Copy link

vercel bot commented Mar 21, 2026

@shubsolos19 is attempting to deploy a commit to the mftsio Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 21, 2026

Walkthrough

Modified the dataroom views query to include DOCUMENT_VIEW records (filtered by downloadType "FOLDER" and "BULK") alongside DATAROOM_VIEW records, with adjusted pause-time constraints applied consistently across both view types in both the main query and hidden views count.

Changes

Cohort / File(s) Summary
Dataroom views query expansion
pages/api/teams/[teamId]/datarooms/[id]/views/index.ts
Updated Prisma query to fetch views using disjunctive OR filter combining DATAROOM_VIEW and DOCUMENT_VIEW (with downloadType restriction) records. Adjusted pause-time filtering logic to apply consistently across both view types in the main query and hiddenViewsFromPause count.

Possibly related PRs

  • Dataroom endpoint performance #1992: Updates how dataroom views are aggregated by computing lastViewedAt through view aggregation logic, complementing the expanded view filtering introduced in this PR.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: audit log not showing folder downloads' directly and clearly describes the main change in the changeset.
Linked Issues check ✅ Passed The PR successfully addresses issue #1910 by updating the Prisma query to include DOCUMENT_VIEW records with FOLDER/BULK downloadType in the audit log, ensuring folder downloads are tracked.
Out of Scope Changes check ✅ Passed All changes are focused on fixing the audit log query to include folder downloads, with no unrelated modifications present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can use oxc to improve the quality of JavaScript and TypeScript code reviews.

Add a configuration file to your project to customize how CodeRabbit runs oxc.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
pages/api/teams/[teamId]/datarooms/[id]/views/index.ts (1)

57-75: Refactor duplicated view filters to prevent future query drift.

The same inclusion logic is now repeated in both the main list query and the hidden-count query. Extracting shared predicates into helpers/constants will reduce regression risk.

♻️ Suggested refactor sketch
+const includedViewTypes = [
+  { viewType: "DATAROOM_VIEW" as const },
+  {
+    viewType: "DOCUMENT_VIEW" as const,
+    downloadType: { in: ["FOLDER", "BULK"] as const },
+  },
+];
+
+const beforePause = team.pauseStartsAt
+  ? { viewedAt: { lt: team.pauseStartsAt } }
+  : {};
+
+const afterPause = team.pauseStartsAt
+  ? { viewedAt: { gte: team.pauseStartsAt } }
+  : {};
...
-where: { OR: [ ...duplicated conditions... ] }
+where: {
+  OR: includedViewTypes.map((v) => ({ ...v, ...beforePause })),
+}
...
-where: {
-  dataroomId: dataroomId,
-  OR: [ ...duplicated conditions... ],
-  viewedAt: { gte: team.pauseStartsAt },
-}
+where: {
+  dataroomId,
+  ...afterPause,
+  OR: includedViewTypes,
+}

Also applies to: 118-126

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pages/api/teams/`[teamId]/datarooms/[id]/views/index.ts around lines 57 - 75,
The query repeats the same view predicates in the views selection (the OR with
viewType "DATAROOM_VIEW" and "DOCUMENT_VIEW" plus the optional viewedAt filter
using team.pauseStartsAt) and again in the hidden-count query; extract these
shared predicates into a single reusable helper (e.g., a function or constant
like buildDataroomViewFilter or dataroomViewPredicates) and use it in both
places (the views query and the hidden-count query) so both the
DATAROOM_VIEW/DOCUMENT_VIEW conditions, dataroomId inclusion and the conditional
viewedAt: { lt: team.pauseStartsAt } logic are defined once and reused.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@pages/api/teams/`[teamId]/datarooms/[id]/views/index.ts:
- Around line 57-75: The query repeats the same view predicates in the views
selection (the OR with viewType "DATAROOM_VIEW" and "DOCUMENT_VIEW" plus the
optional viewedAt filter using team.pauseStartsAt) and again in the hidden-count
query; extract these shared predicates into a single reusable helper (e.g., a
function or constant like buildDataroomViewFilter or dataroomViewPredicates) and
use it in both places (the views query and the hidden-count query) so both the
DATAROOM_VIEW/DOCUMENT_VIEW conditions, dataroomId inclusion and the conditional
viewedAt: { lt: team.pauseStartsAt } logic are defined once and reused.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 721e43fc-c27d-4e05-995a-801d92ad844f

📥 Commits

Reviewing files that changed from the base of the PR and between fd7d017 and d28470d.

📒 Files selected for processing (1)
  • pages/api/teams/[teamId]/datarooms/[id]/views/index.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"audit log" not showing download of folder

1 participant