Skip to content

feat: add bulk delete all measurements for a device - #858

Open
JerryVincent wants to merge 9 commits into
devfrom
feat/deleteMeasurements_at_Once
Open

feat: add bulk delete all measurements for a device#858
JerryVincent wants to merge 9 commits into
devfrom
feat/deleteMeasurements_at_Once

Conversation

@JerryVincent

Copy link
Copy Markdown
Collaborator

Type of Change

  • Dependency upgrade
  • Bug fix (non-breaking change)
  • Breaking change
    • e.g. a fixed bug or new feature that may break something else
  • New feature
  • Code quality improvements
    • e.g. refactoring, documentation, tests, tooling, ...

Implementation

Added a new Delete Measurements page under the device settings sidebar (/device/:deviceId/edit/delete-measurements). On the backend, deleteMeasurementsForDevice was added to measurement.server.ts — it uses a Drizzle subquery to fetch all sensor IDs belonging to the device and deletes their measurements in a single database operation. The route action follows the same auth pattern as the device deletion page: session-based ownership check plus password re-verification via verifyLogin before any data is touched. The action returns the deleted row count so the UI can distinguish between a successful deletion and a no-op (device had no measurements), showing a green success banner or a yellow warning respectively. EN and DE translations are included.

Checklist

  • I gave this pull request a meaningful title
  • My pull request is targeting the dev branch
  • I have added documentation to my code
  • I have deleted code that I have commented out

Additional Information

Previously, clearing a device's measurement history required deleting
each sensor's data individually. Users can now delete all measurements
across all sensors at once from the device settings sidebar, with
password confirmation and feedback for both success and empty states.
@github-actions

github-actions Bot commented Mar 25, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 65.97% 2243 / 3400
🔵 Statements 64.5% 2317 / 3592
🔵 Functions 63.17% 434 / 687
🔵 Branches 50.84% 1081 / 2126
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
app/db/models/measurement.server.ts 54.87% 37.5% 64.28% 54.54% 35-160, 186, 187, 199-203, 250-252, 256, 340-351
Generated in workflow #2944 for commit 8e1648c by the Vitest Coverage Report Action

@scheidtdav scheidtdav left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should revisit the UX of this:
Currently on osem, the users are able to select "delete measurements" per sensor on the "sensors" page of the device settings.
I think we should keep that and add "delete all measurements" to that.

The confirmation by entering the password again is a good idea. We should totally keep that.

@JerryVincent There is no pressure for you to pick this up again. I am just leaving this here for our future reference :-) Of course, if you have fun doing it, feel free to do so.

@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 5f71c41a-e6fb-498d-95fe-6973f51f6433

📥 Commits

Reviewing files that changed from the base of the PR and between cd50ac8 and 8e1648c.

📒 Files selected for processing (3)
  • app/routes/device.$deviceId.edit.sensors.tsx
  • public/locales/de/edit-device-sensors.json
  • public/locales/en/edit-device-sensors.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/routes/device.$deviceId.edit.sensors.tsx

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added an option to permanently delete all measurements for a device from sensor settings.
    • Added password confirmation and invalid-password feedback to protect this destructive action.
    • Added success and empty-state messages, including German translations.
  • Bug Fixes

    • Removed the outdated “Delete Measurements” navigation entry from the device edit sidebar.
    • Password fields now reset after successful sensor updates.

Walkthrough

Adds password-confirmed deletion of all measurements linked to a device’s sensors. The edit sensors page now provides the form and status feedback. English and German translations support the flow, and the separate deletion navigation entry is removed.

Changes

Device measurement deletion

Layer / File(s) Summary
Measurement deletion storage
app/db/models/measurement.server.ts
Adds deleteMeasurementsForDevice(deviceId), which selects the device’s sensors and deletes their measurements.
Protected deletion route
app/routes/device.$deviceId.edit.sensors.tsx
Verifies the submitted password, deletes the device measurements, returns deletion status, and renders the confirmation form and feedback messages.
Deletion navigation and localization
app/routes/device.$deviceId.edit.tsx, public/locales/en/edit-device-sensors.json, public/locales/de/edit-device-sensors.json
Removes the separate deletion navigation entry and adds English and German strings for the deletion flow.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: 🟡 Moderate · up to 8e164

Bulk deletion checks ownership separately from the destructive operation, so a concurrent ownership transfer could allow measurements to be deleted after authorization becomes stale. This concrete data-security risk should be fixed or explicitly accepted before merging.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant SensorsPage
  participant SensorsAction
  participant MeasurementModel
  participant Database

  User->>SensorsPage: Submit password
  SensorsPage->>SensorsAction: POST delete-measurements
  SensorsAction->>SensorsAction: Verify password
  SensorsAction->>MeasurementModel: Delete device measurements
  MeasurementModel->>Database: Select sensors and delete measurements
  Database-->>MeasurementModel: Return deleted row count
  MeasurementModel-->>SensorsAction: Return deletion result
  SensorsAction-->>SensorsPage: Return success or error data
  SensorsPage-->>User: Display status message
Loading
🚥 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%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 4 files. (2 skipped: 2 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: bulk deletion of all measurements for a device.
Description check ✅ Passed The description is directly related to the changeset and explains the new page, backend deletion function, authorization, feedback, and translations.
Linked Issues check ✅ Passed The pull request satisfies issue #833 by providing a device-level operation that deletes measurements across all sensors, with the required backend and user interface support.
Out of Scope Changes check ✅ Passed The changes are within scope for issue #833. They implement bulk deletion, authorization, user feedback, navigation updates, and localization required by the feature.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 4 files. (2 skipped: 2 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/deleteMeasurements_at_Once

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e8e5b315-bc29-421b-8642-1e1e942277bd

📥 Commits

Reviewing files that changed from the base of the PR and between 7efd824 and b0a8027.

📒 Files selected for processing (5)
  • app/db/models/measurement.server.ts
  • app/routes/device.$deviceId.edit.delete-measurements.tsx
  • app/routes/device.$deviceId.edit.tsx
  • public/locales/de/delete-measurements.json
  • public/locales/en/delete-measurements.json

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.

Comment thread app/routes/device.$deviceId.edit.delete-measurements.tsx Outdated
)
}

const result = await deleteMeasurementsForDevice(deviceId)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

sed -n '1,115p' 'app/routes/device.$deviceId.edit.delete-measurements.tsx'
sed -n '325,360p' app/db/models/measurement.server.ts
rg -n "update.*device|userId.*device|deviceId.*userId|set\\(.*userId|getUserDevice|deleteMeasurementsForDevice" app/db app/routes

Repository: openSenseMap/frontend

Length of output: 9733


Authorization Bypass (CWE-367): Time-of-check Time-of-use (TOCTOU) Race Condition

Reachability: External · Exploitability: Difficult

Make the ownership check atomic with deletion.

getUserDevice checks ownership before the separate, unscoped deletion. Pass userId to deleteMeasurementsForDevice and include it in the deletion predicate. Add a race test that transfers ownership between these operations and confirms that no measurements are deleted.

📍 Affects 2 files
  • app/routes/device.$deviceId.edit.delete-measurements.tsx#L70-L70 (this comment)
  • app/db/models/measurement.server.ts#L339-L347

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b9a43aa6-25dd-4a82-b171-6f3a221e9051

📥 Commits

Reviewing files that changed from the base of the PR and between b0a8027 and cd50ac8.

📒 Files selected for processing (4)
  • app/routes/device.$deviceId.edit.sensors.tsx
  • app/routes/device.$deviceId.edit.tsx
  • public/locales/de/edit-device-sensors.json
  • public/locales/en/edit-device-sensors.json
💤 Files with no reviewable changes (1)
  • app/routes/device.$deviceId.edit.tsx

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.

Comment thread app/routes/device.$deviceId.edit.sensors.tsx
Comment thread app/routes/device.$deviceId.edit.sensors.tsx Outdated
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.

Provide function for deleting measurements of all sensors/phenomena at once

2 participants