Autolab icon indicating copy to clipboard operation
Autolab copied to clipboard

File manager fixes

Open KesterTan opened this issue 3 months ago โ€ข 1 comments

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
Screenshot 2025-10-06 at 4 06 27โ€ฏPM

How Has This Been Tested?

  1. Create new course and assessments
  2. Check that they appear in the file manager
  3. Click download tar and check that you can un-tar the file after it is downloaded
  4. Upload the tar file and check that you can extract the contents of the tar file
  5. 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 --sign to 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.

KesterTan avatar Oct 06 '25 20:10 KesterTan

๐Ÿ“ 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 + helpers
app/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 view
app/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.
Routes
config/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 styles
app/assets/stylesheets/file_manager.scss
Reindent/formatting changes and adds .permissions-display style (monospace, small font, dark color).
Spec
spec/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.erb and tar_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.rb and 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.

โค๏ธ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Oct 06 '25 20:10 coderabbitai[bot]