Skip to content

Add file download support with permission checks and UI integration - #17

Merged
cyberinferno merged 3 commits into
masterfrom
feat/download
Jun 9, 2026
Merged

Add file download support with permission checks and UI integration#17
cyberinferno merged 3 commits into
masterfrom
feat/download

Conversation

@cyberinferno

@cyberinferno cyberinferno commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Added backend file download routes, database tracking, and permission enforcement for downloadable files.
  • Updated the UI backup/file tree/file view flows to surface downloads through the new API.
  • Refreshed OpenAPI and README documentation to cover the download feature and related setup notes.

Testing

  • Added and updated unit tests for download routes, permissions, and file download database behavior.
  • Not run (not requested)

Summary by CodeRabbit

  • New Features

    • Users with appropriate permissions can now download files and backup outputs via temporary, user-bound download links that expire after one day
    • Download activity is tracked with event logging for audit purposes
  • Bug Fixes

    • Improved Windows registry resource cleanup in DSN managers

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@cyberinferno, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b20f55d9-e7e2-4418-b87c-3da91ef8d373

📥 Commits

Reviewing files that changed from the base of the PR and between 52dc1de and de7766f.

📒 Files selected for processing (9)
  • README.md
  • cmd/omnihance-a3-agent/omnihance-a3-agent-ui/src/components/file-tree.tsx
  • cmd/omnihance-a3-agent/omnihance-a3-agent-ui/src/components/file-view.tsx
  • internal/constants/constants.go
  • internal/db/file_downloads.go
  • internal/db/file_downloads_test.go
  • internal/db/internal_db.go
  • internal/odbc/sqlserverdsn/driver_path_windows.go
  • internal/server/file_download_routes.go
📝 Walkthrough

Walkthrough

This 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 download_files permission.

Changes

File Download Sharing Feature

Layer / File(s) Summary
Documentation and Permission Model
README.md, cmd/omnihance-a3-agent/docs/openapi.yml, cmd/omnihance-a3-agent/omnihance-a3-agent-ui/README.md, internal/permissions/permissions.go
OpenAPI spec and README document two new file-tree endpoints for creating and downloading via temp links, and a new backup download-link endpoint. A new ActionDownloadFiles permission constant grants access to super_admin and admin roles.
Permission System Extension
cmd/omnihance-a3-agent/omnihance-a3-agent-ui/src/hooks/use-permissions.ts, internal/permissions/permissions_test.go
The download_files permission is added to the permission action union and role mappings, with test cases validating super_admin/admin access and viewer denial.
Database Schema and Access Methods
internal/db/file_downloads.go, internal/db/file_downloads_test.go, internal/db/internal_db.go, internal/db/mock_InternalDB.go
New file_download_links and file_download_events tables store reusable download link records with file fingerprints and per-download audit events. Four database methods handle link reuse, creation, lookup, and event recording. The migration lifecycle and mock helpers are updated to support testing.
Backend Download Route Handlers
internal/server/file_download_routes.go, internal/server/file_download_routes_test.go, internal/server/file_system_routes.go
Two HTTP endpoints create/reuse download links and validate/serve files, including HMAC-SHA256 token signing/verification, fingerprint validation to detect file changes, and download event recording. Tests cover link reuse, permission enforcement, and error cases (expiry, missing files, changed content).
Backup Download Integration
internal/server/backup_routes.go, internal/server/backup_routes_test.go
The backup service gains a download-link endpoint for succeeded run output files and refactors the legacy download endpoint to redirect via the shared temp-link flow. New response types include download_available boolean to indicate file existence. Tests validate link creation and redirect behavior.
Frontend API Client and Types
cmd/omnihance-a3-agent/omnihance-a3-agent-ui/src/lib/api.ts
New DownloadLinkResponse schema and two API client functions (createFileDownloadLink, createBackupRunFileDownloadLink) POST to the backend and return link metadata. The BackupRunFile type gains a download_available field.
Frontend UI Components: File Downloads
cmd/omnihance-a3-agent/omnihance-a3-agent-ui/src/components/file-tree.tsx, cmd/omnihance-a3-agent/omnihance-a3-agent-ui/src/components/file-view.tsx, cmd/omnihance-a3-agent/omnihance-a3-agent-ui/src/components/backup-page.tsx
Three React components add download UI: file-tree includes a context-menu "Download" item, file-view adds a header download button, and backup-page switches to link-based downloads. All use the new API functions, enforce permission gates, and show loading/error states.

Windows Registry Cleanup

Layer / File(s) Summary
Registry Key Closure Pattern
internal/odbc/sqlserverdsn/driver_path_windows.go, internal/utils/userdsn/dsn_windows.go
Six methods now consistently defer registry key closure using defer func() { _ = key.Close() }() instead of direct defers, explicitly discarding Close() errors.

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

🐰 A rabbit hops through file-trees with glee,
Temp links in hand for a download spree!
MD5 and tokens keep watch all day,
Admin and super-admin lead the way.
One day to share, then links fade away—
Secure downloads, hip-hip-hooray! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 2.27% 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: adding file download functionality with associated permission checks and frontend UI integration.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/download

Warning

Review ran into problems

🔥 Problems

Stopped 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 @coderabbit review after the pipeline has finished.


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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3ac6316 and 52dc1de.

📒 Files selected for processing (21)
  • README.md
  • cmd/omnihance-a3-agent/docs/openapi.yml
  • cmd/omnihance-a3-agent/omnihance-a3-agent-ui/README.md
  • cmd/omnihance-a3-agent/omnihance-a3-agent-ui/src/components/backup-page.tsx
  • cmd/omnihance-a3-agent/omnihance-a3-agent-ui/src/components/file-tree.tsx
  • cmd/omnihance-a3-agent/omnihance-a3-agent-ui/src/components/file-view.tsx
  • cmd/omnihance-a3-agent/omnihance-a3-agent-ui/src/hooks/use-permissions.ts
  • cmd/omnihance-a3-agent/omnihance-a3-agent-ui/src/lib/api.ts
  • internal/db/file_downloads.go
  • internal/db/file_downloads_test.go
  • internal/db/internal_db.go
  • internal/db/mock_InternalDB.go
  • internal/odbc/sqlserverdsn/driver_path_windows.go
  • internal/permissions/permissions.go
  • internal/permissions/permissions_test.go
  • internal/server/backup_routes.go
  • internal/server/backup_routes_test.go
  • internal/server/file_download_routes.go
  • internal/server/file_download_routes_test.go
  • internal/server/file_system_routes.go
  • internal/utils/userdsn/dsn_windows.go

Comment thread cmd/omnihance-a3-agent/omnihance-a3-agent-ui/src/components/file-tree.tsx Outdated
Comment thread internal/db/file_downloads.go
Comment thread internal/db/internal_db.go Outdated
Comment thread internal/odbc/sqlserverdsn/driver_path_windows.go Outdated
Comment thread internal/server/file_download_routes.go Outdated
Comment thread README.md
@cyberinferno
cyberinferno merged commit 72936c6 into master Jun 9, 2026
2 checks passed
@cyberinferno
cyberinferno deleted the feat/download branch June 9, 2026 17:50
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.

1 participant