@@ -635,9 +635,17 @@ def import_users_from_csv(file)
635635 end
636636
637637 # Check if these headers should be processed by institution file or from DF format
638+ # Asking "Who will convert the users to the right format?"
639+ # If these are "institution formatted"? then use import settings from institution settings
640+ # Which contain:
641+ # - function to check if row is missing header values
642+ # - function to convert row to hash in the required format
643+ # - booleans for replacing tutorial/campus if different
638644 if Doubtfire ::Application . config . institution_settings . are_headers_institution_users? csv . headers
645+ logger . debug 'Importing users using institution\'s import settings'
639646 import_settings = Doubtfire ::Application . config . institution_settings . user_import_settings_for ( csv . headers )
640647 else
648+ logger . debug 'Importing users using default import settings'
641649 if tutorial_streams . count > 0
642650 stream_names = tutorial_stream_abbr . map { |abbr | abbr . downcase }
643651 else
@@ -759,7 +767,17 @@ def sync_enrolment_with(enrolment_data, import_settings, result)
759767 if changes . key? username
760768 if row_data [ :enrolled ] # they should be enrolled - record that... overriding anything else
761769 # record previous row as ignored
762- ignored << { row : changes [ username ] [ :row ] , message : "Skipping duplicate role - ensuring enrolled" }
770+ ignored_entry = { row : changes [ username ] [ :row ] , message : 'Skipping duplicate role - ensuring enrolled.' }
771+
772+ # Allocate+ csv data may have duplicate student rows for each tutorial enrolment
773+ # We need to combine the tutorials from both rows so that the student is enrolled into each tutorial
774+ if import_settings [ :merge_tutorials_for_duplicate_students ] && changes [ username ] [ :tutorials ] &.any?
775+ row_data [ :tutorials ] ||= [ ]
776+ row_data [ :tutorials ] . concat ( changes [ username ] [ :tutorials ] )
777+ ignored_entry [ :message ] += ' Merged tutorial enrolments.'
778+ end
779+
780+ ignored << ignored_entry
763781 changes [ username ] = row_data
764782 else
765783 # record this row as skipped
0 commit comments