feat: add saved views API with proper migration (#235)#403
Conversation
…fetchone/fetchall
utksh1
left a comment
There was a problem hiding this comment.
Thanks for the update. I am still seeing a blocker before merge: the migration runner resolves file-backed DB migrations from the database path rather than the package source path. The in-memory tests pass because they use the module directory, while a configured file database can skip 002_add_saved_views.sql and leave the saved-views API without its table. Please resolve migrations relative to the backend.secuscan package location consistently, add coverage for a file-backed database path, and avoid swallowing migration failures silently so startup does not continue with a missing schema.
|
Implemented the requested migration fixes:
Validation:
|
|
Re-reviewed after the latest push. Still blocked: the migration runner must resolve migrations from the backend.secuscan package/source location for file-backed DBs, and startup should not silently continue if a required migration fails. Please add file-backed DB coverage for the saved_views migration path. |
…tion error, add file-backed DB and failure path tests
|
Addressed the requested changes:
I also added explicit cleanup in the new file-backed DB test to ensure the database connection is always closed. After the latest push, the test suite completes successfully ( |
|
Re-reviewed after the latest push. Still blocked: please make migration discovery package-relative for file-backed databases, fail startup visibly if required migrations fail, and add file-backed DB coverage proving saved_views is created outside the in-memory test path. |
|
The migration runner already uses |
utksh1
left a comment
There was a problem hiding this comment.
Thanks for the updates. I re-reviewed the latest diff and this still needs changes before merge. The migration path is now package-relative and the SQL failure path raises, but _run_migrations() still silently returns when the migrations directory is missing. That means a packaged/deploy-time omission would start the app without creating saved_views, and the API would fail later at runtime instead of failing fast during startup. Please make a missing migrations directory an explicit startup error and keep the existing failure-path coverage aligned with that behavior. While touching this, please also avoid broad formatting/noise in main.py so the PR stays focused on saved views.
|
Thanks for the feedback Changes in this update:
All checks are now passing. |
What Changed
backend/secuscan/saved_views.py— New FastAPI router at/api/v1/saved-viewswith full CRUD. POST returns 409 on duplicate names, PUT handles overwrite and rename, DELETE is idempotent. FilterPreset validatessortModeandseverityat the boundary so invalid values get a 422 before touching the database.backend/secuscan/migrations/002_add_saved_views.sql— Proper migration file that creates thesaved_viewstable and a case-insensitive name index. Applied automatically by the migration runner on startup.backend/secuscan/database.py— Added_run_migrations()which scans the migrations directory and applies any.sqlfiles in order. Idempotent — safe to run multiple times.backend/secuscan/main.py— Two lines: importsaved_views_routerandapp.include_router(saved_views_router).testing/backend/unit/test_saved_views.py— 23 tests covering create, list, apply, overwrite, rename, delete, duplicate name (409), invalid JSON (422), invalid enum values (422), empty name (422), name too long (422), non-existent ID (404), idempotent delete, and SQL injection via extra fields.Why
Power users need to save named filter combinations on the Findings page. This PR delivers the backend contract. The frontend hook and panel will follow in a separate PR once this merges.
API
/api/v1/saved-views/api/v1/saved-views/api/v1/saved-views/{id}/api/v1/saved-views/{id}Testing
Closes #235