Skip to content

fix: update import status to error on invalid file type validation#38522

Open
Lakshyalamba wants to merge 4 commits intoRocketChat:developfrom
Lakshyalamba:fix/import-status-validation
Open

fix: update import status to error on invalid file type validation#38522
Lakshyalamba wants to merge 4 commits intoRocketChat:developfrom
Lakshyalamba:fix/import-status-validation

Conversation

@Lakshyalamba
Copy link

@Lakshyalamba Lakshyalamba commented Feb 6, 2026

Summary

Fixed a bug where the workspace import status remained "File Loaded" even if the file validation failed (e.g., uploading a PDF to a CSV importer).

Description

  • Backend: Updated executeGetImportFileData in apps/meteor/app/importer/server/methods/getImportFileData.ts to explicitly update the database status to importer_import_failed and set valid: false when an invalid file type is detected.
  • Frontend: Updated ImportOperationSummary.tsx to handle the valid: false state and show the correct error translation.

Steps to test

  1. Go to Administration -> Workspace -> Import.
  2. Click "Import New File" and select the CSV importer.
  3. Upload a non-CSV file (e.g., a .pdf or .txt).
  4. Observe that the "Last Status" column now correctly shows "Error" (or the relevant failed translation) instead of "File Loaded".

Screenshots

Screenshot 2026-02-06 at 12 10 31

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced CSV upload validation to better detect invalid or mismatched CSV content.
    • Import operations now update to an Error status when file validation fails, preventing misleading waiting states.
    • UI status display clarified to explicitly show failed imports for invalid CSVs.
  • Documentation

    • Added changelog entry documenting the improved import validation and status behavior.

@Lakshyalamba Lakshyalamba requested a review from a team as a code owner February 6, 2026 06:42
@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Feb 6, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Feb 6, 2026

🦋 Changeset detected

Latest commit: 4676005

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/meteor Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/api-client Patch
@rocket.chat/apps Patch
@rocket.chat/core-services Patch
@rocket.chat/cron 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/model-typings Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-client Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/ui-voip Patch
@rocket.chat/web-ui-registration 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/abac Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/license Patch
@rocket.chat/media-calls Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/models Patch
@rocket.chat/network-broker Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/mock-providers Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core 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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 6, 2026

Walkthrough

Server validation now treats CSV imports with non-text/csv contentType as invalid, updates the import operation to ERROR and valid: false before throwing; client summary accepts an optional contentType prop and displays import_failed when valid is false.

Changes

Cohort / File(s) Summary
Server-side CSV validation
apps/meteor/app/importer/server/methods/getImportFileData.ts
Added guard detecting invalid CSV imports (checks type === 'CSV' vs contentType), updates import operation to status: ERROR, valid: false in DB before throwing an error when invalid.
Client-side import status display
apps/meteor/client/views/admin/import/ImportOperationSummary.tsx
Added optional contentType?: string to ImportOperationSummaryProps and component props; status cell now renders import_failed when valid is false.
Changelog
.changeset/fix-import-status-validation.md
New changeset documenting the patch that updates import history to reflect error status when file validation fails.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Server
    participant DB

    Client->>Server: getImportFileData(importId)
    Server->>DB: fetch import operation record
    alt importRecord.valid && not (type == "CSV" && contentType != "text/csv")
        Server-->>Client: continue/waiting response
    else invalid OR (type == "CSV" && contentType != "text/csv")
        Server->>DB: update import operation { status: "ERROR", valid: false }
        Server-->>Client: error/throw
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I twitched my whiskers at the stream of rows,
A CSV that wore the wrong clothes,
I nudged the DB, a gentle shove — ERROR shown,
Told the client, "Not this one, go home!"
Hooray for checks and tidy throws. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately describes the main change: updating import status to error when file validation fails on invalid file types.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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

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

@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: 3

🤖 Fix all issues with AI agents
In `@apps/meteor/app/importer/server/methods/getImportFileData.ts`:
- Around line 38-49: The preflight CSV check in getImportFileData rejects valid
CSVs by only allowing 'text/csv'; change the isInvalidCSV logic so
operation.importerKey === 'csv' checks operation.contentType against a list of
common CSV MIME types (e.g. 'text/csv', 'text/plain',
'application/vnd.ms-excel', 'text/comma-separated-values', plus any other
platform variants) instead of a strict inequality, by replacing the
single-string check with an allowlist (e.g.
allowedCsvTypes.includes(operation.contentType)); keep the existing behavior
that marks the operation invalid via Imports.updateOne and throws the
Meteor.Error when the content type is not in the allowlist, and apply the same
relaxed check in the frontend ImportOperationSummary.tsx at the referenced line
to avoid duplicate false failures.

In `@apps/meteor/client/views/admin/import/ImportOperationSummary.tsx`:
- Around line 105-111: In ImportOperationSummary.tsx replace the conditional
inside TableCell to only check valid === false for failure (i.e. render
t('importer_status_import_failed') when valid === false, otherwise use
t(status.replace(...))), remove the CSV-specific guard (type === 'CSV' &&
contentType !== 'text/csv'); also drop the now-unused contentType prop from this
component's props and callers and update any related typings to simplify the
component interface. Ensure you reference the status, valid, type and
contentType symbols when making these edits so you remove all duplicated CSV
content-type logic.
- Line 24: The CSV validation condition in ImportOperationSummary (check
involving variables valid, type, and contentType) treats undefined contentType
as a mismatch and marks CSV imports as Error; update the boolean expression used
to compute the status so it only enforces the CSV MIME check when contentType
exists (e.g., replace the subcondition (type === 'CSV' && contentType !==
'text/csv') with a guarded check such as (type === 'CSV' && contentType != null
&& contentType !== 'text/csv') or (type === 'CSV' && contentType && contentType
!== 'text/csv')), ensuring imports with undefined contentType are not
incorrectly flagged.

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.

2 issues found across 2 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="apps/meteor/app/importer/server/methods/getImportFileData.ts">

<violation number="1" location="apps/meteor/app/importer/server/methods/getImportFileData.ts:39">
P1: The strict `text/csv` MIME type check will incorrectly reject legitimate CSV uploads. Browsers report CSV file MIME types inconsistently across operating systems (e.g., Windows often reports `text/plain` or `application/vnd.ms-excel`). Consider accepting multiple CSV-compatible MIME types.</violation>
</file>

<file name="apps/meteor/client/views/admin/import/ImportOperationSummary.tsx">

<violation number="1" location="apps/meteor/client/views/admin/import/ImportOperationSummary.tsx:107">
P2: Optional contentType is compared strictly to 'text/csv'; when contentType is undefined (legacy records), CSV imports will be marked as failed regardless of actual status, causing regression in status display.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@CLAassistant
Copy link

CLAassistant commented Feb 6, 2026

CLA assistant check
All committers have signed the CLA.

@Lakshyalamba Lakshyalamba changed the title Fix: Update import status to error on invalid file type validation fix: update import status to error on invalid file type validation Feb 6, 2026
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.

3 participants