CSC/ECE 517 Spring 2024 - E2404 Refactor student teams functionality

From Expertiza_Wiki
Revision as of 20:20, 24 March 2024 by Mainamp (talk | contribs)
Jump to navigation Jump to search

This page provides details about Expertiza Issue E2404. "Refactor student_teams functionality" which is an OSS project in CSC517 Spring 2024.

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 OODD class is a user in expertiza, and instructors can add users as participants in an assignment so that they can access it. Almost everything within Assignments is done by participants, not users. That is, everything except teams_users. In the documentation, it can be noted that the team_users table references users instead of participants. This anomaly causes problems with how student teams are rendered in the UI, and it doesn’t go well with the new functionality that was recently introduced.

Requirements

Changing the schema

  • Rename the table table teams_users to teams_participants
  • Create a column that would be called “participant_id”, which will be a foreign key that references participants table
  • Create a migration that fetches the assignment_id for each tuple from the teams table.
  • Find out all the places where user_id is being used, refactor those so that participant_id is used.

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

  • The logic in the team's view that iterates and fetches information of all the team members and displays them would be refactored so that it matches our new design.
  • The new changes should not break the view that works for data where things are populated with user_id. Hence best approach is separate the older functionality into a separate partial and code the new functionality into a separate partial.
  • All the teams are being formed with participant_id instead of user_id

Other Changes

  • Update logic for all the crud functionalities in teams_users controller
  • Rename the teams_users_controller to teams_participants_controller
  • Some code where sql queries are written to fetch data, should be replaced with fetching data from rails ActiveRecord methods.
  • The html.erb files have extensive ruby code written for fetching data from the database. This code should be removed from the view files and placed into helper classes.
  • Extensive test cases should be present for all the code that is written.

Schema Changes

Here's a brief overview of the key changes we implemented:

  • Table Renaming: Our schema initially included a teams_users table, which, upon review, seemed misaligned with our domain model. To better represent the relationship between teams and participants, we decided to rename this table to teams_participants. GitHub Commit
  • Introduction of participant_id: To establish a more direct linkage between team participations and individual participants, we added a participant_id column to the newly named teams_participants table. This column serves as a foreign key that references the participants table, clearly defining the relationship. GitHub Commit
  • Populating participant_id column: The centerpiece of our refactor was the migration designed to populate the new participant_id column with accurate data. Leveraging the existing assignment_id from the teams table and user_id from the teams_participants table, our migration carefully matched each team participation to its corresponding participant and updated the participant_id accordingly.GitHub Commit

ER diagram for updated schema

Refactoring teams rendering

The objective of this refactoring task is to improve the readability, maintainability, and scalability of the code responsible for rendering team information in the view.html.erb file of the student_teams view. This refactoring involves separating existing functionality into specific partials and ensuring compatibility with the new data structure using participant_id instead of user_id. It's crucial to ensure that these changes do not break existing functionality that relies on user_id data. By separating old and new functionalities into distinct partials and conducting a data migration, the codebase will become more organized and adaptable, facilitating future development efforts. GitHub Commit

Refactor Implementation

we have successfully refactored the 'view.html.erb' file in the student_teams view to enhance readability and maintainability. The original code was cluttered, making it challenging to understand and extend. Through modularization, we have simplified the code by introducing partials, resulting in a more organized structure.

The following partials were created as part of the refactoring process:

  1. '_invited_people.html.erb' : This partial is responsible for displaying invited participants to the assignment team.
  2. '_display_advertisements.html.erb' : This partial handles the display of advertisements within the view.
  3. '_send_invitations.html.erb': This partial implements the functionality for sending invitations to team members.
  4. '_received_invitations.html.erb': This partial is used to display received invitations for the current user.

These partials contribute to a cleaner and more manageable codebase, improving the overall developer experience and facilitating future updates to the Expertiza application.

Implementation

Main files which were changed are

Models:

  • app/models/teams_participant.rb

Test Plan

Manual Testing

After implementing changes in 'teams_users', it's essential to reassess the flows and user stories involving its usage. This entails manually examining various pathways through which a team for an assignment can be created in Expertiza, along with associated operations like removing a user from a team, adding a new user, deleting a team, and so forth. This testing phase is crucial to verify that Expertiza's functionality remains intact and operates as expected post-refactoring.

The primary user stories we examined include:

  1. Student Creates a Team:
  • First, the student navigates to the assignments section in their view.
  • Then, they select a specific assignment and access the "Your Team" page.
  • On this page, they input a team name and confirm by clicking the "Name Team" button.
  1. Student Sends Invitations to Other Students:
  • After successfully creating a team, the student proceeds to send invitations to other students.
  • They input the usernames of the desired recipients and send invitations by clicking on the "Invite" button.
  1. Student Joins a Team:
  • In the recipient student's Expertiza view, they will see a notification or invitation indicating that they have been invited to join a team.
  • They navigate to the relevant assignment and locate the invitation.
  • Finally, they accept the invitation to join the team.


Team Members

  1. Meghana Chowdary Ainampudi (mainamp@ncsu.edu)
  2. Sai Abhigna Tummala (stummal5@ncsu.edu)
  3. Parshav Gandhi (pjgandh3@ncsu.edu)

Mentor: Ananya Mantravadi

Code Details

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

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