Add file download support with permission checks and UI integration - #17
Conversation
|
Warning Review limit reached
More reviews will be available in 16 minutes and 49 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (9)
📝 WalkthroughWalkthroughThis pull request implements a complete file download sharing system using temporary, user-bound download links valid for one day. Users with admin/super-admin roles generate links via POST endpoints, and authenticated users can download files via signed tokens. The backend stores link metadata and per-download audit events; the frontend provides UI controls in the file browser and backup pages, gated by a new ChangesFile Download Sharing Feature
Windows Registry Cleanup
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes This PR spans full-stack changes across a new feature (file downloads) with heterogeneous components: database schema and migrations, cryptographic token handling, permission logic, backend HTTP handlers with transactional record-keeping, and multiple frontend UI surfaces. The logic density is moderate to high (fingerprinting, token signing/verification, transaction safety) spread across multiple files with different review concerns (schema, API contract, cryptography, UI patterns). The scope includes coordinated backend-frontend wiring and comprehensive test coverage across both layers. Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsStopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 7
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/omnihance-a3-agent/omnihance-a3-agent-ui/src/components/file-tree.tsx`:
- Around line 513-515: The onError handler for the download assumes the error is
APIError and calls error.getErrorMessage(), which can itself throw for
non-APIError values; change the onError implementation in the file-tree
component to safely handle all error types: wrap the body in a small try/catch,
detect if the error is an instance of APIError and use error.getErrorMessage(),
otherwise use a safe fallback like error?.message || String(error) || 'Download
failed', and call toast.error with that message so the handler never throws.
Ensure you reference the onError handler and APIError/getErrorMessage symbols
when editing.
In `@cmd/omnihance-a3-agent/omnihance-a3-agent-ui/src/components/file-view.tsx`:
- Line 67: The Download button is currently only permission-checked in the click
handler (canDownloadFiles) which leaves the button visible to unauthorized
users; update the rendering logic in the FileView component to conditionally
render or hide/disable the Download button based on the canDownloadFiles boolean
(the same variable used in the onDownloadClick handler), i.e., wrap the JSX that
renders the Download button (the code around the existing download button render
and the handler reference) with a check like if (canDownloadFiles) ... or render
a disabled/tooltip variant when false; apply the same guard to the other
instances referenced (the blocks corresponding to lines ~285-292 and ~367-380)
so the button is gated at render time as well as on click.
In `@internal/db/file_downloads.go`:
- Around line 202-204: Replace the string-built error with the shared
constants-based not-found error: instead of returning fmt.Errorf("file download
link not found") in the file download lookup (the block where found is checked
in internal/db/file_downloads.go), return the project standard not-found
sentinel (e.g. constants.ErrNotFound) and ensure the constants package is
imported; do not wrap it in fmt.Errorf so callers can reliably use errors.Is to
detect "not found".
In `@internal/db/internal_db.go`:
- Around line 2018-2019: Remove the redundant index creation for
idx_file_download_links_public_id: delete the CREATE INDEX IF NOT EXISTS
idx_file_download_links_public_id ON file_download_links (public_id); statement
because file_download_links.public_id is defined TEXT NOT NULL UNIQUE and the
UNIQUE constraint already creates the necessary index; ensure no code relies on
the explicit idx_file_download_links_public_id name (search references to
idx_file_download_links_public_id) before removing.
In `@internal/odbc/sqlserverdsn/driver_path_windows.go`:
- Around line 22-24: The defer inside the loop captures the loop variable key by
reference causing earlier opened registry keys to leak; update the loop in
driver_path_windows.go so the defer captures the current key value (e.g., change
defer func() { _ = key.Close() }() to defer func(k registry.Key) { _ = k.Close()
}(key)) or alternatively close the key immediately after use; look for the
variable named key and the defer registration in the loop that checks the
"Driver" value and ensure each opened key is closed deterministically by
capturing key in the closure or by explicit Close() before continuing.
In `@internal/server/file_download_routes.go`:
- Around line 96-120: The current flow validates the file via
s.buildFileDownloadFingerprint but then calls http.ServeFile which reopens the
path and can race or double-read; instead open the file once (os.Open) prior to
fingerprinting, pass that file handle into the fingerprint routine (or add a
sibling like buildFileDownloadFingerprintFromFile) so the same *os.File is used
for validation, rewind it if the fingerprint read consumed bytes
(file.Seek(0,0)), record the download (RecordFileDownload) and then serve using
http.ServeContent or io.Copy from that open file handle rather than
http.ServeFile, and ensure the opened file is closed after serving to prevent
leaks.
In `@README.md`:
- Around line 579-580: The "Permission Actions" section is missing the
download_files action referenced by the file download endpoints; add a new entry
named download_files to that central permission list (Permission Actions) with a
short description like "Allows creating and using one-day user-bound download
links and downloading files," indicate its scope (e.g., project or user-bound)
and reference the related endpoints (POST /api/file-tree/download-link and GET
/api/file-tree/download/{token}) so RBAC docs remain consistent with the API
doc.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2295110f-a697-48e7-9072-31349b5ae1f0
📒 Files selected for processing (21)
README.mdcmd/omnihance-a3-agent/docs/openapi.ymlcmd/omnihance-a3-agent/omnihance-a3-agent-ui/README.mdcmd/omnihance-a3-agent/omnihance-a3-agent-ui/src/components/backup-page.tsxcmd/omnihance-a3-agent/omnihance-a3-agent-ui/src/components/file-tree.tsxcmd/omnihance-a3-agent/omnihance-a3-agent-ui/src/components/file-view.tsxcmd/omnihance-a3-agent/omnihance-a3-agent-ui/src/hooks/use-permissions.tscmd/omnihance-a3-agent/omnihance-a3-agent-ui/src/lib/api.tsinternal/db/file_downloads.gointernal/db/file_downloads_test.gointernal/db/internal_db.gointernal/db/mock_InternalDB.gointernal/odbc/sqlserverdsn/driver_path_windows.gointernal/permissions/permissions.gointernal/permissions/permissions_test.gointernal/server/backup_routes.gointernal/server/backup_routes_test.gointernal/server/file_download_routes.gointernal/server/file_download_routes_test.gointernal/server/file_system_routes.gointernal/utils/userdsn/dsn_windows.go
Summary
Testing
Summary by CodeRabbit
New Features
Bug Fixes