Skip to content

Conversation

@americac
Copy link
Collaborator

@americac americac commented Jan 8, 2026

Closes #943

This PR implements CSV bulk import functionality for Students in the new admin interface (/admin-new/students), matching the behavior of the existing admin import system.


Changes Made

Routes (config/routes.rb)

  • Added POST /admin-new/students/import route for CSV file uploads
  • Added GET /admin-new/students/template route for downloading CSV template

Controller (app/controllers/admin_v2/students_controller.rb)

  • New Actions:
    • import - Handles CSV file upload, validates file presence/format, processes imports via BulkStudentImportService
    • template - Generates and downloads CSV template file
  • Helper Methods:
    • redirect_with_missing_file_error - Handles missing file validation
    • redirect_with_import_results - Processes and displays import results
      - redirect_with_no_results_error - Handles empty CSV files
    • partition_results - Separates results into created/skipped/failed categories
    • build_success_messages - Builds user-friendly success messages
    • build_created_message - Formats created student messages with usernames
    • build_skipped_message - Formats skipped student messages
    • redirect_with_mixed_results - Handles partial success scenarios with both success and error flash messages

View (app/views/admin_v2/students/index.html.erb)

  • Added "Template" button to download sample CSV
  • Added "Import Students" button to open import modal
  • Added professional Tailwind-styled modal with:
    • File upload field (.csv files only)
    • CSV requirements displayed: classroom_id, username
    • Cancel and Import buttons
    • Close button and background overlay dismiss

Tests (test/controllers/admin_v2/students_controller_test.rb)

  • Added 10 comprehensive tests covering:
    • Template download functionality
    • Successful CSV imports
    • Duplicate username handling (skip existing)
    • Error reporting with line numbers
    • Missing file validation
    • Malformed CSV handling
    • Empty CSV handling
    • Mixed success/error scenarios
    • Authorization (admin-only access)

Configuration (.gitignore)

  • Added .DS_Store and **/.DS_Store to prevent macOS metadata files from being tracked

Features

✅ CSV Template Download - One-click download of properly formatted CSV template
✅ Bulk Student Import - Upload CSV files to create multiple students at once
✅ Smart Duplicate Handling - Automatically skips existing usernames
✅ Detailed Error Reporting - Shows specific line numbers and error messages for failed imports
✅ Partial Success Support - Displays both success and error messages when some students succeed and others fail
✅ CSV Format Validation - Detects and reports malformed CSV files
✅ Admin-Only Access - Import and template features restricted to admin users
✅ Professional UI - Modern Tailwind-styled modal matching admin_v2 design system


CSV Format

classroom_id,username
1,student001
1,student002
2,student003

Required columns: classroom_id, username


Testing

  • Manual testing completed with sample CSV files
  • All edge cases verified (empty files, malformed CSV, invalid data, duplicates)
  • Error messages display correctly with line numbers
  • Success messages show created usernames

Sample import file included: student_import_sample.csv (10 students across 2 classrooms)


Statistics

  • 5 files changed
  • 299 insertions
  • 0 deletions

Screenshots

Screenshot 2026-01-07 at 9 06 21 PM Screenshot 2026-01-07 at 9 06 28 PM

@americac americac requested a review from pollygee January 8, 2026 03:07
@americac americac force-pushed the issue-944_edit-portfolio-from-student branch from 05cf629 to c9b71e8 Compare January 8, 2026 03:08
@americac americac force-pushed the issue-943_admin-student-bulk-import branch from 3129d7e to 29f42cc Compare January 8, 2026 03:09
Base automatically changed from issue-944_edit-portfolio-from-student to main January 8, 2026 03:14
@americac americac force-pushed the issue-943_admin-student-bulk-import branch from 29f42cc to 9617ed1 Compare January 8, 2026 03:15
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.

2 participants