CSC/ECE 517 Spring 2023 - E2304 Refactor student teams functionality

From Expertiza_Wiki
Jump to navigation Jump to search

This page contains information about Expertiza Issue E2304. Refactor student teams functionality which was a project in CSC517 Spring 2023.

Please see below for a description of the design of the project.

Background

The Expertiza project is software to create reusable learning objects through peer review. It also supports team projects, and the submission of almost any document type, including URLs and wiki pages.

Users & Participants: Everyone who took the CSC517 OODD class at NC State is a user in Expertiza, and instructors can add users as participants in an assignment so that they can access it to contribute, make changes and submit their work to be graded.

Almost all of the work within Assignments is done by participants, not users. All the tables use participant_id to track contributions to assignments, except teams_users. The team_users table references users instead of participants. This anomaly in the teams_users relation causes problems with how student teams are rendered in the UI, and it doesn’t mix well with the new functionality that was recently introduced. The participant_id field should be added to the model, and references that use user_id should also incorporate participant_id. Ideally, the application should use only participant_id, but to handle the existing data in the database without running a massive migration, the application should be able to handle both old records that use user_id and new ones that shall, from after this project is completed, use participant_id instead.

Requirements

Changing the schema

  • Create a column that would be called “participant_id”, which will be a foreign key that references the participants table.
  • Use this participant_id field in all operations for teams going forward. There are a number of workflows involving teams we have examined and worked on, which are elaborated below.
  • However, it is to be noted that this must also work with the existing functionality and data which makes use of user_id, so the code written must take both into account in its working.

Refactoring the teams rendering (/views/student_teams/view.html.erb)

The logic in the team's view (where participants can see their team members) that iterates and fetches information of all the team members and displays them would be refactored as this view is quite bloated and has lots of functionalities written on it. We have made partials and placed those functionality in their specific partials.

Other Changes

Fixed tests to incorporate the new logic as a result of using both user_id and participant_id in the teams_user logic.

Schema Changes

In teams_users table, we can add a new column participant_id which is a foreign key from participants table . Since the user_id field is used predominantly in several other controllers in a variety of ways, we cannot remove the user_id column without major changes in the application. After performing migration changes to populate the participant_id, we found that there were multiple rows in the teams_participants (earlier teams_users) table which did not have any participant id linked to it. This seems to be a data inconsistency issue in the database provided.

The participant_id field in the the teams_participants relation is computed as follows:

  • Finding Assignment ID By Team ID

The teams_participants table contains team_id, user_id and duty_id but not the participant_id. Since the same user_id can be associated with multiple participant_ids (since the same user can participate in multiple assignments and gets a unique participant_id in each assignment they take part in), we need to get the user_ids in the assignment for which we need the particular user's participant_id. For this reason, we need to first find the assignment_id.

  • Finding Participant ID By Assignment ID and User ID

With the assignment_id retrieved, we can find the list of participant_ids that participated in the assignment, and using the user_id, get the participant_id which is saved in the participants table.

ER diagram for updated schema

Implementation

Main files which were changed are

Controllers:

  • app/controllers/assessment360_controller.rb
  • app/controllers/grades_controller.rb
  • app/controllers/invitations_controller.rb
  • app/controllers/join_team_requests_controller.rb
  • app/controllers/lottery_controller.rb
  • app/controllers/pair_programming_controller.rb
  • app/controllers/popup_controller.rb
  • app/controllers/review_mapping_controller.rb
  • app/controllers/sign_up_sheet_controller.rb
  • app/controllers/students_teams_controller.rb
  • app/controllers/suggestion_controller.rb
  • app/controllers/teams_controller.rb
  • app/controllers/teams_participants_controller.rb (changes also include renaming from teams_users_controller to teams_participants_controller)
  • app/controllers/users_controller.rb

Helpers:

  • app/helpers/assignment_helper.rb
  • app/helpers/manage_team_helper.rb
  • app/helpers/review_mapping_helper.rb
  • app/helpers/sign_up_sheet_helper.rb
  • app/helpers/teams_participants_helper.rb (changes also include renaming from teams_users_helper to teams_participants_helper)

Mailers:

  • app/mailers/mail_worker.rb

Models:

  • app/models/assignment.rb
  • app/models/assignment_participant.rb
  • app/models/assignment_team.rb
  • app/models/cake.rb
  • app/models/course_team.rb
  • app/models/invitaiton.rb
  • app/models/lock.rb
  • app/models/mentor_management.rb
  • app/models/participant.rb
  • app/models/review_response_map.rb
  • app/models/sign_up_sheet.rb
  • app/models/sign_up_topic.rb
  • app/models/signed_up_team.rb
  • app/models/tag_prompt_deployment.rb
  • app/models/team.rb
  • app/models/team_user_node.rb
  • app/models/teams_participant.rb
  • app/models/user.rb

Views:

  • app/views/assignments/edit/_calibration.html.erb
  • app/views/bookmarks/list.html.erb
  • app/views/popup/participants_popup.html.erb
  • app/views/reports/_teammate_review_report.html.erb
  • app/response/response.html.erb
  • app/views/review_mapping/_list_review_mappings.html.erb
  • app/sign_up_sheet/show_team.html.erb
  • app/views/student_teams/_display_advertisements.html.erb
  • app/views/student_teams/_invited_people.html.erb
  • app/views/student_teams/_received_invitations.html.erb
  • app/views/student_teams/_select_duty_form.html.erb
  • app/views/student_teams/_send_invitations.html.erb
  • app/views/student_teams/_team_display.html.erb
  • app/student_teams/view.html.erb
  • app/submitted_content/_hyperlink.html.erb
  • app/_self_review.html.erb
  • app/teams_participants/_form.html.erb
  • app/teams_participants/_members.html.erb
  • app/teams_participants/list.html.erb
  • app/teams_participants/new.html.erb
  • app/views/tree_display/actions/_teams_actions.html.erb
  • app/views/tree_display/actions/_teams_participants_actions.html.erb
  • app/views/tree_display/actions/_teams_users_actions.html.erb

As the project tries to introduce participant_id as a replacement of user_id, we've calculated all the details with both user_id and participant_id (whichever is available based on whether the data is old or new). We've also added comments everywhere to show the code snippets which need to be removed once user_id is deprecated.


add_participant_to_team

The existing function to add a member

add_member(user,team.parent_id)

adds user to a team based on the user_id and team_id.

We've introduced a new function called

add_participant_to_team(student, team.parent_id)

which adds participant(student) to a team based on participant_id(or user_id wherever participant_id is not available)

This function takes participant and team_id, and assigns that participant to a team. In future, once user_id is removed, add_participant_to_team can be used as a replacement.

Analysis

user_id exists as a foreign key in 2 relations - Participants and teams_users. Although they correspond to same attribute, user_id alone cannot be used to find corresponding Participants because same user_id can exist for multiple Participants - due to Expertiza's design wherein for every assignment, every user is added to participant's table. Therefore Participant ID can be mapped to (assignment_id, user_id) pair.

View Changes and Refactoring

One of the requirements in E2243 is the refactoring of the student teams view in views/student_teams/view.html.erb

This view is quite cluttered and as a result, makes editing, understanding and extension difficult and tiresome for any future updates to the expertiza application. The code in this file can be modularized to obtain simpler and easier-to-understand, which is what we have achieved. The view was reafactored to incorporate partials, and some of the partials created as a result are:

  • _invited_people.html.erb : partial for displaying the invited participants to the assignment team
  • _display_advertisements.html.erb : partial for displaying advertisements in the view
  • _send_invitaions.html.erb : partial for the send invitations functionality
  • _received_invitations.html.erb : partial to display the received invitations for the current user

Please see the next sections for some screenshots of the UI related to the above described partials.

Impacted Files

  • teams_users_controller.rb (expertiza/app/controller/teams_user_controller.rb)

We will be adding code here to compute the participant_id using the methodologies described above.

  • teams_users.rb (expertiza/app/models/teams_user.rb)

The model will be updated (as can be seen in the ER diagram above) to have the participant_id added.

  • teams_users(expertiza/app/views/teams_users)

The view will be updated to reflect the new name of the model, and contain new partials that make use of the participant_id field.

  • teams_users_controller_spec.rb(expertiza/spec/controllers/teams_users_controller_spec.rb)

The test file for the controller will be modified so that existing test cases pass the new changes, and also introduce new test cases to increase test coverage.

Test Plan

Manual Testing

The changes in teams_users means we need to re-examine the flows and user stories through where teams_users is used. This, in practice, means that we manually have checked the different ways in which a team for an assignment can be created in expertiza, and other associated operations such as removal of a user from a team, addition of a new user, deletion of a team etc. This testing was necessary to ensure that the functionality in expertiza still worked as expected even after our refactoring was completed.

The main user stories we examined are:

1. Student creates a team: A student, newly added to an assignment, opens the application and goes to "my team" after opening the assignment on expertiza. He enters his team's name and the team is created.

2. Student joins a team: A student, is invited to join a team for an assignment, and accepts. He is added to an existing team, possibly created by another student or instructor.

3. Instructor creates a team manually: An instructor who wishes to create a team with certain students on it, chooses the assignment on expertiza, and clicks on the icon to add a new team and in the manual section, creates a new team by giving a team name. They add students or participants to the newly created team and can remove them too.

4. Instructor creates teams automatically: An instructor wishes to assign all the students involved in an assignment randomly to teams of a certain size. They open expertiza, choose the assignment, and then click on the icon to add a new team, and in the "create teams automatically" section, enter the team size they wish to use. The system then creates teams of the specified size, adding students randomly to teams which is reflected in both student and instructor views.

In addition to verifying team creation in all of the above scenarios, we also verified other operations such as addition of a team member after the team capacity was exhausted, deletion and re-addition of the same user, invitations to already existing participants in the same team etc and ensure the system was working as expected in these scenarios as well.

Automated Testing RSpec

Since this is a refactoring project, the scope of testing is limited to the changes made as part of refactoring and also to ensure that the existing test cases do not break or are modified accordingly. In all the existing test cases in expertiza/spec/controllers/teams_users_controller_spec.rb :

  • object initialization
  • #update_duties
  • when user is added to assignment team
  • when user is added to assignment team
  • when user is added to course team
  • when user is already on an assignment team
  • when user is added to assignment team while on a team already
  • when user is already on a course team

the new methods which use both participant_id and user_id have been incorporated as needed to ensure continued quality of the testing suite and maintenance of code coverage.

Fixed Test Files

After our refactoring, we noticed failing tests in the below files, and we have worked on fixing these to work with the new and updated functionality. The main issues were involving tests using the old methods for creating a team, adding participants to the team etc.

Models:

  • spec/models/assignment_team_spec.rb
  • spec/models/course_team_spec.rb
  • spec/models/invitation_spec.rb
  • spec/models/student_task_spec.rb
  • spec/models/team_spec.rb

Helper:

  • spec/helpers/authorization_helper_spec.rb
  • spec/helpers/grades_helper_spec.rb
  • spec/helpers/sign_up_sheet_helper_spec.rb

Controllers:

  • spec/controllers/student_teams_controller_spec.rb
  • spec/controllers/teams_participants_controller_spec.rb

Changes in controllers due to renaming TeamsUsers to TeamsParticipants:

  • spec/controllers/airbrake_exception_errors_controller_tests_spec.rb
  • spec/controllers/assessment360_controller_spec.rb
  • spec/controllers/grades_controller_spec.rb
  • spec/controllers/invitations_controller_spec.rb
  • spec/controllers/lottery_controller_spec.rb
  • spec/controllers/pair_programming_controller_spec.rb
  • spec/controllers/review_mapping_controller_spec.rb
  • spec/controllers/sign_up_sheet_controller_spec.rb
  • spec/controllers/suggestion_controller_spec.rb
  • spec/controllers/users_controller_spec.rb
  • spec/controllers/join_team_request_controller_spec.rb

Helpers:

  • spec/helpers/authorization_helper_spec.rb
  • spec/helpers/grades_helper_spec.rb

Factories:

  • spec/factories/factories.rb

Features:

  • spec/features/assignment_team_member_spec.rb

Models:

  • spec/models/assignment_spec.rb
  • spec/models/assignment_team_spec.rb
  • spec/models/course_spec.rb
  • spec/models/course_team_spec.rb
  • spec/models/participant_spec.rb
  • spec/models/team_spec.rb

Changes in controllers due to renaming TeamsUsers to TeamsParticipants:

  • spec/models/airbrake_expection_errors_unit_tests_spec.rb
  • spec/models/assignment_participant_spec.rb
  • spec/models/cake_spec.rb
  • spec/models/invitation_spec.rb
  • spec/models/lock_spec.rb
  • spec/models/review_response_map_spec.rb
  • spec/models/sign_up_sheet_spec.rb
  • spec/models/tag_prompt_deployment_spec.rb


Future Scope

  1. A lot of the functionality is interlinked with user id and can break on trying to make use of participant id. This is a huge change which needs proper planning because it affects multiple functions.
  2. Figure out a way to create a migration to compute the participant_id field for those rows in the teams_participants table that are null
  3. Remove the user_id column from the teams_users table.
  4. Modify functions which use user_id and replace them with functions using participant_id only

Team Members

  1. Tanvi Sinha (tsinha2@ncsu.edu)
  2. Shreya Maheshwari (smahesh4@ncsu.edu)
  3. Rishikesh Pravin Yelne (ryelne@ncsu.edu)

Mentor: Divyang Doshi

Code Details

Github Pull Request - https://github.com/expertiza/expertiza/pull/2531

Repo - https://github.com/ShreyaMaheshwari/expertiza

[1] contains detailed information on the previous team's work on this feature.