CSC/ECE 517 Fall 2022 - E2263.Refactor student teams functionality
This page contains information about Expertiza Issue E2263. Refactor student teams functionality which is a project in CSC517 Fall 2022.
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 works within Assignments is done by participants, not users. All the tables use participant_id to track contributions to assignments, except teams_users. In the documentation, it can be noted that 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.
So, to give a breif information about this change, instead of using the user_id in the teams_users table to manage the student teams, we renamed the latter table to teams_participants with a new column named participant_id which will be used to manage the student teams and which supports new funtionality going forward. And splitted bolated and lengthy code to partials and implemented it in multiple files.Implemented creational Singleton design pattern to ensure only one instance.
Requirements
Changes to the schema:
We renamed the table table teams_users to teams_participants
Created a column that would be called “participant_id”, which will be a foreign key that references participants table.
Created a migration that fetches the assignment_id for each tuple from the teams table. We would find the participant with the help of the assignment_id we just got from the teams table and the user_id that is already present in the current table, and store its “id” in the participant_id column we created in the last step. You have to come with optimal migration strategy that reliably calculates the participant_id
Found out all the places where user_id is being used, refactored those so that participant id is used.
Got rid of the user_id column.
Refactoring the teams rendering
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 are be refactored so that it matches our new design.
Migration is executed to calculate participant_id and update in the table.
Made partials and placed bloated functionality in their specific partials.
The new changes do not break the view that works for data where things are populated with user_id.
Other Changes
Updated logic for all the CRUD functionalities in teams_users controller (wherever applicable).
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 added a new column participant_id which is a foreign key from participants table and remove the column user_id. We removed the user_id column only after data migration since the user_id field is used predominantly in several other controllers in a variety of ways, and as such its removal must be done carefully.
The participant_id field in the the teams_users relation is computed as follows:
- Finding Assignment ID By Team ID
The teams_users 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
- app/models/participant.rb
- app/models/team.rb
- app/models/teams_participant.rb
- app/models/user.rb
Currently teams_participant table has user_id or participant_id for now. So we've ensured that checks happen based on both the IDs unless user_id is removed.
addParticipantIdToTeamsParticipant
This migration helps in populating the participant_id column in the teams_participant table.
Analysis
user_id exists as a foreign key in 2 relations - Participants and teams_participant. 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 E2263 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_participants_controller.rb (expertiza/app/controller/teams_participants_controller.rb)
Added code here to compute the participant_id using the methodologies described above.
- teams_participant.rb (expertiza/app/models/teams_participant.rb)
The model is be updated (as can be seen in the ER diagram above) to have the participant_id added.
- teams_participants(expertiza/app/views/teams_participants)
The view is updated to reflect the new name of the model, and contain new partials that make use of the participant_id field.
- teams_participants_controller_spec.rb(expertiza/spec/controllers/teams_participants_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_participant means we need to re-examine the flows and user stories through where teams_participant 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.
5. Instructor will be able to manage the assignments in several ways like creating a team, add participants, edit assignment, delete assignment from the course, copy the assignment, assign reviewers, view submissions, view scores and view reports.
6. Instructor will be able to see the list of teams in any given project. The instructor will be able to add, delete and edit teams.
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_participants_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
- when user is added to assignment team it throws error when assignmentTeam has maximum number of participants
- when user is deleted it deletes the user and redirects to Teams#list page
- when selected users are deleted it deletes the selected users and redirects to Teams#list page
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 few 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.
Team Members
- Sahithi Ammana (sammana@ncsu.edu)
- Nagaraj Madamshetti (nmadams@ncsu.edu)
- Tyler Craine (tcraine@ncsu.edu)
Mentor: Naman Shrimali
Code Details
Github Pull Request - https://github.com/expertiza/expertiza/pull/2467
Repo - https://github.com/SahithiAmmana/expertiza
Demo - CREDENTIALS:
username: instructor6 password: password