CSC/ECE 517 Fall 2022 - E2263.Refactor student teams functionality

From Expertiza_Wiki
Revision as of 14:55, 26 October 2022 by Nmadams (talk | contribs)
Jump to navigation Jump to search

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.

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

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 [In Progress]
  • when user is deleted it deletes the user and redirects to Teams#list page [In Progress]
  • when selected users are deleted it deletes the selected users and redirects to Teams#list page [In Progress]

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: In-Progress

Helper: In-Progress

Controllers: In-Progress

Team Members

  1. Sahithi Ammana (sammana@ncsu.edu)
  2. Nagaraj Madamshetti (nmadams@ncsu.edu)
  3. 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