Skip to content

Conversation

@pierre-lehnen-rc
Copy link
Contributor

@pierre-lehnen-rc pierre-lehnen-rc commented Jan 8, 2026

Proposed changes (including videos or screenshots)

Issue(s)

CORE-1621

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • Bug Fixes
    • Improved cleanup when a user is deleted: all file attachments (including messages with multiple attachments) and their thumbnails are now reliably removed.

✏️ Tip: You can customize this high-level summary in your review settings.

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Jan 8, 2026

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Jan 8, 2026

🦋 Changeset detected

Latest commit: bd502ff

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 40 packages
Name Type
@rocket.chat/model-typings Patch
@rocket.chat/models Patch
@rocket.chat/meteor Patch
@rocket.chat/apps Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/omnichannel-services Patch
rocketchat-services Patch
@rocket.chat/core-services Patch
@rocket.chat/cron Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core Patch
@rocket.chat/ui-client Patch
@rocket.chat/abac Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/media-calls Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/presence Patch
@rocket.chat/network-broker Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/api-client Patch
@rocket.chat/ddp-client Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/gazzodown Patch
@rocket.chat/http-router Patch
@rocket.chat/livechat Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/ui-voip Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/license Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/mock-providers Patch
@rocket.chat/ui-video-conf Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pierre-lehnen-rc pierre-lehnen-rc marked this pull request as ready for review January 8, 2026 16:23
@pierre-lehnen-rc pierre-lehnen-rc requested a review from a team as a code owner January 8, 2026 16:23
@pierre-lehnen-rc pierre-lehnen-rc added this to the 8.1.0 milestone Jan 8, 2026
@pierre-lehnen-rc pierre-lehnen-rc added the stat: QA assured Means it has been tested and approved by a company insider label Jan 8, 2026
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Jan 8, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 8, 2026

Walkthrough

Extends user-deletion file cleanup to handle messages referencing either a single file or multiple files: updates model typings and Messages query to return both fields, and changes deleteUser to iterate cursor results, delete all files entries per message and conditionally delete file._id.

Changes

Cohort / File(s) Summary
Changeset declaration
​.changeset/stupid-keys-double.md
Adds a patch changeset noting a fix to remove thumbnails/files when a user is deleted.
Type definitions
packages/model-typings/src/models/IMessagesModel.ts
findFilesByUserId return type updated to `FindCursor<Pick<IMessage, 'file'
Model implementation
packages/models/src/models/Messages.ts
Query and projection updated to match and project file._id OR files._id; return cursor now includes both file and files.
Deletion logic
apps/meteor/app/lib/server/functions/deleteUser.ts
deleteUser iterates cursor items, collects and deletes IDs from files arrays via store.deleteById, and conditionally deletes file._id when present.

Sequence Diagram(s)

sequenceDiagram
  actor Admin
  Admin->>Server: request deleteUser(userId)
  Server->>MessagesModel: findFilesByUserId(userId)
  MessagesModel->>Database: query { $or: [file._id, files._id] } + projection
  Database-->>MessagesModel: cursor (items with file and/or files)
  Server->>Cursor: iterate items
  loop per item
    Cursor-->>Server: item { file?, files? }
    alt item.files exists
      Server->>Store: deleteById(fileId) for each files._id
    end
    alt item.file exists and not in files
      Server->>Store: deleteById(file._id)
    end
  end
  Server-->>Admin: deletedRooms result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • KevLehman
  • tassoevan
  • ggazzo

Poem

🐰
I nibble through cursor rows with cheer,
Snatching stray thumbnails far and near.
Single files or many, none shall stay—
I hop, I delete, and clear the way!

🚥 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 clearly and accurately summarizes the main change: fixing the removal of thumbnails when a file is deleted during user removal.
Linked Issues check ✅ Passed The PR addresses CORE-1621 by modifying deleteUser() to properly delete all files (including thumbnails) uploaded by a user through updated query logic in findFilesByUserId().
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the file deletion issue: updates to deleteUser logic, IMessagesModel type signature, and Messages query implementation.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/user-delete-all-message-files

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 63fcffc and bd502ff.

📒 Files selected for processing (1)
  • packages/models/src/models/Messages.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/models/src/models/Messages.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build

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.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 4 files

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.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/models/src/models/Messages.ts (1)

771-777: Query logic is correct, but consider adding an index for files._id.

The updated implementation correctly handles both single file references and files arrays using an $or condition. The projection appropriately includes both fields.

However, there's an index for file._id (line 56) but no corresponding index for files._id. Since this query is part of user deletion (typically infrequent), it may not be performance-critical, but for repositories with many messages, adding an index for files._id could improve query performance.

apps/meteor/app/lib/server/functions/deleteUser.ts (1)

76-87: File deletion logic correctly handles both single and multiple files, including thumbnails.

The implementation properly:

  • Extracts all file IDs from the files array (which includes both regular files and thumbnails stored as separate records with typeGroup: 'thumb')
  • Deletes each file individually in sequence via for await
  • Additionally deletes the legacy file._id if it exists and wasn't already deleted

The use of sequential for await instead of Promise.all is intentional, as indicated by the commit message. Thumbnails are automatically handled because they exist as separate upload records in the files array alongside their parent files.

However, if store.deleteById throws an error for any file, the entire deletion process halts. Consider wrapping individual deletions in try-catch blocks to ensure all files are attempted even if some fail:

🛡️ Optional error handling improvement
 for await (const { file, files } of cursor) {
   const fileIds = files?.map(({ _id }) => _id) || [];
   for await (const fileId of fileIds) {
     if (fileId) {
+      try {
         await store.deleteById(fileId);
+      } catch (error) {
+        console.error(`Failed to delete file ${fileId}:`, error);
+      }
     }
   }

   if (file?._id && !fileIds.includes(file._id)) {
+    try {
       await store.deleteById(file._id);
+    } catch (error) {
+      console.error(`Failed to delete file ${file._id}:`, error);
+    }
   }
 }
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 69aa0bd and 63fcffc.

📒 Files selected for processing (4)
  • .changeset/stupid-keys-double.md
  • apps/meteor/app/lib/server/functions/deleteUser.ts
  • packages/model-typings/src/models/IMessagesModel.ts
  • packages/models/src/models/Messages.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • packages/model-typings/src/models/IMessagesModel.ts
  • packages/models/src/models/Messages.ts
  • apps/meteor/app/lib/server/functions/deleteUser.ts
🧠 Learnings (1)
📚 Learning: 2025-09-30T13:00:05.465Z
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 36990
File: apps/meteor/ee/server/apps/storage/AppRealStorage.ts:55-58
Timestamp: 2025-09-30T13:00:05.465Z
Learning: In AppRealStorage (apps/meteor/ee/server/apps/storage/AppRealStorage.ts), the `remove` method is designed to be idempotent and returns `{ success: true }` unconditionally because the goal is to ensure the app is removed, not to distinguish whether this specific call performed the deletion. Database errors will throw exceptions.

Applied to files:

  • apps/meteor/app/lib/server/functions/deleteUser.ts
🧬 Code graph analysis (2)
packages/model-typings/src/models/IMessagesModel.ts (1)
packages/core-typings/src/IMessage/IMessage.ts (1)
  • IMessage (145-242)
packages/models/src/models/Messages.ts (1)
packages/core-typings/src/IMessage/IMessage.ts (1)
  • IMessage (145-242)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build
🔇 Additional comments (2)
packages/model-typings/src/models/IMessagesModel.ts (1)

154-154: LGTM! Type signature correctly updated to include files array.

The return type now includes both file and files fields, which aligns with the implementation changes and enables proper handling of messages with multiple file attachments.

.changeset/stupid-keys-double.md (1)

1-7: LGTM! Changeset properly documents the fix.

The changeset correctly identifies the affected packages and clearly describes the fix for thumbnail removal during user deletion.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 8, 2026

📦 Docker Image Size Report

➡️ Changes

Service Current Baseline Change Percent
sum of all images 0B 0B 0B
account-service 0B 0B 0B
authorization-service 0B 0B 0B
ddp-streamer-service 0B 0B 0B
omnichannel-transcript-service 0B 0B 0B
presence-service 0B 0B 0B
queue-worker-service 0B 0B 0B
rocketchat 0B 0B 0B

📊 Historical Trend

---
config:
  theme: "dark"
  xyChart:
    width: 900
    height: 400
---
xychart
  title "Image Size Evolution by Service (Last 30 Days + This PR)"
  x-axis ["11/18 22:53", "11/19 23:02", "11/21 16:49", "11/24 17:34", "11/27 22:32", "11/28 19:05", "12/01 23:01", "12/02 21:57", "12/03 21:00", "12/04 18:17", "12/05 21:56", "12/08 20:15", "12/09 22:17", "12/10 23:26", "12/11 21:56", "12/12 22:45", "12/13 01:34", "12/15 22:31", "12/16 22:18", "12/17 21:04", "12/18 23:12", "12/19 23:27", "12/20 21:03", "12/22 18:54", "12/23 16:16", "12/24 19:38", "12/25 17:51", "12/26 13:18", "12/29 19:01", "12/30 20:52", "01/09 07:10 (PR)"]
  y-axis "Size (GB)" 0 --> 0.5
  line "account-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "authorization-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "ddp-streamer-service" [0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.00]
  line "omnichannel-transcript-service" [0.14, 0.14, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.00]
  line "presence-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "queue-worker-service" [0.14, 0.14, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.00]
  line "rocketchat" [0.35, 0.35, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.00]
Loading

Statistics (last 30 days):

  • 📊 Average: 1.5GiB
  • ⬇️ Minimum: 1.4GiB
  • ⬆️ Maximum: 1.6GiB
  • 🎯 Current PR: 0B
ℹ️ About this report

This report compares Docker image sizes from this build against the develop baseline.

  • Tag: pr-38105
  • Baseline: develop
  • Timestamp: 2026-01-09 07:10:00 UTC
  • Historical data points: 30

Updated: Fri, 09 Jan 2026 07:10:00 GMT

@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.71%. Comparing base (e9a46d8) to head (bd502ff).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #38105      +/-   ##
===========================================
+ Coverage    70.69%   70.71%   +0.02%     
===========================================
  Files         3146     3146              
  Lines       108829   108829              
  Branches     19564    19598      +34     
===========================================
+ Hits         76933    76961      +28     
+ Misses       29896    29868      -28     
  Partials      2000     2000              
Flag Coverage Δ
e2e 60.24% <ø> (+0.06%) ⬆️
e2e-api 48.47% <ø> (+1.10%) ⬆️
unit 71.80% <ø> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kodiakhq kodiakhq bot merged commit 05c415b into develop Jan 9, 2026
45 checks passed
@kodiakhq kodiakhq bot deleted the chore/user-delete-all-message-files branch January 9, 2026 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants