Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed LTI duplicate roster error #2213

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +556 to +559
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider improving the warning display mechanism

The new warning system is a good addition, but there are a few points to consider:

  1. Using flash[:error] for warnings might be confusing. Consider using flash[:warning] instead to differentiate between errors and warnings.
  2. Joining warning messages with '\n' might not render properly in HTML. Consider using <br> for line breaks or formatting the warnings as an HTML list.
  3. The success message is still displayed even when there are warnings. Consider adjusting the logic to provide a more nuanced feedback.

Here's a suggested improvement:

if @roster_warnings.present?
  flash[:warning] = "Roster uploaded with warnings:"
  flash[:warning] += "<ul>"
  @roster_warnings.keys.each do |warning|
    flash[:warning] += "<li>#{warning}</li>"
  end
  flash[:warning] += "</ul>"
  flash[:partial_success] = "Roster updated, but with some warnings. Please review."
else
  flash[:success] = "Successfully updated roster!"
end
flash[:html_safe] = true

This change separates warnings from errors, formats the warnings as an HTML list, and provides a more accurate success message.

redirect_to(action: "users") && return
rescue StandardError => e
if e != "Roster validation error"
Expand Down Expand Up @@ -798,6 +802,7 @@ def categorize_courses_for_listing(courses)
def write_cuds(cuds)
rowNum = 0
rosterErrors = {}
rosterWarnings = {}
20wildmanj marked this conversation as resolved.
Show resolved Hide resolved
rowCUDs = []
duplicates = Set.new

Expand Down Expand Up @@ -863,7 +868,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(
Expand Down Expand Up @@ -945,13 +950,15 @@ 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]}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add that this duplicate email was ignored / which line the duplicate email was on?

if !rosterWarnings.key?(msg)
rosterWarnings[msg] = []
end
rosterErrors[msg].push(cud)
rosterWarnings[msg].push(cud)
end

@roster_warnings = rosterWarnings

return if rosterErrors.empty?

@roster_error = rosterErrors
Expand Down