From 234f8e379535ea042e64d26755a6a860fb87660f Mon Sep 17 00:00:00 2001 From: coder6583 Date: Sun, 22 Sep 2024 13:24:52 -0400 Subject: [PATCH 1/2] Filters out duplicate user --- app/controllers/courses_controller.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index fb5a0371d..6f4b2e769 100755 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -798,6 +798,7 @@ def categorize_courses_for_listing(courses) def write_cuds(cuds) rowNum = 0 rosterErrors = {} + rosterWarnings = {} rowCUDs = [] duplicates = Set.new @@ -863,7 +864,7 @@ def write_cuds(cuds) new_cud.delete(:year) # Build cud - if !user.nil? + if !user.nil? && !existing cud = @course.course_user_data.new cud.user = user params = ActionController::Parameters.new( @@ -945,11 +946,11 @@ def write_cuds(cuds) rowCUDs.each do |cud| next unless duplicates.include?(cud[:email]) - msg = "Validation failed: Duplicate email #{cud[:email]}" - if !rosterErrors.key?(msg) - rosterErrors[msg] = [] + msg = "Warning : Duplicate email #{cud[:email]}" + if !rosterWarnings.key?(msg) + rosterWarnings[msg] = [] end - rosterErrors[msg].push(cud) + rosterWarnings[msg].push(cud) end return if rosterErrors.empty? From 2fb8c46e5ae989268b8742fc547ec6f529aa71ab Mon Sep 17 00:00:00 2001 From: coder6583 Date: Sun, 22 Sep 2024 13:48:14 -0400 Subject: [PATCH 2/2] show warning message --- app/controllers/courses_controller.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 6f4b2e769..50444a018 100755 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -553,6 +553,10 @@ def upload_roster begin save_uploaded_roster flash[:success] = "Successfully updated roster!" + unless @roster_warnings.nil? + w = @roster_warnings.keys.join('\n') + flash[:error] = w + end redirect_to(action: "users") && return rescue StandardError => e if e != "Roster validation error" @@ -953,6 +957,8 @@ def write_cuds(cuds) rosterWarnings[msg].push(cud) end + @roster_warnings = rosterWarnings + return if rosterErrors.empty? @roster_error = rosterErrors