Add student import to new admin students page #989
+299
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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)POST /admin-new/students/importroute for CSV file uploadsGET /admin-new/students/templateroute for downloading CSV templateController (
app/controllers/admin_v2/students_controller.rb)BulkStudentImportServiceredirect_with_missing_file_error- Handles missing file validationredirect_with_import_results- Processes and displays import results-
redirect_with_no_results_error- Handles empty CSV filespartition_results- Separates results into created/skipped/failed categoriesbuild_success_messages- Builds user-friendly success messagesbuild_created_message- Formats created student messages with usernamesbuild_skipped_message- Formats skipped student messagesredirect_with_mixed_results- Handles partial success scenarios with both success and error flash messagesView (
app/views/admin_v2/students/index.html.erb)Tests (
test/controllers/admin_v2/students_controller_test.rb)Configuration (
.gitignore)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
Sample import file included: student_import_sample.csv (10 students across 2 classrooms)
Statistics
Screenshots