E1829 OSS project Duke Blue Fix import glitches

From Expertiza_Wiki
Jump to navigation Jump to search

This wiki page is for the description of changes made to Fix import glitches.

Background

The import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc. from their learning management system. Being able to import these into expertiza saves a lot of time when setting up an assignment.


Issues Resolved

  • Issue #329: When importing teams there are different options to handle conflicting team names. We added an option rename EXISTING team when a conflict exists.

  • Issue #328: When importing teams, and a conflict exists there is an option to merge the two teams by inserting the new members into an existing team.

  • Issue #181: If one attempts to import users or participants, and does not specify the file to import from, a NoMethodError error occurs. the error has been handled by validating the file before importing the teams, thus the file needs to mandatorily be uploaded in order to import team.

Implementation

Issue #328

  1. We search the database to see if there is an existing team with the same name. In such a case we save the old team in the ‘team’ variable and set the team_exists flag to true.
  2. We then cal the handle_dups method which handles the case if value chosen by the user is ‘insert into existing team’, inside the code this value is represented as ‘insert’.
  3. Then the import_team_members function is called
  4. We get the user through his/her name
  5. If a user isn’t registered, we get a nil object and raise an ImportError
  6. Else we add the user to the team if he/she isn’t already in the team
  7. The add_member function only works till the team isn’t filled to its maximum capacity

Issue 329

  1. We included a new option in the duplicate handler field.
  2. We added a new handler in the handleDuplicates method to handle the given option as shown in the below screenshot.
  3. We leveraged the existing generateTeam() method and sent the existing team id to this method and replaced the existing team’s team name as follows:

Issue 181

  1. We validate the file before importing the teams. Thus,the file needs to mandatorily be uploaded in order to import team.


Code Snippet


Issue #329 In file app/models/team.rb

     if handle_dups == "rename_existing" # rename: rename existing team
       if teamtype.is_a?(CourseTeam)
        team.update(name:self.generate_team_name(Course.find(id).name)) # update the old team name
      elsif  teamtype.is_a?(AssignmentTeam)
        team.update(name:self.generate_team_name(Assignment.find(id).name)) # update the old team name
      end
      #team.update(name:self.generate_team_name(Assignment.find(id).name))
      return name # send the new team name
    end

Issue #328 In file app/models/team.rb

 if handle_dups=="insert"
      team.import_team_members(row_hash)
      return nil

def import_team_members(starting_index = 0, row_hash)
    starting_index
    index = 0
    row_hash[:teammembers].each do |teammember|
      next if index < starting_index # not sure this will work, hash is not ordered like array
      user = User.find_by(name: teammember.to_s)
      if user.nil?
        raise ImportError, "The user '#{teammember.to_s}' was not found. <a href='/users/new'>Create</a> this user?"
      else
        add_member(user) if TeamsUser.find_by(team_id: id, user_id: user.id).nil?
      end
      index += 1
    end
  end