File manager fixes
Description
Previously, courses, labs and assessments that were downloaded as tar files ended up being corrupted. There was also no quick and easy way to view permission bits and change permissions of files on the system.
This PR allows
- Courses and labs to be downloaded and exported correctly as tar files
- Tar files can be exported and opened in the file manager without affecting the core project directory
- File manager shows permission bits of each file and directory
How Has This Been Tested?
- Create new course and assessments
- Check that they appear in the file manager
- Click download tar and check that you can un-tar the file after it is downloaded
- Upload the tar file and check that you can extract the contents of the tar file
- Check that you can view permission bits of a file, try changing one of the permission bits and check that the permission bits are as you expect
Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
Checklist:
- [x] I have run rubocop and erblint for style check. If you haven't, run
overcommit --install && overcommit --signto use pre-commit hook for linting - [ ] My change requires a change to the documentation, which is located at Autolab Docs
- [ ] I have updated the documentation accordingly, included in this PR
If unsure, feel free to submit first and we'll help you along.
๐ Walkthrough
Walkthrough
Adds tar archive support (preview, list contents, view single entry, stream/generate tars) and permissions display in listings; introduces multiple controller helpers for path mapping and tar handling, a new tar viewing/preview UI, a permissions column, a standalone import_submissions.rb script, and minor JS/CSS formatting and a spec update.
Changes
| Cohort / File(s) | Summary |
|---|---|
Controller: tar + permissions + helpersapp/controllers/file_manager_controller.rb |
Adds many methods: tar detection (is_tar_file?), listing (list_tar_contents), single-file extraction (extract_single_file_from_tar), tar streaming/generation (download_tar, add_directory_to_tar, tar_writer flow), tar viewing (view_tar_file), directory/path helpers (find_by_directory_path, find_by_folder_path, path_belongs_to_assessment?, path_belongs_to_course?), integrates permissions into directory listings, and robust error handling / normalization for tar operations. |
Views: UI, tar preview & file viewapp/views/file_manager/index.html.erb, app/views/file_manager/tar_preview.html.erb, app/views/file_manager/tar_file_view.html.erb |
Adds Permissions column to listing; special rendering and actions for tar archives (preview, download, view entry); new templates for archive preview and rendering a single extracted file with syntax highlighting and controls. |
Routesconfig/routes.rb |
Adds route: get 'file_manager/view_tar_file' โ file_manager#view_tar_file (named view_tar_file). |
Frontend JS (formatting)app/assets/javascripts/file_manager.js |
Formatting/whitespace changes only (no behavior change) per diff summary; no new JS behavior introduced in this PR. |
Frontend stylesapp/assets/stylesheets/file_manager.scss |
Reindent/formatting changes and adds .permissions-display style (monospace, small font, dark color). |
Specspec/controllers/file_manager_controller_spec.rb |
Adds expectation asserting a "Permissions" table header in index HTML tests. |
Utility script (new)import_submissions.rb |
New standalone script to bulk-import submissions from a ZIP: extracts per-user tar handins, finds users/CUDs, creates Submission records and uploads files; includes per-entry error handling and cleanup. |
Sequence Diagram(s)
sequenceDiagram
autonumber
actor User
participant UI as FileManager UI
participant FM as FileManagerController
participant FS as Filesystem
Note over UI,FM: Permissions display and tar actions available in listing
User->>UI: Click "Preview Contents" (tar)
UI->>FM: GET /file_manager?path=...&preview=true
FM->>FM: is_tar_file? -> list_tar_contents(path)
FM->>FM: build preview model (entries with permissions)
FM-->>UI: Render tar_preview (list of entries)
sequenceDiagram
autonumber
actor User
participant UI as FileManager UI
participant FM as FileManagerController
participant Tar as Tar/Gzip libs
participant FS as Filesystem
Note over UI,FM: View single file inside tar
User->>UI: Click entry link (view_tar_file)
UI->>FM: GET file_manager/view_tar_file?tar_path=...&file_path=...
FM->>FM: authorize + validate tar format
FM->>Tar: extract_single_file_from_tar(tar_path, file_path)
Tar-->>FM: file payload or error
alt success (text)
FM-->>UI: render tar_file_view with file contents
else success (binary/attachment)
FM-->>UI: send_data as attachment
else error
FM-->>UI: redirect with flash error
end
sequenceDiagram
autonumber
actor User
participant UI as FileManager UI
participant FM as FileManagerController
participant Tar as Tar writer
participant FS as Filesystem
User->>UI: Click "Download" on directory/course/assessment
UI->>FM: GET download (target)
alt single file
FM->>FS: read file
FM-->>UI: send file
else directory / assessment / course
FM->>Tar: stream tar via add_directory_to_tar / tar_writer
FM->>FS: read entries recursively
Tar-->>FM: tar stream
FM-->>UI: stream tar download
end
Estimated code review effort
๐ฏ 4 (Complex) | โฑ๏ธ ~60โ90 minutes
Files/areas needing extra attention:
-
app/controllers/file_manager_controller.rbโ large surface area: tar streaming, extraction, authorization, path normalization, and recursive tar generation. - Tar safety checks: traversal normalization, symlink handling, and extraction write paths.
- New views
tar_preview.html.erbandtar_file_view.html.erbโ ensure correct escaping and safe rendering of file contents. -
import_submissions.rbโ uses Rack test upload flow and filesystem temp handling; verify security assumptions and hardcoded course name.
Possibly related PRs
- autolab/Autolab#2229 โ Modifies
app/controllers/file_manager_controller.rband overlaps with download/tar and authorization logic; likely intersecting changes.
Suggested reviewers
- jlge
- evanyeyeye
Pre-merge checks and finishing touches
โ Failed checks (1 inconclusive)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Title check | โ Inconclusive | The title 'File manager fixes' is vague and generic, using non-descriptive language that doesn't convey meaningful information about the specific changes. | Revise the title to be more specific, such as 'Add tar file support and permissions display to file manager' or 'Enable tar file previews and permissions management in file manager'. |
โ Passed checks (1 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description check | โ Passed | The pull request description covers all major required sections: clear description of changes, motivation (fixing corruption), comprehensive testing steps, and proper checklist completion with style checks marked as done. |
โจ Finishing touches
- [ ] ๐ Generate docstrings
๐งช Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
- [ ] Commit unit tests in branch
file-manager-fixes
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 @coderabbitai help to get the list of available commands and usage tips.