<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ppmanbhe</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ppmanbhe"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Ppmanbhe"/>
	<updated>2026-05-20T00:23:24Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=160540</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb (Phase 2 - Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=160540"/>
		<updated>2024-12-04T03:25:56Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: /* Sample Test Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class currently serves as a join model between Team and Participant classes, managing team memberships for assignments and courses. However, it creates an architectural inconsistency by linking teams directly to users rather than participants, even though participants are the primary entities associated with assignments and courses throughout the rest of the application. The refactoring initiative will replace the TeamsUser class with a new TeamsParticipant class, bringing several key improvements:&lt;br /&gt;
&lt;br /&gt;
1. Align team management with the application's existing participant-based pattern.&lt;br /&gt;
&lt;br /&gt;
2. Creates proper associations between teams and participants within assignment contexts.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
The primary design goal is to improve the data model and overall architecture of the Expertiza application by replacing the TeamsUser class with a more appropriate TeamsParticipant class. This change aims to achieve the following objectives:&lt;br /&gt;
&lt;br /&gt;
1. '''Enhance Data Model Consistency:''' Modify the association between teams and users to reflect a more accurate relationship between teams and participants throughout the app.&lt;br /&gt;
&lt;br /&gt;
2. '''Simplify Application Logic:''' Align the team related management with the existing pattern of using Participant objects rather than User objects throughout the application, reducing exceptions and inconsistencies.&lt;br /&gt;
&lt;br /&gt;
3. '''Improve Code Maintainability:''' Refactor the codebase to use TeamsParticipant consistently, updating all relevant models, views, and controllers to reflect this change.&lt;br /&gt;
&lt;br /&gt;
4. '''Enhance Database Structure:''' Update the database schema to include appropriate foreign keys and indexes for the TeamsParticipant table, improving data integrity and query performance.&lt;br /&gt;
&lt;br /&gt;
5. '''Ensure Backward Compatibility:''' Implement the changes in phases, allowing for a gradual transition from TeamsUser to TeamsParticipant while maintaining functionality throughout the refactoring process.&lt;br /&gt;
&lt;br /&gt;
6. '''Improve Testability:''' Develop comprehensive test cases for the new TeamsParticipant model and update existing tests to reflect the changes in associations and logic.&lt;br /&gt;
&lt;br /&gt;
==Design Pattern==&lt;br /&gt;
&lt;br /&gt;
To manage the complexity and responsibilities of the TeamsParticipant class, the following design patterns can be applied here. Since TeamsParticipant is handling both join table duties and additional business logic, a combination of patterns could improve maintainability and flexibility.&lt;br /&gt;
&lt;br /&gt;
1. '''Facade Pattern''' for Simplifying Interface&lt;br /&gt;
&lt;br /&gt;
The TeamsParticipant class handles multiple responsibilities, from managing teams and participants to removing members and adding members who accepted invites. Applying the Facade Pattern can simplify its interface by offloading complex processes to service classes. For example, a TeamsParticipantService could manage team membership rules, while TeamsParticipantManager could handle table-related operations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
class TeamParticipantService&lt;br /&gt;
  def self.add_accepted_invitee_to_team(inviter_participant_id, invited_participant_id, assignment_id)&lt;br /&gt;
    participants_teams = TeamsParticipant.where(participant_id: inviter_participant_id)&lt;br /&gt;
    participants_teams.any? do |team|&lt;br /&gt;
      assigned_team = AssignmentTeam.find_by(id: team.team_id, parent_id: assignment_id)&lt;br /&gt;
      assigned_team&amp;amp;.add_member(Participant.find(invited_participant_id), assignment_id) if assigned_team&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.handle_pair_programming(team_id, user_id)&lt;br /&gt;
    user = TeamsParticipant.find_by(team_id: team_id, user_id: user_id)&lt;br /&gt;
    user.update_attributes(pair_programming_status: &amp;quot;A&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    TeamsParticipant.where(team_id: team_id).empty?&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, within TeamsParticipant, these actions could be delegated to the facade for simplicity and modularity:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
class TeamsParticipant &amp;lt; ApplicationRecord&lt;br /&gt;
  # Other associations and methods&lt;br /&gt;
  &lt;br /&gt;
  def self.add_accepted_invitee_to_team(*args)&lt;br /&gt;
    TeamParticipantService.add_accepted_invitee_to_team(*args)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. '''Repository Pattern''' for Database Queries&lt;br /&gt;
&lt;br /&gt;
The Repository Pattern would be useful for separating data access logic since this class is heavily querying the database for create, update, find operations. This involves creating a TeamsParticipantRepository that encapsulates all finders and queries, improving modularity and making it easier to test and reuse.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
class TeamsParticipantRepository&lt;br /&gt;
  def self.find_team_participant(participant_id, team_id)&lt;br /&gt;
    TeamsParticipant.find_by(participant_id: participant_id, team_id: team_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.first_participant_for_team(team_id)&lt;br /&gt;
    TeamsParticipant.find_by(team_id: team_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    TeamsParticipant.where(team_id: team_id).empty?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.find_team_id(assignment_id, user_id)&lt;br /&gt;
    TeamsParticipant.find_team_id(assignment_id, user_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.get_team_participants(team_id)&lt;br /&gt;
    TeamsParticipant.where(team_id: team_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.get_participants_for_review(team_id)&lt;br /&gt;
    TeamsParticipant.where(team_id: team_id).each do |team_user|&lt;br /&gt;
      yield team_user&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Final design===&lt;br /&gt;
&lt;br /&gt;
The initial design proposed using the Facade and Repository patterns to improve the architecture of the TeamsParticipant refactoring. However, during implementation, we took a more direct approach for several reasons:&lt;br /&gt;
&lt;br /&gt;
1. '''Existing Code Structure:''' The codebase already had established patterns for controller-model interactions. The changes were made to align with these existing patterns, as seen in the invitation.rb and review_mapping_controller.rb modifications&lt;br /&gt;
&lt;br /&gt;
2. '''Minimal Benefit:''' The main goal was to fix the architectural inconsistency of teams being linked to users instead of participants. The proposed patterns would have added an extra layer of abstraction without providing &lt;br /&gt;
significant immediate benefits to this specific problem&lt;br /&gt;
&lt;br /&gt;
3. '''Future Considerations:''' While the Facade and Repository patterns could improve code organization and maintainability, they would be better implemented as part of a larger architectural refactoring effort. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Migration Strategy===&lt;br /&gt;
1. Create new TeamsParticipant model and table&lt;br /&gt;
&lt;br /&gt;
2. Implement parallel methods in TeamsParticipant&lt;br /&gt;
&lt;br /&gt;
3. Update controllers to use TeamsParticipant&lt;br /&gt;
&lt;br /&gt;
4. Migrate existing data&lt;br /&gt;
&lt;br /&gt;
5. Remove TeamsUser dependencies&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
[[File:ClassDiagram_TeamsParticipant.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
==Sequence Diagram==&lt;br /&gt;
[[File:SequenceDiagram_TeamsParticipant.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
==Solutions/Details of Changes Made==&lt;br /&gt;
&lt;br /&gt;
===Phase 1 Improvements===&lt;br /&gt;
&lt;br /&gt;
* Renamed TeamsUser to TeamsParticipant to modify application logic to join Teams with Participants instead of Users&lt;br /&gt;
* Updated associations in immediate neighbor classes i.e Teams, Users and Participants to ensure correctness and consistency in the data model&lt;br /&gt;
* Renamed method names for increased readability and removed redundant methods from the TeamsParticipant class&lt;br /&gt;
* Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity, improving overall maintainability of the codebase&lt;br /&gt;
* Renamed TeamUserNode to TeamParticipantNode for correctness, to align with the new design of Participation association in TeamsParticipant&lt;br /&gt;
* Added migrations to add foreign key for Participant in TeamsParticipant table and updated indexes for the same&lt;br /&gt;
&lt;br /&gt;
===Phase 2 Plan===&lt;br /&gt;
&lt;br /&gt;
* Update associations in all the models that were previously using TeamsUser to implement them with TeamsParticipant&lt;br /&gt;
* Modify implementations of all models, views, and controllers to use Participant with TeamsParticipant class instead of User&lt;br /&gt;
* This future involves modifying queries to retrieve participant and user objects that are passed to the TeamsParticipant class as commands to their methods&lt;br /&gt;
* Deprecate user_id foreign key from TeamsParticipant to completely remove the association of User from TeamsParticant, only linking Participants to Teams&lt;br /&gt;
* Update all the test cases to work with this implementation, including updating associations and mocking DB calls&lt;br /&gt;
&lt;br /&gt;
==Files Added/Modified==&lt;br /&gt;
&lt;br /&gt;
As part of the refactoring process, we need to update all references and method calls related to the TeamsParticipant table and the teams_participant class throughout the repository. This refactor will involve over 200 instances across various files.&lt;br /&gt;
&lt;br /&gt;
===Affected Components===&lt;br /&gt;
&lt;br /&gt;
   Models: &lt;br /&gt;
   1. course_team.rb&lt;br /&gt;
   2. mentor_management.rb&lt;br /&gt;
   3. mentored_team.rb&lt;br /&gt;
   4. review_response_map.rb&lt;br /&gt;
   5. signed_up_team.rb&lt;br /&gt;
   6. tag_prompt_deployment.rb&lt;br /&gt;
   7. invitation.rb&lt;br /&gt;
&lt;br /&gt;
   Controllers: &lt;br /&gt;
   1. assessment360_controller.rb&lt;br /&gt;
   2. grades_controller.rb&lt;br /&gt;
   3. join_team_requests_controller.rb&lt;br /&gt;
   4. lottery_controller.rb&lt;br /&gt;
   5. popup_controller.rb&lt;br /&gt;
   6. sign_up_sheet_controller.rb&lt;br /&gt;
   7. student_teams_controller.rb&lt;br /&gt;
   8. suggestion_controller.rb&lt;br /&gt;
   9. review_mapping_controller.rb&lt;br /&gt;
   10. pair_programming_controller.rb&lt;br /&gt;
&lt;br /&gt;
   Helpers/Workers:&lt;br /&gt;
   1. assignment_helper.rb&lt;br /&gt;
   2. manage_team_helper.rb&lt;br /&gt;
   3. review_mapping_helper.rb&lt;br /&gt;
   4. sign_up_sheet_helper.rb&lt;br /&gt;
   5. teams_users_helper.rb&lt;br /&gt;
   6. mail_worker.rb&lt;br /&gt;
&lt;br /&gt;
   Views:&lt;br /&gt;
   1. assignments/edit/_calibration.html.erb&lt;br /&gt;
   2. bookmarks/list.html.erb&lt;br /&gt;
   3. popup/participants_popup.html.erb&lt;br /&gt;
   4. reports/_teammate_review_report.html.erb&lt;br /&gt;
   5. response/response.html.erb&lt;br /&gt;
   6. review_mapping/_list_review_mappings.html.erb&lt;br /&gt;
   7. sign_up_sheet/show_team.html.erb&lt;br /&gt;
   8. student_teams/_received_invitations.html.erb&lt;br /&gt;
   9. student_teams/view.html.erb&lt;br /&gt;
   10. submitted_content/_hyperlink.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The required changes will follow the pattern shown in the attached modifications for models and controllers.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''invitation.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Invitation_model_changes.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''review_mapping_controller.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review_mapping_controller_changes2.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''pair_programming_controller.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Pair_programming_controller_changes.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
We added a new spec file for the teams_participant model, which was previously missing, and fixed issues in the team_participant_controller_spec. Additionally, we resolved model and controller tests for direct associations with Team, User, and Participant.&lt;br /&gt;
&lt;br /&gt;
===Detailed '''Test Plan''' for &amp;lt;code&amp;gt;TeamsParticipant&amp;lt;/code&amp;gt; Model===&lt;br /&gt;
&lt;br /&gt;
The test plan for the TeamsParticipant refactoring will verify both the model's core functionality and its integration with the invitation and review mapping systems.&lt;br /&gt;
&lt;br /&gt;
'''Test 1.''' Associations&lt;br /&gt;
&lt;br /&gt;
 Verify correct associations:&lt;br /&gt;
  * Belongs to participant&lt;br /&gt;
  * Belongs to team&lt;br /&gt;
  * Has one team_participant_node (dependent: destroy)&lt;br /&gt;
&lt;br /&gt;
'''Test 2.''' Method: &amp;lt;code&amp;gt;#name&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  Returns participant’s name.&lt;br /&gt;
  Appends &amp;quot;(Mentor)&amp;quot; if participant is a mentor.&lt;br /&gt;
&lt;br /&gt;
'''Test 3.''' Method: &amp;lt;code&amp;gt;#delete&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Calls methods for cleanup:&lt;br /&gt;
  * remove_team_participant_node&lt;br /&gt;
  * remove_team_if_participants_empty&lt;br /&gt;
  * remove_teams_participant_instance&lt;br /&gt;
 Destroys itself and associated TeamParticipantNode.&lt;br /&gt;
 Deletes the team if it’s the last participant.&lt;br /&gt;
&lt;br /&gt;
'''Test 4.''' Method: &amp;lt;code&amp;gt;.remove_participant&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Destroys TeamsParticipant if it exists.&lt;br /&gt;
 Does nothing if it doesn’t exist.&lt;br /&gt;
&lt;br /&gt;
'''Test 5.''' Method: &amp;lt;code&amp;gt;.first_participant_for_team&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Retrieves the first participant for a given team ID.&lt;br /&gt;
&lt;br /&gt;
'''Test 6.''' Method: &amp;lt;code&amp;gt;.team_empty?&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Returns true if team has no participants; false otherwise.&lt;br /&gt;
&lt;br /&gt;
'''Test 7.''' Method: &amp;lt;code&amp;gt;.add_accepted_invitee_to_team&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Adds a participant to the team, returning true if successful.&lt;br /&gt;
&lt;br /&gt;
'''Test 8.''' Method: &amp;lt;code&amp;gt;.team_id&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Returns team ID if participant is assigned to a team.&lt;br /&gt;
 Returns nil if not assigned.&lt;br /&gt;
&lt;br /&gt;
===Model Tests===&lt;br /&gt;
&lt;br /&gt;
  describe '.remove_participant' do&lt;br /&gt;
    before do&lt;br /&gt;
      allow(TeamsParticipant).to receive(:find_by).with(user_id: user.id, team_id: team.id).and_return(team_participant)&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team participant exists' do&lt;br /&gt;
      it 'destroys the team participant' do&lt;br /&gt;
        expect(team_participant).to receive(:destroy)&lt;br /&gt;
        TeamsParticipant.remove_team_participant(user.id, team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team participant does not exist' do&lt;br /&gt;
      before do&lt;br /&gt;
        allow(TeamsParticipant).to receive(:find_by).with(user_id: user.id, team_id: team.id).and_return(nil)&lt;br /&gt;
      end&lt;br /&gt;
  &lt;br /&gt;
      it 'does not call destroy' do&lt;br /&gt;
        expect(team_participant).not_to receive(:destroy)&lt;br /&gt;
        TeamsParticipant.remove_team_participant(user.id, team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
===Integration Tests===&lt;br /&gt;
&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    context 'when team with given id that exists' do&lt;br /&gt;
      it 'successfully returns the team with the given team id' do&lt;br /&gt;
        allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
        request_params = { id: team1.id }&lt;br /&gt;
        user_session = { user: ta }&lt;br /&gt;
        result = get :edit, params: request_params, session: user_session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when team with given id does not exist' do&lt;br /&gt;
      it 'raises an ActiveRecord::RecordNotFound error' do&lt;br /&gt;
        expect {&lt;br /&gt;
          get :edit, params: { id: 999 }, session: { user: ta }&lt;br /&gt;
        }.to raise_error(ActiveRecord::RecordNotFound)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== UI Testing===&lt;br /&gt;
&lt;br /&gt;
1. Created a new team for an assignment, sent an invite to another user and successfully accepted the invite, and added another user to the team, demonstrating the working of team-participants&lt;br /&gt;
&lt;br /&gt;
[[File:TeamsParticipantUIDemo.png|800px|center|border|]]&lt;br /&gt;
&lt;br /&gt;
2. Added a participant to an existing course&lt;br /&gt;
&lt;br /&gt;
[[File:CourseParticipantUIdemo.png|800px|center|border|]]&lt;br /&gt;
&lt;br /&gt;
===Sample Test Changes===&lt;br /&gt;
&lt;br /&gt;
We went ahead with updating all the table references as needed, adjusting or adding mocks for methods, and revising database queries involving the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
Below are examples of changes that were made to the 200 refrences across all models, controllers and views throughout the repository.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''invitation_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Invitation_spec1.png|800px|center|]]&lt;br /&gt;
[[File:Invitation_spec2.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''review_mapping_controller_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review_map_controller_spec.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''pair_programming_controller_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Pair_prog_controller_spec.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
===Test success===&lt;br /&gt;
&lt;br /&gt;
[[File:Test-Github-actions.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
==Final Pull Request==&lt;br /&gt;
&lt;br /&gt;
The PR to Expertiza repo can be found here: &lt;br /&gt;
&lt;br /&gt;
 [https://github.com/expertiza/expertiza/pull/2887 E2456. Refactor teams user.rb #2887]&lt;br /&gt;
&lt;br /&gt;
==Project Demo==&lt;br /&gt;
&lt;br /&gt;
Click [https://vimeo.com/1035806635/f8dc0a1fc3 here] to view demo&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jay, Patel&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
# [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0OSS Projects on Expertiza]&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Github]&lt;br /&gt;
# [https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page Expertiza Wiki]&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Test-Github-actions.png&amp;diff=160538</id>
		<title>File:Test-Github-actions.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Test-Github-actions.png&amp;diff=160538"/>
		<updated>2024-12-04T03:24:41Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=160458</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb (Phase 2 - Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=160458"/>
		<updated>2024-12-04T02:09:14Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class currently serves as a join model between Team and Participant classes, managing team memberships for assignments and courses. However, it creates an architectural inconsistency by linking teams directly to users rather than participants, even though participants are the primary entities associated with assignments and courses throughout the rest of the application. The refactoring initiative will replace the TeamsUser class with a new TeamsParticipant class, bringing several key improvements:&lt;br /&gt;
&lt;br /&gt;
1. Align team management with the application's existing participant-based pattern.&lt;br /&gt;
&lt;br /&gt;
2. Creates proper associations between teams and participants within assignment contexts.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
The primary design goal is to improve the data model and overall architecture of the Expertiza application by replacing the TeamsUser class with a more appropriate TeamsParticipant class. This change aims to achieve the following objectives:&lt;br /&gt;
&lt;br /&gt;
1. '''Enhance Data Model Consistency:''' Modify the association between teams and users to reflect a more accurate relationship between teams and participants throughout the app.&lt;br /&gt;
&lt;br /&gt;
2. '''Simplify Application Logic:''' Align the team related management with the existing pattern of using Participant objects rather than User objects throughout the application, reducing exceptions and inconsistencies.&lt;br /&gt;
&lt;br /&gt;
3. '''Improve Code Maintainability:''' Refactor the codebase to use TeamsParticipant consistently, updating all relevant models, views, and controllers to reflect this change.&lt;br /&gt;
&lt;br /&gt;
4. '''Enhance Database Structure:''' Update the database schema to include appropriate foreign keys and indexes for the TeamsParticipant table, improving data integrity and query performance.&lt;br /&gt;
&lt;br /&gt;
5. '''Ensure Backward Compatibility:''' Implement the changes in phases, allowing for a gradual transition from TeamsUser to TeamsParticipant while maintaining functionality throughout the refactoring process.&lt;br /&gt;
&lt;br /&gt;
6. '''Improve Testability:''' Develop comprehensive test cases for the new TeamsParticipant model and update existing tests to reflect the changes in associations and logic.&lt;br /&gt;
&lt;br /&gt;
==Design Pattern==&lt;br /&gt;
&lt;br /&gt;
To manage the complexity and responsibilities of the TeamsParticipant class, the following design patterns can be applied here. Since TeamsParticipant is handling both join table duties and additional business logic, a combination of patterns could improve maintainability and flexibility.&lt;br /&gt;
&lt;br /&gt;
1. '''Facade Pattern''' for Simplifying Interface&lt;br /&gt;
&lt;br /&gt;
The TeamsParticipant class handles multiple responsibilities, from managing teams and participants to removing members and adding members who accepted invites. Applying the Facade Pattern can simplify its interface by offloading complex processes to service classes. For example, a TeamsParticipantService could manage team membership rules, while TeamsParticipantManager could handle table-related operations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
class TeamParticipantService&lt;br /&gt;
  def self.add_accepted_invitee_to_team(inviter_participant_id, invited_participant_id, assignment_id)&lt;br /&gt;
    participants_teams = TeamsParticipant.where(participant_id: inviter_participant_id)&lt;br /&gt;
    participants_teams.any? do |team|&lt;br /&gt;
      assigned_team = AssignmentTeam.find_by(id: team.team_id, parent_id: assignment_id)&lt;br /&gt;
      assigned_team&amp;amp;.add_member(Participant.find(invited_participant_id), assignment_id) if assigned_team&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.handle_pair_programming(team_id, user_id)&lt;br /&gt;
    user = TeamsParticipant.find_by(team_id: team_id, user_id: user_id)&lt;br /&gt;
    user.update_attributes(pair_programming_status: &amp;quot;A&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    TeamsParticipant.where(team_id: team_id).empty?&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, within TeamsParticipant, these actions could be delegated to the facade for simplicity and modularity:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
class TeamsParticipant &amp;lt; ApplicationRecord&lt;br /&gt;
  # Other associations and methods&lt;br /&gt;
  &lt;br /&gt;
  def self.add_accepted_invitee_to_team(*args)&lt;br /&gt;
    TeamParticipantService.add_accepted_invitee_to_team(*args)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. '''Repository Pattern''' for Database Queries&lt;br /&gt;
&lt;br /&gt;
The Repository Pattern would be useful for separating data access logic since this class is heavily querying the database for create, update, find operations. This involves creating a TeamsParticipantRepository that encapsulates all finders and queries, improving modularity and making it easier to test and reuse.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
class TeamsParticipantRepository&lt;br /&gt;
  def self.find_team_participant(participant_id, team_id)&lt;br /&gt;
    TeamsParticipant.find_by(participant_id: participant_id, team_id: team_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.first_participant_for_team(team_id)&lt;br /&gt;
    TeamsParticipant.find_by(team_id: team_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    TeamsParticipant.where(team_id: team_id).empty?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.find_team_id(assignment_id, user_id)&lt;br /&gt;
    TeamsParticipant.find_team_id(assignment_id, user_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.get_team_participants(team_id)&lt;br /&gt;
    TeamsParticipant.where(team_id: team_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.get_participants_for_review(team_id)&lt;br /&gt;
    TeamsParticipant.where(team_id: team_id).each do |team_user|&lt;br /&gt;
      yield team_user&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Migration Strategy===&lt;br /&gt;
1. Create new TeamsParticipant model and table&lt;br /&gt;
&lt;br /&gt;
2. Implement parallel methods in TeamsParticipant&lt;br /&gt;
&lt;br /&gt;
3. Update controllers to use TeamsParticipant&lt;br /&gt;
&lt;br /&gt;
4. Migrate existing data&lt;br /&gt;
&lt;br /&gt;
5. Remove TeamsUser dependencies&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
[[File:ClassDiagram_TeamsParticipant.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
==Sequence Diagram==&lt;br /&gt;
[[File:SequenceDiagram_TeamsParticipant.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
==Solutions/Details of Changes Made==&lt;br /&gt;
&lt;br /&gt;
===Phase 1 Improvements===&lt;br /&gt;
&lt;br /&gt;
* Renamed TeamsUser to TeamsParticipant to modify application logic to join Teams with Participants instead of Users&lt;br /&gt;
* Updated associations in immediate neighbor classes i.e Teams, Users and Participants to ensure correctness and consistency in the data model&lt;br /&gt;
* Renamed method names for increased readability and removed redundant methods from the TeamsParticipant class&lt;br /&gt;
* Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity, improving overall maintainability of the codebase&lt;br /&gt;
* Renamed TeamUserNode to TeamParticipantNode for correctness, to align with the new design of Participation association in TeamsParticipant&lt;br /&gt;
* Added migrations to add foreign key for Participant in TeamsParticipant table and updated indexes for the same&lt;br /&gt;
&lt;br /&gt;
===Phase 2 Plan===&lt;br /&gt;
&lt;br /&gt;
* Update associations in all the models that were previously using TeamsUser to implement them with TeamsParticipant&lt;br /&gt;
* Modify implementations of all models, views, and controllers to use Participant with TeamsParticipant class instead of User&lt;br /&gt;
* This future involves modifying queries to retrieve participant and user objects that are passed to the TeamsParticipant class as commands to their methods&lt;br /&gt;
* Deprecate user_id foreign key from TeamsParticipant to completely remove the association of User from TeamsParticant, only linking Participants to Teams&lt;br /&gt;
* Update all the test cases to work with this implementation, including updating associations and mocking DB calls&lt;br /&gt;
&lt;br /&gt;
==Files Added/Modified==&lt;br /&gt;
&lt;br /&gt;
As part of the refactoring process, we need to update all references and method calls related to the TeamsParticipant table and the teams_participant class throughout the repository. This refactor will involve over 200 instances across various files.&lt;br /&gt;
&lt;br /&gt;
===Affected Components===&lt;br /&gt;
&lt;br /&gt;
   Models: &lt;br /&gt;
   1. course_team.rb&lt;br /&gt;
   2. mentor_management.rb&lt;br /&gt;
   3. mentored_team.rb&lt;br /&gt;
   4. review_response_map.rb&lt;br /&gt;
   5. signed_up_team.rb&lt;br /&gt;
   6. tag_prompt_deployment.rb&lt;br /&gt;
   7. invitation.rb&lt;br /&gt;
&lt;br /&gt;
   Controllers: &lt;br /&gt;
   1. assessment360_controller.rb&lt;br /&gt;
   2. grades_controller.rb&lt;br /&gt;
   3. join_team_requests_controller.rb&lt;br /&gt;
   4. lottery_controller.rb&lt;br /&gt;
   5. popup_controller.rb&lt;br /&gt;
   6. sign_up_sheet_controller.rb&lt;br /&gt;
   7. student_teams_controller.rb&lt;br /&gt;
   8. suggestion_controller.rb&lt;br /&gt;
   9. review_mapping_controller.rb&lt;br /&gt;
   10. pair_programming_controller.rb&lt;br /&gt;
&lt;br /&gt;
   Helpers/Workers:&lt;br /&gt;
   1. assignment_helper.rb&lt;br /&gt;
   2. manage_team_helper.rb&lt;br /&gt;
   3. review_mapping_helper.rb&lt;br /&gt;
   4. sign_up_sheet_helper.rb&lt;br /&gt;
   5. teams_users_helper.rb&lt;br /&gt;
   6. mail_worker.rb&lt;br /&gt;
&lt;br /&gt;
   Views:&lt;br /&gt;
   1. assignments/edit/_calibration.html.erb&lt;br /&gt;
   2. bookmarks/list.html.erb&lt;br /&gt;
   3. popup/participants_popup.html.erb&lt;br /&gt;
   4. reports/_teammate_review_report.html.erb&lt;br /&gt;
   5. response/response.html.erb&lt;br /&gt;
   6. review_mapping/_list_review_mappings.html.erb&lt;br /&gt;
   7. sign_up_sheet/show_team.html.erb&lt;br /&gt;
   8. student_teams/_received_invitations.html.erb&lt;br /&gt;
   9. student_teams/view.html.erb&lt;br /&gt;
   10. submitted_content/_hyperlink.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The required changes will follow the pattern shown in the attached modifications for models and controllers.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''invitation.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Invitation_model_changes.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''review_mapping_controller.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review_mapping_controller_changes2.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''pair_programming_controller.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Pair_programming_controller_changes.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
We added a new spec file for the teams_participant model, which was previously missing, and fixed issues in the team_participant_controller_spec. Additionally, we resolved model and controller tests for direct associations with Team, User, and Participant.&lt;br /&gt;
&lt;br /&gt;
===Detailed '''Test Plan''' for &amp;lt;code&amp;gt;TeamsParticipant&amp;lt;/code&amp;gt; Model===&lt;br /&gt;
&lt;br /&gt;
The test plan for the TeamsParticipant refactoring will verify both the model's core functionality and its integration with the invitation and review mapping systems.&lt;br /&gt;
&lt;br /&gt;
'''Test 1.''' Associations&lt;br /&gt;
&lt;br /&gt;
 Verify correct associations:&lt;br /&gt;
  * Belongs to participant&lt;br /&gt;
  * Belongs to team&lt;br /&gt;
  * Has one team_participant_node (dependent: destroy)&lt;br /&gt;
&lt;br /&gt;
'''Test 2.''' Method: &amp;lt;code&amp;gt;#name&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  Returns participant’s name.&lt;br /&gt;
  Appends &amp;quot;(Mentor)&amp;quot; if participant is a mentor.&lt;br /&gt;
&lt;br /&gt;
'''Test 3.''' Method: &amp;lt;code&amp;gt;#delete&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Calls methods for cleanup:&lt;br /&gt;
  * remove_team_participant_node&lt;br /&gt;
  * remove_team_if_participants_empty&lt;br /&gt;
  * remove_teams_participant_instance&lt;br /&gt;
 Destroys itself and associated TeamParticipantNode.&lt;br /&gt;
 Deletes the team if it’s the last participant.&lt;br /&gt;
&lt;br /&gt;
'''Test 4.''' Method: &amp;lt;code&amp;gt;.remove_participant&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Destroys TeamsParticipant if it exists.&lt;br /&gt;
 Does nothing if it doesn’t exist.&lt;br /&gt;
&lt;br /&gt;
'''Test 5.''' Method: &amp;lt;code&amp;gt;.first_participant_for_team&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Retrieves the first participant for a given team ID.&lt;br /&gt;
&lt;br /&gt;
'''Test 6.''' Method: &amp;lt;code&amp;gt;.team_empty?&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Returns true if team has no participants; false otherwise.&lt;br /&gt;
&lt;br /&gt;
'''Test 7.''' Method: &amp;lt;code&amp;gt;.add_accepted_invitee_to_team&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Adds a participant to the team, returning true if successful.&lt;br /&gt;
&lt;br /&gt;
'''Test 8.''' Method: &amp;lt;code&amp;gt;.team_id&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Returns team ID if participant is assigned to a team.&lt;br /&gt;
 Returns nil if not assigned.&lt;br /&gt;
&lt;br /&gt;
===Model Tests===&lt;br /&gt;
&lt;br /&gt;
  describe '.remove_participant' do&lt;br /&gt;
    before do&lt;br /&gt;
      allow(TeamsParticipant).to receive(:find_by).with(user_id: user.id, team_id: team.id).and_return(team_participant)&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team participant exists' do&lt;br /&gt;
      it 'destroys the team participant' do&lt;br /&gt;
        expect(team_participant).to receive(:destroy)&lt;br /&gt;
        TeamsParticipant.remove_team_participant(user.id, team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team participant does not exist' do&lt;br /&gt;
      before do&lt;br /&gt;
        allow(TeamsParticipant).to receive(:find_by).with(user_id: user.id, team_id: team.id).and_return(nil)&lt;br /&gt;
      end&lt;br /&gt;
  &lt;br /&gt;
      it 'does not call destroy' do&lt;br /&gt;
        expect(team_participant).not_to receive(:destroy)&lt;br /&gt;
        TeamsParticipant.remove_team_participant(user.id, team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
===Integration Tests===&lt;br /&gt;
&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    context 'when team with given id that exists' do&lt;br /&gt;
      it 'successfully returns the team with the given team id' do&lt;br /&gt;
        allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
        request_params = { id: team1.id }&lt;br /&gt;
        user_session = { user: ta }&lt;br /&gt;
        result = get :edit, params: request_params, session: user_session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when team with given id does not exist' do&lt;br /&gt;
      it 'raises an ActiveRecord::RecordNotFound error' do&lt;br /&gt;
        expect {&lt;br /&gt;
          get :edit, params: { id: 999 }, session: { user: ta }&lt;br /&gt;
        }.to raise_error(ActiveRecord::RecordNotFound)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== UI Testing===&lt;br /&gt;
&lt;br /&gt;
1. Created a new team for an assignment, sent an invite to another user and successfully accepted the invite, and added another user to the team, demonstrating the working of team-participants&lt;br /&gt;
&lt;br /&gt;
[[File:TeamsParticipantUIDemo.png|800px|center|border|]]&lt;br /&gt;
&lt;br /&gt;
2. Added a participant to an existing course&lt;br /&gt;
&lt;br /&gt;
[[File:CourseParticipantUIdemo.png|800px|center|border|]]&lt;br /&gt;
&lt;br /&gt;
===Sample Test Changes===&lt;br /&gt;
&lt;br /&gt;
We went ahead with updating all the table references as needed, adjusting or adding mocks for methods, and revising database queries involving the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
Below are examples of changes that were made to the 200 refrences across all models, controllers and views throughout the repository.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''invitation_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Invitation_spec1.png|800px|center|]]&lt;br /&gt;
[[File:Invitation_spec2.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''review_mapping_controller_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review_map_controller_spec.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''pair_programming_controller_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Pair_prog_controller_spec.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
==Final Pull Request==&lt;br /&gt;
&lt;br /&gt;
The PR to Expertiza repo can be found here: &lt;br /&gt;
&lt;br /&gt;
 [https://github.com/expertiza/expertiza/pull/2887 E2456. Refactor teams user.rb #2887]&lt;br /&gt;
&lt;br /&gt;
==Project Demo==&lt;br /&gt;
&lt;br /&gt;
Click [https://vimeo.com/1035806635/f8dc0a1fc3 here] to view demo&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jay, Patel&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
# [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0OSS Projects on Expertiza]&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Github]&lt;br /&gt;
# [https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page Expertiza Wiki]&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=160455</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb (Phase 2 - Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=160455"/>
		<updated>2024-12-04T02:05:30Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: /* UI Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class currently serves as a join model between Team and Participant classes, managing team memberships for assignments and courses. However, it creates an architectural inconsistency by linking teams directly to users rather than participants, even though participants are the primary entities associated with assignments and courses throughout the rest of the application. The refactoring initiative will replace the TeamsUser class with a new TeamsParticipant class, bringing several key improvements:&lt;br /&gt;
&lt;br /&gt;
1. Align team management with the application's existing participant-based pattern.&lt;br /&gt;
&lt;br /&gt;
2. Creates proper associations between teams and participants within assignment contexts.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
The primary design goal is to improve the data model and overall architecture of the Expertiza application by replacing the TeamsUser class with a more appropriate TeamsParticipant class. This change aims to achieve the following objectives:&lt;br /&gt;
&lt;br /&gt;
1. '''Enhance Data Model Consistency:''' Modify the association between teams and users to reflect a more accurate relationship between teams and participants throughout the app.&lt;br /&gt;
&lt;br /&gt;
2. '''Simplify Application Logic:''' Align the team related management with the existing pattern of using Participant objects rather than User objects throughout the application, reducing exceptions and inconsistencies.&lt;br /&gt;
&lt;br /&gt;
3. '''Improve Code Maintainability:''' Refactor the codebase to use TeamsParticipant consistently, updating all relevant models, views, and controllers to reflect this change.&lt;br /&gt;
&lt;br /&gt;
4. '''Enhance Database Structure:''' Update the database schema to include appropriate foreign keys and indexes for the TeamsParticipant table, improving data integrity and query performance.&lt;br /&gt;
&lt;br /&gt;
5. '''Ensure Backward Compatibility:''' Implement the changes in phases, allowing for a gradual transition from TeamsUser to TeamsParticipant while maintaining functionality throughout the refactoring process.&lt;br /&gt;
&lt;br /&gt;
6. '''Improve Testability:''' Develop comprehensive test cases for the new TeamsParticipant model and update existing tests to reflect the changes in associations and logic.&lt;br /&gt;
&lt;br /&gt;
==Design Pattern==&lt;br /&gt;
&lt;br /&gt;
To manage the complexity and responsibilities of the TeamsParticipant class, the following design patterns can be applied here. Since TeamsParticipant is handling both join table duties and additional business logic, a combination of patterns could improve maintainability and flexibility.&lt;br /&gt;
&lt;br /&gt;
1. '''Facade Pattern''' for Simplifying Interface&lt;br /&gt;
&lt;br /&gt;
The TeamsParticipant class handles multiple responsibilities, from managing teams and participants to removing members and adding members who accepted invites. Applying the Facade Pattern can simplify its interface by offloading complex processes to service classes. For example, a TeamsParticipantService could manage team membership rules, while TeamsParticipantManager could handle table-related operations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
class TeamParticipantService&lt;br /&gt;
  def self.add_accepted_invitee_to_team(inviter_participant_id, invited_participant_id, assignment_id)&lt;br /&gt;
    participants_teams = TeamsParticipant.where(participant_id: inviter_participant_id)&lt;br /&gt;
    participants_teams.any? do |team|&lt;br /&gt;
      assigned_team = AssignmentTeam.find_by(id: team.team_id, parent_id: assignment_id)&lt;br /&gt;
      assigned_team&amp;amp;.add_member(Participant.find(invited_participant_id), assignment_id) if assigned_team&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.handle_pair_programming(team_id, user_id)&lt;br /&gt;
    user = TeamsParticipant.find_by(team_id: team_id, user_id: user_id)&lt;br /&gt;
    user.update_attributes(pair_programming_status: &amp;quot;A&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    TeamsParticipant.where(team_id: team_id).empty?&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, within TeamsParticipant, these actions could be delegated to the facade for simplicity and modularity:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
class TeamsParticipant &amp;lt; ApplicationRecord&lt;br /&gt;
  # Other associations and methods&lt;br /&gt;
  &lt;br /&gt;
  def self.add_accepted_invitee_to_team(*args)&lt;br /&gt;
    TeamParticipantService.add_accepted_invitee_to_team(*args)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. '''Repository Pattern''' for Database Queries&lt;br /&gt;
&lt;br /&gt;
The Repository Pattern would be useful for separating data access logic since this class is heavily querying the database for create, update, find operations. This involves creating a TeamsParticipantRepository that encapsulates all finders and queries, improving modularity and making it easier to test and reuse.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
class TeamsParticipantRepository&lt;br /&gt;
  def self.find_team_participant(participant_id, team_id)&lt;br /&gt;
    TeamsParticipant.find_by(participant_id: participant_id, team_id: team_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.first_participant_for_team(team_id)&lt;br /&gt;
    TeamsParticipant.find_by(team_id: team_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    TeamsParticipant.where(team_id: team_id).empty?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.find_team_id(assignment_id, user_id)&lt;br /&gt;
    TeamsParticipant.find_team_id(assignment_id, user_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.get_team_participants(team_id)&lt;br /&gt;
    TeamsParticipant.where(team_id: team_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.get_participants_for_review(team_id)&lt;br /&gt;
    TeamsParticipant.where(team_id: team_id).each do |team_user|&lt;br /&gt;
      yield team_user&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Migration Strategy===&lt;br /&gt;
1. Create new TeamsParticipant model and table&lt;br /&gt;
&lt;br /&gt;
2. Implement parallel methods in TeamsParticipant&lt;br /&gt;
&lt;br /&gt;
3. Update controllers to use TeamsParticipant&lt;br /&gt;
&lt;br /&gt;
4. Migrate existing data&lt;br /&gt;
&lt;br /&gt;
5. Remove TeamsUser dependencies&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
[[File:ClassDiagram_TeamsParticipant.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
==Sequence Diagram==&lt;br /&gt;
[[File:SequenceDiagram_TeamsParticipant.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
==Solutions/Details of Changes Made==&lt;br /&gt;
&lt;br /&gt;
===Phase 1 Improvements===&lt;br /&gt;
&lt;br /&gt;
* Renamed TeamsUser to TeamsParticipant to modify application logic to join Teams with Participants instead of Users&lt;br /&gt;
* Updated associations in immediate neighbor classes i.e Teams, Users and Participants to ensure correctness and consistency in the data model&lt;br /&gt;
* Renamed method names for increased readability and removed redundant methods from the TeamsParticipant class&lt;br /&gt;
* Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity, improving overall maintainability of the codebase&lt;br /&gt;
* Renamed TeamUserNode to TeamParticipantNode for correctness, to align with the new design of Participation association in TeamsParticipant&lt;br /&gt;
* Added migrations to add foreign key for Participant in TeamsParticipant table and updated indexes for the same&lt;br /&gt;
&lt;br /&gt;
===Phase 2 Plan===&lt;br /&gt;
&lt;br /&gt;
* Update associations in all the models that were previously using TeamsUser to implement them with TeamsParticipant&lt;br /&gt;
* Modify implementations of all models, views, and controllers to use Participant with TeamsParticipant class instead of User&lt;br /&gt;
* This future involves modifying queries to retrieve participant and user objects that are passed to the TeamsParticipant class as commands to their methods&lt;br /&gt;
* Deprecate user_id foreign key from TeamsParticipant to completely remove the association of User from TeamsParticant, only linking Participants to Teams&lt;br /&gt;
* Update all the test cases to work with this implementation, including updating associations and mocking DB calls&lt;br /&gt;
&lt;br /&gt;
==Files Added/Modified==&lt;br /&gt;
&lt;br /&gt;
As part of the refactoring process, we need to update all references and method calls related to the TeamsParticipant table and the teams_participant class throughout the repository. This refactor will involve over 200 instances across various files.&lt;br /&gt;
&lt;br /&gt;
===Affected Components===&lt;br /&gt;
&lt;br /&gt;
   Models: &lt;br /&gt;
   1. course_team.rb&lt;br /&gt;
   2. mentor_management.rb&lt;br /&gt;
   3. mentored_team.rb&lt;br /&gt;
   4. review_response_map.rb&lt;br /&gt;
   5. signed_up_team.rb&lt;br /&gt;
   6. tag_prompt_deployment.rb&lt;br /&gt;
   7. invitation.rb&lt;br /&gt;
&lt;br /&gt;
   Controllers: &lt;br /&gt;
   1. assessment360_controller.rb&lt;br /&gt;
   2. grades_controller.rb&lt;br /&gt;
   3. join_team_requests_controller.rb&lt;br /&gt;
   4. lottery_controller.rb&lt;br /&gt;
   5. popup_controller.rb&lt;br /&gt;
   6. sign_up_sheet_controller.rb&lt;br /&gt;
   7. student_teams_controller.rb&lt;br /&gt;
   8. suggestion_controller.rb&lt;br /&gt;
   9. review_mapping_controller.rb&lt;br /&gt;
   10. pair_programming_controller.rb&lt;br /&gt;
&lt;br /&gt;
   Helpers/Workers:&lt;br /&gt;
   1. assignment_helper.rb&lt;br /&gt;
   2. manage_team_helper.rb&lt;br /&gt;
   3. review_mapping_helper.rb&lt;br /&gt;
   4. sign_up_sheet_helper.rb&lt;br /&gt;
   5. teams_users_helper.rb&lt;br /&gt;
   6. mail_worker.rb&lt;br /&gt;
&lt;br /&gt;
   Views:&lt;br /&gt;
   1. assignments/edit/_calibration.html.erb&lt;br /&gt;
   2. bookmarks/list.html.erb&lt;br /&gt;
   3. popup/participants_popup.html.erb&lt;br /&gt;
   4. reports/_teammate_review_report.html.erb&lt;br /&gt;
   5. response/response.html.erb&lt;br /&gt;
   6. review_mapping/_list_review_mappings.html.erb&lt;br /&gt;
   7. sign_up_sheet/show_team.html.erb&lt;br /&gt;
   8. student_teams/_received_invitations.html.erb&lt;br /&gt;
   9. student_teams/view.html.erb&lt;br /&gt;
   10. submitted_content/_hyperlink.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The required changes will follow the pattern shown in the attached modifications for models and controllers.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''invitation.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Invitation_model_changes.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''review_mapping_controller.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review_mapping_controller_changes2.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''pair_programming_controller.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Pair_programming_controller_changes.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
We added a new spec file for the teams_participant model, which was previously missing, and fixed issues in the team_participant_controller_spec. Additionally, we resolved model and controller tests for direct associations with Team, User, and Participant.&lt;br /&gt;
&lt;br /&gt;
===Detailed '''Test Plan''' for &amp;lt;code&amp;gt;TeamsParticipant&amp;lt;/code&amp;gt; Model===&lt;br /&gt;
&lt;br /&gt;
The test plan for the TeamsParticipant refactoring will verify both the model's core functionality and its integration with the invitation and review mapping systems.&lt;br /&gt;
&lt;br /&gt;
'''Test 1.''' Associations&lt;br /&gt;
&lt;br /&gt;
 Verify correct associations:&lt;br /&gt;
  * Belongs to participant&lt;br /&gt;
  * Belongs to team&lt;br /&gt;
  * Has one team_participant_node (dependent: destroy)&lt;br /&gt;
&lt;br /&gt;
'''Test 2.''' Method: &amp;lt;code&amp;gt;#name&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  Returns participant’s name.&lt;br /&gt;
  Appends &amp;quot;(Mentor)&amp;quot; if participant is a mentor.&lt;br /&gt;
&lt;br /&gt;
'''Test 3.''' Method: &amp;lt;code&amp;gt;#delete&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Calls methods for cleanup:&lt;br /&gt;
  * remove_team_participant_node&lt;br /&gt;
  * remove_team_if_participants_empty&lt;br /&gt;
  * remove_teams_participant_instance&lt;br /&gt;
 Destroys itself and associated TeamParticipantNode.&lt;br /&gt;
 Deletes the team if it’s the last participant.&lt;br /&gt;
&lt;br /&gt;
'''Test 4.''' Method: &amp;lt;code&amp;gt;.remove_participant&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Destroys TeamsParticipant if it exists.&lt;br /&gt;
 Does nothing if it doesn’t exist.&lt;br /&gt;
&lt;br /&gt;
'''Test 5.''' Method: &amp;lt;code&amp;gt;.first_participant_for_team&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Retrieves the first participant for a given team ID.&lt;br /&gt;
&lt;br /&gt;
'''Test 6.''' Method: &amp;lt;code&amp;gt;.team_empty?&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Returns true if team has no participants; false otherwise.&lt;br /&gt;
&lt;br /&gt;
'''Test 7.''' Method: &amp;lt;code&amp;gt;.add_accepted_invitee_to_team&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Adds a participant to the team, returning true if successful.&lt;br /&gt;
&lt;br /&gt;
'''Test 8.''' Method: &amp;lt;code&amp;gt;.team_id&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Returns team ID if participant is assigned to a team.&lt;br /&gt;
 Returns nil if not assigned.&lt;br /&gt;
&lt;br /&gt;
===Model Tests===&lt;br /&gt;
&lt;br /&gt;
  describe '.remove_participant' do&lt;br /&gt;
    before do&lt;br /&gt;
      allow(TeamsParticipant).to receive(:find_by).with(user_id: user.id, team_id: team.id).and_return(team_participant)&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team participant exists' do&lt;br /&gt;
      it 'destroys the team participant' do&lt;br /&gt;
        expect(team_participant).to receive(:destroy)&lt;br /&gt;
        TeamsParticipant.remove_team_participant(user.id, team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team participant does not exist' do&lt;br /&gt;
      before do&lt;br /&gt;
        allow(TeamsParticipant).to receive(:find_by).with(user_id: user.id, team_id: team.id).and_return(nil)&lt;br /&gt;
      end&lt;br /&gt;
  &lt;br /&gt;
      it 'does not call destroy' do&lt;br /&gt;
        expect(team_participant).not_to receive(:destroy)&lt;br /&gt;
        TeamsParticipant.remove_team_participant(user.id, team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
===Integration Tests===&lt;br /&gt;
&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    context 'when team with given id that exists' do&lt;br /&gt;
      it 'successfully returns the team with the given team id' do&lt;br /&gt;
        allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
        request_params = { id: team1.id }&lt;br /&gt;
        user_session = { user: ta }&lt;br /&gt;
        result = get :edit, params: request_params, session: user_session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when team with given id does not exist' do&lt;br /&gt;
      it 'raises an ActiveRecord::RecordNotFound error' do&lt;br /&gt;
        expect {&lt;br /&gt;
          get :edit, params: { id: 999 }, session: { user: ta }&lt;br /&gt;
        }.to raise_error(ActiveRecord::RecordNotFound)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== UI Testing===&lt;br /&gt;
&lt;br /&gt;
1. Created a new team for an assignment, sent an invite to another user and successfully accepted the invite, and added another user to the team, demonstrating the working of team-participants&lt;br /&gt;
&lt;br /&gt;
[[File:TeamsParticipantUIDemo.png|800px|center|border|]]&lt;br /&gt;
&lt;br /&gt;
2. Added a participant to an existing course&lt;br /&gt;
&lt;br /&gt;
[[File:CourseParticipantUIdemo.png|800px|center|border|]]&lt;br /&gt;
&lt;br /&gt;
===Sample Test Changes===&lt;br /&gt;
&lt;br /&gt;
We went ahead with updating all the table references as needed, adjusting or adding mocks for methods, and revising database queries involving the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
Below are examples of changes that were made to the 200 refrences across all models, controllers and views throughout the repository.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''invitation_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Invitation_spec1.png|800px|center|]]&lt;br /&gt;
[[File:Invitation_spec2.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''review_mapping_controller_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review_map_controller_spec.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''pair_programming_controller_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Pair_prog_controller_spec.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
==Final Pull Request==&lt;br /&gt;
&lt;br /&gt;
The PR to Expertiza repo can be found here: &lt;br /&gt;
&lt;br /&gt;
 [https://github.com/expertiza/expertiza/pull/2887 E2456. Refactor teams user.rb #2887]&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jay, Patel&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
# [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0OSS Projects on Expertiza])&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Github]&lt;br /&gt;
# [https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page Expertiza Wiki]&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=160449</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb (Phase 2 - Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=160449"/>
		<updated>2024-12-04T02:03:54Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class currently serves as a join model between Team and Participant classes, managing team memberships for assignments and courses. However, it creates an architectural inconsistency by linking teams directly to users rather than participants, even though participants are the primary entities associated with assignments and courses throughout the rest of the application. The refactoring initiative will replace the TeamsUser class with a new TeamsParticipant class, bringing several key improvements:&lt;br /&gt;
&lt;br /&gt;
1. Align team management with the application's existing participant-based pattern.&lt;br /&gt;
&lt;br /&gt;
2. Creates proper associations between teams and participants within assignment contexts.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
The primary design goal is to improve the data model and overall architecture of the Expertiza application by replacing the TeamsUser class with a more appropriate TeamsParticipant class. This change aims to achieve the following objectives:&lt;br /&gt;
&lt;br /&gt;
1. '''Enhance Data Model Consistency:''' Modify the association between teams and users to reflect a more accurate relationship between teams and participants throughout the app.&lt;br /&gt;
&lt;br /&gt;
2. '''Simplify Application Logic:''' Align the team related management with the existing pattern of using Participant objects rather than User objects throughout the application, reducing exceptions and inconsistencies.&lt;br /&gt;
&lt;br /&gt;
3. '''Improve Code Maintainability:''' Refactor the codebase to use TeamsParticipant consistently, updating all relevant models, views, and controllers to reflect this change.&lt;br /&gt;
&lt;br /&gt;
4. '''Enhance Database Structure:''' Update the database schema to include appropriate foreign keys and indexes for the TeamsParticipant table, improving data integrity and query performance.&lt;br /&gt;
&lt;br /&gt;
5. '''Ensure Backward Compatibility:''' Implement the changes in phases, allowing for a gradual transition from TeamsUser to TeamsParticipant while maintaining functionality throughout the refactoring process.&lt;br /&gt;
&lt;br /&gt;
6. '''Improve Testability:''' Develop comprehensive test cases for the new TeamsParticipant model and update existing tests to reflect the changes in associations and logic.&lt;br /&gt;
&lt;br /&gt;
==Design Pattern==&lt;br /&gt;
&lt;br /&gt;
To manage the complexity and responsibilities of the TeamsParticipant class, the following design patterns can be applied here. Since TeamsParticipant is handling both join table duties and additional business logic, a combination of patterns could improve maintainability and flexibility.&lt;br /&gt;
&lt;br /&gt;
1. '''Facade Pattern''' for Simplifying Interface&lt;br /&gt;
&lt;br /&gt;
The TeamsParticipant class handles multiple responsibilities, from managing teams and participants to removing members and adding members who accepted invites. Applying the Facade Pattern can simplify its interface by offloading complex processes to service classes. For example, a TeamsParticipantService could manage team membership rules, while TeamsParticipantManager could handle table-related operations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
class TeamParticipantService&lt;br /&gt;
  def self.add_accepted_invitee_to_team(inviter_participant_id, invited_participant_id, assignment_id)&lt;br /&gt;
    participants_teams = TeamsParticipant.where(participant_id: inviter_participant_id)&lt;br /&gt;
    participants_teams.any? do |team|&lt;br /&gt;
      assigned_team = AssignmentTeam.find_by(id: team.team_id, parent_id: assignment_id)&lt;br /&gt;
      assigned_team&amp;amp;.add_member(Participant.find(invited_participant_id), assignment_id) if assigned_team&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.handle_pair_programming(team_id, user_id)&lt;br /&gt;
    user = TeamsParticipant.find_by(team_id: team_id, user_id: user_id)&lt;br /&gt;
    user.update_attributes(pair_programming_status: &amp;quot;A&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    TeamsParticipant.where(team_id: team_id).empty?&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, within TeamsParticipant, these actions could be delegated to the facade for simplicity and modularity:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
class TeamsParticipant &amp;lt; ApplicationRecord&lt;br /&gt;
  # Other associations and methods&lt;br /&gt;
  &lt;br /&gt;
  def self.add_accepted_invitee_to_team(*args)&lt;br /&gt;
    TeamParticipantService.add_accepted_invitee_to_team(*args)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. '''Repository Pattern''' for Database Queries&lt;br /&gt;
&lt;br /&gt;
The Repository Pattern would be useful for separating data access logic since this class is heavily querying the database for create, update, find operations. This involves creating a TeamsParticipantRepository that encapsulates all finders and queries, improving modularity and making it easier to test and reuse.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
class TeamsParticipantRepository&lt;br /&gt;
  def self.find_team_participant(participant_id, team_id)&lt;br /&gt;
    TeamsParticipant.find_by(participant_id: participant_id, team_id: team_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.first_participant_for_team(team_id)&lt;br /&gt;
    TeamsParticipant.find_by(team_id: team_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    TeamsParticipant.where(team_id: team_id).empty?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.find_team_id(assignment_id, user_id)&lt;br /&gt;
    TeamsParticipant.find_team_id(assignment_id, user_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.get_team_participants(team_id)&lt;br /&gt;
    TeamsParticipant.where(team_id: team_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.get_participants_for_review(team_id)&lt;br /&gt;
    TeamsParticipant.where(team_id: team_id).each do |team_user|&lt;br /&gt;
      yield team_user&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Migration Strategy===&lt;br /&gt;
1. Create new TeamsParticipant model and table&lt;br /&gt;
&lt;br /&gt;
2. Implement parallel methods in TeamsParticipant&lt;br /&gt;
&lt;br /&gt;
3. Update controllers to use TeamsParticipant&lt;br /&gt;
&lt;br /&gt;
4. Migrate existing data&lt;br /&gt;
&lt;br /&gt;
5. Remove TeamsUser dependencies&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
[[File:ClassDiagram_TeamsParticipant.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
==Sequence Diagram==&lt;br /&gt;
[[File:SequenceDiagram_TeamsParticipant.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
==Solutions/Details of Changes Made==&lt;br /&gt;
&lt;br /&gt;
===Phase 1 Improvements===&lt;br /&gt;
&lt;br /&gt;
* Renamed TeamsUser to TeamsParticipant to modify application logic to join Teams with Participants instead of Users&lt;br /&gt;
* Updated associations in immediate neighbor classes i.e Teams, Users and Participants to ensure correctness and consistency in the data model&lt;br /&gt;
* Renamed method names for increased readability and removed redundant methods from the TeamsParticipant class&lt;br /&gt;
* Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity, improving overall maintainability of the codebase&lt;br /&gt;
* Renamed TeamUserNode to TeamParticipantNode for correctness, to align with the new design of Participation association in TeamsParticipant&lt;br /&gt;
* Added migrations to add foreign key for Participant in TeamsParticipant table and updated indexes for the same&lt;br /&gt;
&lt;br /&gt;
===Phase 2 Plan===&lt;br /&gt;
&lt;br /&gt;
* Update associations in all the models that were previously using TeamsUser to implement them with TeamsParticipant&lt;br /&gt;
* Modify implementations of all models, views, and controllers to use Participant with TeamsParticipant class instead of User&lt;br /&gt;
* This future involves modifying queries to retrieve participant and user objects that are passed to the TeamsParticipant class as commands to their methods&lt;br /&gt;
* Deprecate user_id foreign key from TeamsParticipant to completely remove the association of User from TeamsParticant, only linking Participants to Teams&lt;br /&gt;
* Update all the test cases to work with this implementation, including updating associations and mocking DB calls&lt;br /&gt;
&lt;br /&gt;
==Files Added/Modified==&lt;br /&gt;
&lt;br /&gt;
As part of the refactoring process, we need to update all references and method calls related to the TeamsParticipant table and the teams_participant class throughout the repository. This refactor will involve over 200 instances across various files.&lt;br /&gt;
&lt;br /&gt;
===Affected Components===&lt;br /&gt;
&lt;br /&gt;
   Models: &lt;br /&gt;
   1. course_team.rb&lt;br /&gt;
   2. mentor_management.rb&lt;br /&gt;
   3. mentored_team.rb&lt;br /&gt;
   4. review_response_map.rb&lt;br /&gt;
   5. signed_up_team.rb&lt;br /&gt;
   6. tag_prompt_deployment.rb&lt;br /&gt;
   7. invitation.rb&lt;br /&gt;
&lt;br /&gt;
   Controllers: &lt;br /&gt;
   1. assessment360_controller.rb&lt;br /&gt;
   2. grades_controller.rb&lt;br /&gt;
   3. join_team_requests_controller.rb&lt;br /&gt;
   4. lottery_controller.rb&lt;br /&gt;
   5. popup_controller.rb&lt;br /&gt;
   6. sign_up_sheet_controller.rb&lt;br /&gt;
   7. student_teams_controller.rb&lt;br /&gt;
   8. suggestion_controller.rb&lt;br /&gt;
   9. review_mapping_controller.rb&lt;br /&gt;
   10. pair_programming_controller.rb&lt;br /&gt;
&lt;br /&gt;
   Helpers/Workers:&lt;br /&gt;
   1. assignment_helper.rb&lt;br /&gt;
   2. manage_team_helper.rb&lt;br /&gt;
   3. review_mapping_helper.rb&lt;br /&gt;
   4. sign_up_sheet_helper.rb&lt;br /&gt;
   5. teams_users_helper.rb&lt;br /&gt;
   6. mail_worker.rb&lt;br /&gt;
&lt;br /&gt;
   Views:&lt;br /&gt;
   1. assignments/edit/_calibration.html.erb&lt;br /&gt;
   2. bookmarks/list.html.erb&lt;br /&gt;
   3. popup/participants_popup.html.erb&lt;br /&gt;
   4. reports/_teammate_review_report.html.erb&lt;br /&gt;
   5. response/response.html.erb&lt;br /&gt;
   6. review_mapping/_list_review_mappings.html.erb&lt;br /&gt;
   7. sign_up_sheet/show_team.html.erb&lt;br /&gt;
   8. student_teams/_received_invitations.html.erb&lt;br /&gt;
   9. student_teams/view.html.erb&lt;br /&gt;
   10. submitted_content/_hyperlink.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The required changes will follow the pattern shown in the attached modifications for models and controllers.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''invitation.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Invitation_model_changes.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''review_mapping_controller.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review_mapping_controller_changes2.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''pair_programming_controller.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Pair_programming_controller_changes.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
We added a new spec file for the teams_participant model, which was previously missing, and fixed issues in the team_participant_controller_spec. Additionally, we resolved model and controller tests for direct associations with Team, User, and Participant.&lt;br /&gt;
&lt;br /&gt;
===Detailed '''Test Plan''' for &amp;lt;code&amp;gt;TeamsParticipant&amp;lt;/code&amp;gt; Model===&lt;br /&gt;
&lt;br /&gt;
The test plan for the TeamsParticipant refactoring will verify both the model's core functionality and its integration with the invitation and review mapping systems.&lt;br /&gt;
&lt;br /&gt;
'''Test 1.''' Associations&lt;br /&gt;
&lt;br /&gt;
 Verify correct associations:&lt;br /&gt;
  * Belongs to participant&lt;br /&gt;
  * Belongs to team&lt;br /&gt;
  * Has one team_participant_node (dependent: destroy)&lt;br /&gt;
&lt;br /&gt;
'''Test 2.''' Method: &amp;lt;code&amp;gt;#name&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  Returns participant’s name.&lt;br /&gt;
  Appends &amp;quot;(Mentor)&amp;quot; if participant is a mentor.&lt;br /&gt;
&lt;br /&gt;
'''Test 3.''' Method: &amp;lt;code&amp;gt;#delete&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Calls methods for cleanup:&lt;br /&gt;
  * remove_team_participant_node&lt;br /&gt;
  * remove_team_if_participants_empty&lt;br /&gt;
  * remove_teams_participant_instance&lt;br /&gt;
 Destroys itself and associated TeamParticipantNode.&lt;br /&gt;
 Deletes the team if it’s the last participant.&lt;br /&gt;
&lt;br /&gt;
'''Test 4.''' Method: &amp;lt;code&amp;gt;.remove_participant&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Destroys TeamsParticipant if it exists.&lt;br /&gt;
 Does nothing if it doesn’t exist.&lt;br /&gt;
&lt;br /&gt;
'''Test 5.''' Method: &amp;lt;code&amp;gt;.first_participant_for_team&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Retrieves the first participant for a given team ID.&lt;br /&gt;
&lt;br /&gt;
'''Test 6.''' Method: &amp;lt;code&amp;gt;.team_empty?&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Returns true if team has no participants; false otherwise.&lt;br /&gt;
&lt;br /&gt;
'''Test 7.''' Method: &amp;lt;code&amp;gt;.add_accepted_invitee_to_team&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Adds a participant to the team, returning true if successful.&lt;br /&gt;
&lt;br /&gt;
'''Test 8.''' Method: &amp;lt;code&amp;gt;.team_id&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Returns team ID if participant is assigned to a team.&lt;br /&gt;
 Returns nil if not assigned.&lt;br /&gt;
&lt;br /&gt;
===Model Tests===&lt;br /&gt;
&lt;br /&gt;
  describe '.remove_participant' do&lt;br /&gt;
    before do&lt;br /&gt;
      allow(TeamsParticipant).to receive(:find_by).with(user_id: user.id, team_id: team.id).and_return(team_participant)&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team participant exists' do&lt;br /&gt;
      it 'destroys the team participant' do&lt;br /&gt;
        expect(team_participant).to receive(:destroy)&lt;br /&gt;
        TeamsParticipant.remove_team_participant(user.id, team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team participant does not exist' do&lt;br /&gt;
      before do&lt;br /&gt;
        allow(TeamsParticipant).to receive(:find_by).with(user_id: user.id, team_id: team.id).and_return(nil)&lt;br /&gt;
      end&lt;br /&gt;
  &lt;br /&gt;
      it 'does not call destroy' do&lt;br /&gt;
        expect(team_participant).not_to receive(:destroy)&lt;br /&gt;
        TeamsParticipant.remove_team_participant(user.id, team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
===Integration Tests===&lt;br /&gt;
&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    context 'when team with given id that exists' do&lt;br /&gt;
      it 'successfully returns the team with the given team id' do&lt;br /&gt;
        allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
        request_params = { id: team1.id }&lt;br /&gt;
        user_session = { user: ta }&lt;br /&gt;
        result = get :edit, params: request_params, session: user_session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when team with given id does not exist' do&lt;br /&gt;
      it 'raises an ActiveRecord::RecordNotFound error' do&lt;br /&gt;
        expect {&lt;br /&gt;
          get :edit, params: { id: 999 }, session: { user: ta }&lt;br /&gt;
        }.to raise_error(ActiveRecord::RecordNotFound)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== UI Testing===&lt;br /&gt;
&lt;br /&gt;
1. Created a new team for an assignment, sent an invite to another user and successfully accepted the invite, and added another user to the team, demonstrating the working of team-participants&lt;br /&gt;
&lt;br /&gt;
[[File:TeamsParticipantUIDemo.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
2. Added a participant to an existing course&lt;br /&gt;
&lt;br /&gt;
[[File:CourseParticipantUIdemo.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Sample Test Changes===&lt;br /&gt;
&lt;br /&gt;
We went ahead with updating all the table references as needed, adjusting or adding mocks for methods, and revising database queries involving the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
Below are examples of changes that were made to the 200 refrences across all models, controllers and views throughout the repository.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''invitation_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Invitation_spec1.png|800px|center|]]&lt;br /&gt;
[[File:Invitation_spec2.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''review_mapping_controller_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review_map_controller_spec.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''pair_programming_controller_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Pair_prog_controller_spec.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
==Final Pull Request==&lt;br /&gt;
&lt;br /&gt;
The PR to Expertiza repo can be found here: &lt;br /&gt;
&lt;br /&gt;
 [https://github.com/expertiza/expertiza/pull/2887 E2456. Refactor teams user.rb #2887]&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jay, Patel&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
# [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0OSS Projects on Expertiza])&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Github]&lt;br /&gt;
# [https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page Expertiza Wiki]&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:CourseParticipantUIdemo.png&amp;diff=160448</id>
		<title>File:CourseParticipantUIdemo.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:CourseParticipantUIdemo.png&amp;diff=160448"/>
		<updated>2024-12-04T02:03:45Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:TeamsParticipantUIDemo.png&amp;diff=160444</id>
		<title>File:TeamsParticipantUIDemo.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:TeamsParticipantUIDemo.png&amp;diff=160444"/>
		<updated>2024-12-04T02:02:34Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=159327</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb (Phase 2 - Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=159327"/>
		<updated>2024-11-13T01:27:40Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: /* Next Steps */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design Pattern==&lt;br /&gt;
&lt;br /&gt;
To manage the complexity and responsibilities of the TeamsParticipant class, the following design patterns can be applied here. Since TeamsParticipant is handling both join table duties and additional business logic, a combination of patterns could improve maintainability and flexibility.&lt;br /&gt;
&lt;br /&gt;
1. '''Facade Pattern''' for Simplifying Interface&lt;br /&gt;
&lt;br /&gt;
The TeamsParticipant class handles multiple responsibilities, from managing teams and participants to removing members and adding members who accepted invites. Applying the Facade Pattern can simplify its interface by offloading complex processes to service classes. For example, a TeamsParticipantService could manage team membership rules, while TeamsParticipantManager could handle table-related operations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
class TeamParticipantService&lt;br /&gt;
  def self.add_accepted_invitee_to_team(inviter_participant_id, invited_participant_id, assignment_id)&lt;br /&gt;
    participants_teams = TeamsParticipant.where(participant_id: inviter_participant_id)&lt;br /&gt;
    participants_teams.any? do |team|&lt;br /&gt;
      assigned_team = AssignmentTeam.find_by(id: team.team_id, parent_id: assignment_id)&lt;br /&gt;
      assigned_team&amp;amp;.add_member(Participant.find(invited_participant_id), assignment_id) if assigned_team&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    TeamsParticipant.where(team_id: team_id).empty?&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, within TeamsParticipant, these actions could be delegated to the facade for simplicity and modularity:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
class TeamsParticipant &amp;lt; ApplicationRecord&lt;br /&gt;
  # Other associations and methods&lt;br /&gt;
  &lt;br /&gt;
  def self.add_accepted_invitee_to_team(*args)&lt;br /&gt;
    TeamParticipantService.add_accepted_invitee_to_team(*args)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. '''Repository Pattern''' for Database Queries&lt;br /&gt;
&lt;br /&gt;
The Repository Pattern would be useful for separating data access logic since this class is heavily querying the database for create, update, find operations. This involves creating a TeamsParticipantRepository that encapsulates all finders and queries, improving modularity and making it easier to test and reuse.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
class TeamsParticipantRepository&lt;br /&gt;
  def self.find_team_participant(participant_id, team_id)&lt;br /&gt;
    TeamsParticipant.find_by(participant_id: participant_id, team_id: team_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.first_participant_for_team(team_id)&lt;br /&gt;
    TeamsParticipant.find_by(team_id: team_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    TeamsParticipant.where(team_id: team_id).empty?&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
[[File:ClassDiagram_TeamsParticipant.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
==Sequence Diagram==&lt;br /&gt;
[[File:SequenceDiagram_TeamsParticipant.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
==Solutions/Details of Changes Made==&lt;br /&gt;
&lt;br /&gt;
===Phase 1 Improvements===&lt;br /&gt;
&lt;br /&gt;
* Renamed TeamsUser to TeamsParticipant to modify application logic to join Teams with Participants instead of Users&lt;br /&gt;
* Updated associations in immediate neighbor classes i.e Teams, Users and Participants to ensure correctness and consistency in the data model&lt;br /&gt;
* Renamed method names for increased readability and removed redundant methods from the TeamsParticipant class&lt;br /&gt;
* Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity, improving overall maintainability of the codebase&lt;br /&gt;
* Renamed TeamUserNode to TeamParticipantNode for correctness, to align with the new design of Participation association in TeamsParticipant&lt;br /&gt;
* Added migrations to add foreign key for Participant in TeamsParticipant table and updated indexes for the same&lt;br /&gt;
&lt;br /&gt;
===Phase 2 Plan===&lt;br /&gt;
&lt;br /&gt;
* Update associations in all the models that were previously using TeamsUser to implement them with TeamsParticipant&lt;br /&gt;
* Modify implementations of all models, views, and controllers to use Participant with TeamsParticipant class instead of User&lt;br /&gt;
* This future involves modifying queries to retrieve participant and user objects that are passed to the TeamsParticipant class as commands to their methods&lt;br /&gt;
* Deprecate user_id foreign key from TeamsParticipant to completely remove the association of User from TeamsParticant, only linking Participants to Teams&lt;br /&gt;
* Update all the test cases to work with this implementation, including updating associations and mocking DB calls&lt;br /&gt;
&lt;br /&gt;
==Files Added/Modified==&lt;br /&gt;
&lt;br /&gt;
As part of the refactoring process, we need to update all references and method calls related to the TeamsParticipant table and the teams_participant class throughout the repository. This refactor will involve over 200 instances across various files.&lt;br /&gt;
&lt;br /&gt;
The required changes will follow the pattern shown in the attached modifications for models and controllers.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''invitation.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Invitation_model_changes.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''review_mapping_controller.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review_mapping_controller_changes2.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''pair_programming_controller.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Pair_programming_controller_changes.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
We added a new spec file for the teams_participant model, which was previously missing, and fixed issues in the team_participant_controller_spec. Additionally, we resolved model and controller tests for direct associations with Team, User, and Participant.&lt;br /&gt;
&lt;br /&gt;
===Detailed '''Test Plan''' for &amp;lt;code&amp;gt;TeamsParticipant&amp;lt;/code&amp;gt; Model===&lt;br /&gt;
&lt;br /&gt;
1. Associations&lt;br /&gt;
&lt;br /&gt;
 Verify correct associations:&lt;br /&gt;
  * Belongs to participant&lt;br /&gt;
  * Belongs to team&lt;br /&gt;
  * Has one team_participant_node (dependent: destroy)&lt;br /&gt;
&lt;br /&gt;
2. Method: &amp;lt;code&amp;gt;#name&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  Returns participant’s name.&lt;br /&gt;
  Appends &amp;quot;(Mentor)&amp;quot; if participant is a mentor.&lt;br /&gt;
&lt;br /&gt;
3. Method: &amp;lt;code&amp;gt;#delete&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Calls methods for cleanup:&lt;br /&gt;
  * remove_team_participant_node&lt;br /&gt;
  * remove_team_if_participants_empty&lt;br /&gt;
  * remove_teams_participant_instance&lt;br /&gt;
 Destroys itself and associated TeamParticipantNode.&lt;br /&gt;
 Deletes the team if it’s the last participant.&lt;br /&gt;
&lt;br /&gt;
4. Method: &amp;lt;code&amp;gt;.remove_participant&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Destroys TeamsParticipant if it exists.&lt;br /&gt;
 Does nothing if it doesn’t exist.&lt;br /&gt;
&lt;br /&gt;
5. Method: &amp;lt;code&amp;gt;.first_participant_for_team&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Retrieves the first participant for a given team ID.&lt;br /&gt;
&lt;br /&gt;
6. Method: &amp;lt;code&amp;gt;.team_empty?&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Returns true if team has no participants; false otherwise.&lt;br /&gt;
&lt;br /&gt;
7. Method: &amp;lt;code&amp;gt;.add_accepted_invitee_to_team&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Adds a participant to the team, returning true if successful.&lt;br /&gt;
&lt;br /&gt;
8. Method: &amp;lt;code&amp;gt;.team_id&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Returns team ID if participant is assigned to a team.&lt;br /&gt;
 Returns nil if not assigned.&lt;br /&gt;
&lt;br /&gt;
===Sample Changes===&lt;br /&gt;
&lt;br /&gt;
In the next phase, we’ll modify various associations, references, database calls, and methods related to the teams_participant model. This will involve updating table references as needed, adjusting or adding mocks for methods, and revising database queries involving the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
Below are examples of similar changes that need to be implemented across all model and controller specs throughout the repository.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''invitation_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Invitation_spec1.png|800px|center|]]&lt;br /&gt;
[[File:Invitation_spec2.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''review_mapping_controller_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review_map_controller_spec.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''pair_programming_controller_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Pair_prog_controller_spec.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
Next, we’ll update all references and associations of TeamsUser to TeamsParticipant across the repository. This process includes adding and modifying existing test cases and implementing necessary database mocks. Currently, the TeamsParticipant table still holds foreign keys for users, as other models access TeamsParticipant through users.&lt;br /&gt;
&lt;br /&gt;
This can be further improved by replacing direct user associations with participants and retrieving participants through users. This shift will allow us to remove the foreign key constraint for users from the TeamsParticipant table, simplifying its structure. However, this change introduces the need for additional queries to retrieve a participant for a specific user_id before querying TeamsParticipant.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jay, Patel&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
# [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0OSS Projects on Expertiza])&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Github]&lt;br /&gt;
# [https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page Expertiza Wiki]&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=159316</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb (Phase 2 - Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=159316"/>
		<updated>2024-11-13T01:21:39Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: /* Design Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design Pattern==&lt;br /&gt;
&lt;br /&gt;
To manage the complexity and responsibilities of the TeamsParticipant class, the following design patterns can be applied here. Since TeamsParticipant is handling both join table duties and additional business logic, a combination of patterns could improve maintainability and flexibility.&lt;br /&gt;
&lt;br /&gt;
1. '''Facade Pattern''' for Simplifying Interface&lt;br /&gt;
&lt;br /&gt;
The TeamsParticipant class handles multiple responsibilities, from managing teams and participants to removing members and adding members who accepted invites. Applying the Facade Pattern can simplify its interface by offloading complex processes to service classes. For example, a TeamsParticipantService could manage team membership rules, while TeamsParticipantManager could handle table-related operations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
class TeamParticipantService&lt;br /&gt;
  def self.add_accepted_invitee_to_team(inviter_participant_id, invited_participant_id, assignment_id)&lt;br /&gt;
    participants_teams = TeamsParticipant.where(participant_id: inviter_participant_id)&lt;br /&gt;
    participants_teams.any? do |team|&lt;br /&gt;
      assigned_team = AssignmentTeam.find_by(id: team.team_id, parent_id: assignment_id)&lt;br /&gt;
      assigned_team&amp;amp;.add_member(Participant.find(invited_participant_id), assignment_id) if assigned_team&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    TeamsParticipant.where(team_id: team_id).empty?&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, within TeamsParticipant, these actions could be delegated to the facade for simplicity and modularity:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
class TeamsParticipant &amp;lt; ApplicationRecord&lt;br /&gt;
  # Other associations and methods&lt;br /&gt;
  &lt;br /&gt;
  def self.add_accepted_invitee_to_team(*args)&lt;br /&gt;
    TeamParticipantService.add_accepted_invitee_to_team(*args)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. '''Repository Pattern''' for Database Queries&lt;br /&gt;
&lt;br /&gt;
The Repository Pattern would be useful for separating data access logic since this class is heavily querying the database for create, update, find operations. This involves creating a TeamsParticipantRepository that encapsulates all finders and queries, improving modularity and making it easier to test and reuse.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
class TeamsParticipantRepository&lt;br /&gt;
  def self.find_team_participant(participant_id, team_id)&lt;br /&gt;
    TeamsParticipant.find_by(participant_id: participant_id, team_id: team_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.first_participant_for_team(team_id)&lt;br /&gt;
    TeamsParticipant.find_by(team_id: team_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    TeamsParticipant.where(team_id: team_id).empty?&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
[[File:ClassDiagram_TeamsParticipant.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
==Sequence Diagram==&lt;br /&gt;
[[File:SequenceDiagram_TeamsParticipant.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
==Solutions/Details of Changes Made==&lt;br /&gt;
&lt;br /&gt;
===Phase 1 Improvements===&lt;br /&gt;
&lt;br /&gt;
* Renamed TeamsUser to TeamsParticipant to modify application logic to join Teams with Participants instead of Users&lt;br /&gt;
* Updated associations in immediate neighbor classes i.e Teams, Users and Participants to ensure correctness and consistency in the data model&lt;br /&gt;
* Renamed method names for increased readability and removed redundant methods from the TeamsParticipant class&lt;br /&gt;
* Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity, improving overall maintainability of the codebase&lt;br /&gt;
* Renamed TeamUserNode to TeamParticipantNode for correctness, to align with the new design of Participation association in TeamsParticipant&lt;br /&gt;
* Added migrations to add foreign key for Participant in TeamsParticipant table and updated indexes for the same&lt;br /&gt;
&lt;br /&gt;
===Phase 2 Plan===&lt;br /&gt;
&lt;br /&gt;
* Update associations in all the models that were previously using TeamsUser to implement them with TeamsParticipant&lt;br /&gt;
* Modify implementations of all models, views, and controllers to use Participant with TeamsParticipant class instead of User&lt;br /&gt;
* This future involves modifying queries to retrieve participant and user objects that are passed to the TeamsParticipant class as commands to their methods&lt;br /&gt;
* Deprecate user_id foreign key from TeamsParticipant to completely remove the association of User from TeamsParticant, only linking Participants to Teams&lt;br /&gt;
* Update all the test cases to work with this implementation, including updating associations and mocking DB calls&lt;br /&gt;
&lt;br /&gt;
==Files Added/Modified==&lt;br /&gt;
&lt;br /&gt;
As part of the refactoring process, we need to update all references and method calls related to the TeamsParticipant table and the teams_participant class throughout the repository. This refactor will involve over 200 instances across various files.&lt;br /&gt;
&lt;br /&gt;
The required changes will follow the pattern shown in the attached modifications for models and controllers.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''invitation.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Invitation_model_changes.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''review_mapping_controller.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review_mapping_controller_changes2.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''pair_programming_controller.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Pair_programming_controller_changes.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
We added a new spec file for the teams_participant model, which was previously missing, and fixed issues in the team_participant_controller_spec. Additionally, we resolved model and controller tests for direct associations with Team, User, and Participant.&lt;br /&gt;
&lt;br /&gt;
===Detailed '''Test Plan''' for &amp;lt;code&amp;gt;TeamsParticipant&amp;lt;/code&amp;gt; Model===&lt;br /&gt;
&lt;br /&gt;
1. Associations&lt;br /&gt;
&lt;br /&gt;
 Verify correct associations:&lt;br /&gt;
  * Belongs to participant&lt;br /&gt;
  * Belongs to team&lt;br /&gt;
  * Has one team_participant_node (dependent: destroy)&lt;br /&gt;
&lt;br /&gt;
2. Method: &amp;lt;code&amp;gt;#name&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  Returns participant’s name.&lt;br /&gt;
  Appends &amp;quot;(Mentor)&amp;quot; if participant is a mentor.&lt;br /&gt;
&lt;br /&gt;
3. Method: &amp;lt;code&amp;gt;#delete&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Calls methods for cleanup:&lt;br /&gt;
  * remove_team_participant_node&lt;br /&gt;
  * remove_team_if_participants_empty&lt;br /&gt;
  * remove_teams_participant_instance&lt;br /&gt;
 Destroys itself and associated TeamParticipantNode.&lt;br /&gt;
 Deletes the team if it’s the last participant.&lt;br /&gt;
&lt;br /&gt;
4. Method: &amp;lt;code&amp;gt;.remove_participant&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Destroys TeamsParticipant if it exists.&lt;br /&gt;
 Does nothing if it doesn’t exist.&lt;br /&gt;
&lt;br /&gt;
5. Method: &amp;lt;code&amp;gt;.first_participant_for_team&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Retrieves the first participant for a given team ID.&lt;br /&gt;
&lt;br /&gt;
6. Method: &amp;lt;code&amp;gt;.team_empty?&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Returns true if team has no participants; false otherwise.&lt;br /&gt;
&lt;br /&gt;
7. Method: &amp;lt;code&amp;gt;.add_accepted_invitee_to_team&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Adds a participant to the team, returning true if successful.&lt;br /&gt;
&lt;br /&gt;
8. Method: &amp;lt;code&amp;gt;.team_id&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Returns team ID if participant is assigned to a team.&lt;br /&gt;
 Returns nil if not assigned.&lt;br /&gt;
&lt;br /&gt;
===Sample Changes===&lt;br /&gt;
&lt;br /&gt;
In the next phase, we’ll modify various associations, references, database calls, and methods related to the teams_participant model. This will involve updating table references as needed, adjusting or adding mocks for methods, and revising database queries involving the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
Below are examples of similar changes that need to be implemented across all model and controller specs throughout the repository.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''invitation_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Invitation_spec1.png|800px|center|]]&lt;br /&gt;
[[File:Invitation_spec2.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''review_mapping_controller_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review_map_controller_spec.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''pair_programming_controller_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Pair_prog_controller_spec.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
During the refactoring from TeamsUser to TeamsParticipant, we initially retained the association between teams and users (with user_id as a foreign key) in TeamsParticipant. This approach was for backward compatibility, ensuring that other classes and tests would function without immediate disruption.&lt;br /&gt;
&lt;br /&gt;
The next phase will involve fully removing this direct association between teams and users. Instead, we will maintain only the teams-participant relationship in the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
This update will require modifying all references to TeamsParticipant across models and controllers, and adjusting logic to work with Participant instead of User. Certain cases do need user-specific fields previously stored within TeamsParticipant. With the user association deprecated, these areas will need updated logic to retrieve the user associated with each participant. This ensures continued functionality and accuracy of the code. Corresponding updates will also be necessary in the spec files to align with the changes.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jay, Patel&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
# [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0OSS Projects on Expertiza])&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Github]&lt;br /&gt;
# [https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page Expertiza Wiki]&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=159245</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb (Phase 2 - Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=159245"/>
		<updated>2024-11-13T00:42:46Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design Pattern==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
[[File:ClassDiagram_TeamsParticipant.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
==Sequence Diagram==&lt;br /&gt;
[[File:SequenceDiagram_TeamsParticipant.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
==Solutions/Details of Changes Made==&lt;br /&gt;
&lt;br /&gt;
===Phase 1 Improvements===&lt;br /&gt;
&lt;br /&gt;
* Renamed TeamsUser to TeamsParticipant to modify application logic to join Teams with Participants instead of Users&lt;br /&gt;
* Updated associations in immediate neighbor classes i.e Teams, Users and Participants to ensure correctness and consistency in the data model&lt;br /&gt;
* Renamed method names for increased readability and removed redundant methods from the TeamsParticipant class&lt;br /&gt;
* Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity, improving overall maintainability of the codebase&lt;br /&gt;
* Renamed TeamUserNode to TeamParticipantNode for correctness, to align with the new design of Participation association in TeamsParticipant&lt;br /&gt;
* Added migrations to add foreign key for Participant in TeamsParticipant table and updated indexes for the same&lt;br /&gt;
&lt;br /&gt;
===Phase 2 Plan===&lt;br /&gt;
&lt;br /&gt;
* Update associations in all the models that were previously using TeamsUser to implement them with TeamsParticipant&lt;br /&gt;
* Modify implementations of all models, views, and controllers to use Participant with TeamsParticipant class instead of User&lt;br /&gt;
* This future involves modifying queries to retrieve participant and user objects that are passed to the TeamsParticipant class as commands to their methods&lt;br /&gt;
* Deprecate user_id foreign key from TeamsParticipant to completely remove the association of User from TeamsParticant, only linking Participants to Teams&lt;br /&gt;
* Update all the test cases to work with this implementation, including updating associations and mocking DB calls&lt;br /&gt;
&lt;br /&gt;
==Files Added/Modified==&lt;br /&gt;
&lt;br /&gt;
As part of the refactoring process, we need to update all references and method calls related to the TeamsParticipant table and the teams_participant class throughout the repository. This refactor will involve over 200 instances across various files.&lt;br /&gt;
&lt;br /&gt;
The required changes will follow the pattern shown in the attached modifications for models and controllers.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''invitation.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Invitation_model_changes.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''review_mapping_controller.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review_mapping_controller_changes2.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''pair_programming_controller.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Pair_programming_controller_changes.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
We added a new spec file for the teams_participant model, which was previously missing, and fixed issues in the team_participant_controller_spec. Additionally, we resolved model and controller tests for direct associations with Team, User, and Participant.&lt;br /&gt;
&lt;br /&gt;
===Detailed '''Test Plan''' for &amp;lt;code&amp;gt;TeamsParticipant&amp;lt;/code&amp;gt; Model===&lt;br /&gt;
&lt;br /&gt;
1. Associations&lt;br /&gt;
&lt;br /&gt;
 Verify correct associations:&lt;br /&gt;
  * Belongs to participant&lt;br /&gt;
  * Belongs to team&lt;br /&gt;
  * Has one team_participant_node (dependent: destroy)&lt;br /&gt;
&lt;br /&gt;
2. Method: &amp;lt;code&amp;gt;#name&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  Returns participant’s name.&lt;br /&gt;
  Appends &amp;quot;(Mentor)&amp;quot; if participant is a mentor.&lt;br /&gt;
&lt;br /&gt;
3. Method: &amp;lt;code&amp;gt;#delete&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Calls methods for cleanup:&lt;br /&gt;
  * remove_team_participant_node&lt;br /&gt;
  * remove_team_if_participants_empty&lt;br /&gt;
  * remove_teams_participant_instance&lt;br /&gt;
 Destroys itself and associated TeamParticipantNode.&lt;br /&gt;
 Deletes the team if it’s the last participant.&lt;br /&gt;
&lt;br /&gt;
4. Method: &amp;lt;code&amp;gt;.remove_participant&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Destroys TeamsParticipant if it exists.&lt;br /&gt;
 Does nothing if it doesn’t exist.&lt;br /&gt;
&lt;br /&gt;
5. Method: &amp;lt;code&amp;gt;.first_participant_for_team&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Retrieves the first participant for a given team ID.&lt;br /&gt;
&lt;br /&gt;
6. Method: &amp;lt;code&amp;gt;.team_empty?&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Returns true if team has no participants; false otherwise.&lt;br /&gt;
&lt;br /&gt;
7. Method: &amp;lt;code&amp;gt;.add_accepted_invitee_to_team&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Adds a participant to the team, returning true if successful.&lt;br /&gt;
&lt;br /&gt;
8. Method: &amp;lt;code&amp;gt;.team_id&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Returns team ID if participant is assigned to a team.&lt;br /&gt;
 Returns nil if not assigned.&lt;br /&gt;
&lt;br /&gt;
===Sample Changes===&lt;br /&gt;
&lt;br /&gt;
In the next phase, we’ll modify various associations, references, database calls, and methods related to the teams_participant model. This will involve updating table references as needed, adjusting or adding mocks for methods, and revising database queries involving the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
Below are examples of similar changes that need to be implemented across all model and controller specs throughout the repository.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''invitation_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Invitation_spec1.png|800px|center|]]&lt;br /&gt;
[[File:Invitation_spec2.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''review_mapping_controller_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review_map_controller_spec.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''pair_programming_controller_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Pair_prog_controller_spec.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
During the refactoring from TeamsUser to TeamsParticipant, we initially retained the association between teams and users (with user_id as a foreign key) in TeamsParticipant. This approach was for backward compatibility, ensuring that other classes and tests would function without immediate disruption.&lt;br /&gt;
&lt;br /&gt;
The next phase will involve fully removing this direct association between teams and users. Instead, we will maintain only the teams-participant relationship in the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
This update will require modifying all references to TeamsParticipant across models and controllers, and adjusting logic to work with Participant instead of User. Certain cases do need user-specific fields previously stored within TeamsParticipant. With the user association deprecated, these areas will need updated logic to retrieve the user associated with each participant. This ensures continued functionality and accuracy of the code. Corresponding updates will also be necessary in the spec files to align with the changes.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jay, Patel&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
# [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0OSS Projects on Expertiza])&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Github]&lt;br /&gt;
# [https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page Expertiza Wiki]&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=159222</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb (Phase 2 - Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=159222"/>
		<updated>2024-11-13T00:30:27Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design Pattern==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
[[File:ClassDiagram_TeamsParticipant.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
==Sequence Diagram==&lt;br /&gt;
[[File:SequenceDiagram_TeamsParticipant.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
==Solutions/Details of Changes Made==&lt;br /&gt;
&lt;br /&gt;
===Phase 1 Improvements===&lt;br /&gt;
&lt;br /&gt;
* Renamed TeamsUser to TeamsParticipant to modify application logic to join Teams with Participants instead of Users&lt;br /&gt;
* Updated associations in immediate neighbor classes i.e Teams, Users and Participants to ensure correctness and consistency in the data model&lt;br /&gt;
* Renamed method names for increased readability and removed redundant methods from the TeamsParticipant class&lt;br /&gt;
* Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity, improving overall maintainability of the codebase&lt;br /&gt;
* Renamed TeamUserNode to TeamParticipantNode for correctness, to align with the new design of Participation association in TeamsParticipant&lt;br /&gt;
* Added migrations to add foreign key for Participant in TeamsParticipant table and updated indexes for the same&lt;br /&gt;
&lt;br /&gt;
===Phase 2 Plan===&lt;br /&gt;
&lt;br /&gt;
* Update associations in all the models that were previously using TeamsUser to implement them with TeamsParticipant&lt;br /&gt;
* Modify implementations of all models, views, and controllers to use Participant with TeamsParticipant class instead of User&lt;br /&gt;
* This future involves modifying queries to retrieve participant and user objects that are passed to the TeamsParticipant class as commands to their methods&lt;br /&gt;
* Deprecate user_id foreign key from TeamsParticipant to completely remove the association of User from TeamsParticant, only linking Participants to Teams&lt;br /&gt;
* Update all the test cases to work with this implementation, including updating associations and mocking DB calls&lt;br /&gt;
&lt;br /&gt;
==Files Added/Modified==&lt;br /&gt;
&lt;br /&gt;
As part of the refactoring process, we need to update all references and method calls related to the TeamsParticipant table and the teams_participant class throughout the repository. This refactor will involve over 200 instances across various files.&lt;br /&gt;
&lt;br /&gt;
The required changes will follow the pattern shown in the attached modifications for models and controllers.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''invitation.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Invitation_model_changes.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''review_mapping_controller.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review_mapping_controller_changes2.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''pair_programming_controller.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Pair_programming_controller_changes.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
We added a new spec file for the teams_participant model which was missing and fixed team_participant_controller_spec. Also as an additional step, we fixed model and controller tests for direct associations: Team, User, and Participant.&lt;br /&gt;
&lt;br /&gt;
For the next phase, we must modify various associations, references, DB calls, and method classes around the team_participant model. This will include changing the references for tables wherever needed, modifying/adding mocking for methods, and DB queries for the Teams_Participant table.&lt;br /&gt;
&lt;br /&gt;
Below are some of similar changes that we need to do for all models and controllers specs throughout the repository &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''invitation_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Invitation_spec1.png|800px|center|]]&lt;br /&gt;
[[File:Invitation_spec2.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''review_mapping_controller_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review_map_controller_spec.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''pair_programming_controller_spec.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Pair_prog_controller_spec.png|800px|center|]]&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
During the refactoring from TeamsUser to TeamsParticipant, we initially retained the association between teams and users (with user_id as a foreign key) in TeamsParticipant. This approach was for backward compatibility, ensuring that other classes and tests would function without immediate disruption.&lt;br /&gt;
&lt;br /&gt;
The next phase will involve fully removing this direct association between teams and users. Instead, we will maintain only the teams-participant relationship in the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
This update will require modifying all references to TeamsParticipant across models and controllers, and adjusting logic to work with Participant instead of User. Certain cases do need user-specific fields previously stored within TeamsParticipant. With the user association deprecated, these areas will need updated logic to retrieve the user associated with each participant. This ensures continued functionality and accuracy of the code. Corresponding updates will also be necessary in the spec files to align with the changes.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jay, Patel&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
# [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0OSS Projects on Expertiza])&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Github]&lt;br /&gt;
# [https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page Expertiza Wiki]&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Pair_prog_controller_spec.png&amp;diff=159220</id>
		<title>File:Pair prog controller spec.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Pair_prog_controller_spec.png&amp;diff=159220"/>
		<updated>2024-11-13T00:29:04Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Review_map_controller_spec.png&amp;diff=159219</id>
		<title>File:Review map controller spec.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Review_map_controller_spec.png&amp;diff=159219"/>
		<updated>2024-11-13T00:28:29Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Invitation_spec2.png&amp;diff=159218</id>
		<title>File:Invitation spec2.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Invitation_spec2.png&amp;diff=159218"/>
		<updated>2024-11-13T00:27:36Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Invitation_spec1.png&amp;diff=159217</id>
		<title>File:Invitation spec1.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Invitation_spec1.png&amp;diff=159217"/>
		<updated>2024-11-13T00:27:15Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=159215</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb (Phase 2 - Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=159215"/>
		<updated>2024-11-13T00:22:54Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: /* Files Added/Modified */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design Pattern==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
[[File:ClassDiagram_TeamsParticipant.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
==Sequence Diagram==&lt;br /&gt;
[[File:SequenceDiagram_TeamsParticipant.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
==Solutions/Details of Changes Made==&lt;br /&gt;
&lt;br /&gt;
===Phase 1 Improvements===&lt;br /&gt;
&lt;br /&gt;
* Renamed TeamsUser to TeamsParticipant to modify application logic to join Teams with Participants instead of Users&lt;br /&gt;
* Updated associations in immediate neighbor classes i.e Teams, Users and Participants to ensure correctness and consistency in the data model&lt;br /&gt;
* Renamed method names for increased readability and removed redundant methods from the TeamsParticipant class&lt;br /&gt;
* Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity, improving overall maintainability of the codebase&lt;br /&gt;
* Renamed TeamUserNode to TeamParticipantNode for correctness, to align with the new design of Participation association in TeamsParticipant&lt;br /&gt;
* Added migrations to add foreign key for Participant in TeamsParticipant table and updated indexes for the same&lt;br /&gt;
&lt;br /&gt;
===Phase 2 Plan===&lt;br /&gt;
&lt;br /&gt;
* Update associations in all the models that were previously using TeamsUser to implement them with TeamsParticipant&lt;br /&gt;
* Modify implementations of all models, views, and controllers to use Participant with TeamsParticipant class instead of User&lt;br /&gt;
* This future involves modifying queries to retrieve participant and user objects that are passed to the TeamsParticipant class as commands to their methods&lt;br /&gt;
* Deprecate user_id foreign key from TeamsParticipant to completely remove the association of User from TeamsParticant, only linking Participants to Teams&lt;br /&gt;
* Update all the test cases to work with this implementation, including updating associations and mocking DB calls&lt;br /&gt;
&lt;br /&gt;
==Files Added/Modified==&lt;br /&gt;
&lt;br /&gt;
As part of the refactoring process, we need to update all references and method calls related to the TeamsParticipant table and the teams_participant class throughout the repository. This refactor will involve over 200 instances across various files.&lt;br /&gt;
&lt;br /&gt;
The required changes will follow the pattern shown in the attached modifications for models and controllers.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''invitation.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Invitation_model_changes.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''review_mapping_controller.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review_mapping_controller_changes2.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''pair_programming_controller.rb'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Pair_programming_controller_changes.png|1000px|center|]]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
We added a new spec file for the teams_participant model which was missing and fixed team_participant_controller_spec. Also as an additional step, we fixed model and controller tests for direct associations: Team, User, and Participant.&lt;br /&gt;
&lt;br /&gt;
===Code coverage===&lt;br /&gt;
&lt;br /&gt;
'''Before refactoring: 0%'''&lt;br /&gt;
&lt;br /&gt;
'''After refactoring: 100%'''&lt;br /&gt;
&lt;br /&gt;
[[File:teams-participant-code-cov.png|800px|center|Code coverage for &amp;lt;code&amp;gt;teams_participant.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams_participant_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:User_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams_participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Users_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
During the refactoring from TeamsUser to TeamsParticipant, we initially retained the association between teams and users (with user_id as a foreign key) in TeamsParticipant. This approach was for backward compatibility, ensuring that other classes and tests would function without immediate disruption.&lt;br /&gt;
&lt;br /&gt;
The next phase will involve fully removing this direct association between teams and users. Instead, we will maintain only the teams-participant relationship in the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
This update will require modifying all references to TeamsParticipant across models and controllers, and adjusting logic to work with Participant instead of User. Certain cases do need user-specific fields previously stored within TeamsParticipant. With the user association deprecated, these areas will need updated logic to retrieve the user associated with each participant. This ensures continued functionality and accuracy of the code. Corresponding updates will also be necessary in the spec files to align with the changes.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jay, Patel&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
# [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0OSS Projects on Expertiza])&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Github]&lt;br /&gt;
# [https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page Expertiza Wiki]&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Review_mapping_controller_changes2.png&amp;diff=159214</id>
		<title>File:Review mapping controller changes2.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Review_mapping_controller_changes2.png&amp;diff=159214"/>
		<updated>2024-11-13T00:21:27Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Pair_programming_controller_changes.png&amp;diff=159209</id>
		<title>File:Pair programming controller changes.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Pair_programming_controller_changes.png&amp;diff=159209"/>
		<updated>2024-11-13T00:19:39Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Invitation_model_changes.png&amp;diff=159206</id>
		<title>File:Invitation model changes.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Invitation_model_changes.png&amp;diff=159206"/>
		<updated>2024-11-13T00:17:45Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=158773</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb (Phase 2 - Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=158773"/>
		<updated>2024-11-10T23:00:43Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: /* Phase 2 Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design Pattern==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use Cases==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Solutions/Details of Changes Made==&lt;br /&gt;
&lt;br /&gt;
===Phase 1 Improvements===&lt;br /&gt;
&lt;br /&gt;
* Renamed TeamsUser to TeamsParticipant to modify application logic to join Teams with Participants instead of Users&lt;br /&gt;
* Updated associations in immediate neighbor classes i.e Teams, Users and Participants to ensure correctness and consistency in the data model&lt;br /&gt;
* Renamed method names for increased readability and removed redundant methods from the TeamsParticipant class&lt;br /&gt;
* Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity, improving overall maintainability of the codebase&lt;br /&gt;
* Renamed TeamUserNode to TeamParticipantNode for correctness, to align with the new design of Participation association in TeamsParticipant&lt;br /&gt;
* Added migrations to add foreign key for Participant in TeamsParticipant table and updated indexes for the same&lt;br /&gt;
&lt;br /&gt;
===Phase 2 Plan===&lt;br /&gt;
&lt;br /&gt;
* Update associations in all the models that were previously using TeamsUser to implement them with TeamsParticipant&lt;br /&gt;
* Modify implementations of all models, views, and controllers to use Participant with TeamsParticipant class instead of User&lt;br /&gt;
* This future involves modifying queries to retrieve participant and user objects that are passed to the TeamsParticipant class as commands to their methods&lt;br /&gt;
* Deprecate user_id foreign key from TeamsParticipant to completely remove the association of User from TeamsParticant, only linking Participants to Teams&lt;br /&gt;
* Update all the test cases to work with this implementation, including updating associations and mocking DB calls&lt;br /&gt;
&lt;br /&gt;
==Files Added/Modified==&lt;br /&gt;
&lt;br /&gt;
Changed files in &amp;lt;code&amp;gt;Model&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
==== Changes to &amp;lt;code&amp;gt;app/models/teams_user.rb&amp;lt;/code&amp;gt; ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamsUser to TeamsParticipant  &lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Updated associations to reference Participants&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Removed &amp;lt;code&amp;gt;get_team_members&amp;lt;/code&amp;gt; from teams_participant model&lt;br /&gt;
|The method was empty without any logic so it was just a placeholder method without any usage across the project.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|Renamed methods: &amp;lt;code&amp;gt;remove_team_if_participants_empty&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;remove_team_participant&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;first_participant_for_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for clarity&lt;br /&gt;
|Improves code readability for new programmers.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity&lt;br /&gt;
|To reduce Cognitive Complexity and making the model more maintainable and efficient&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Changes to &amp;lt;code&amp;gt;app/models/team_user_node.rb&amp;lt;/code&amp;gt; ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamUserNode to TeamParticipantNode&lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users for node associations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/d5cacfa663e1358a522f52d676f7c6cb7a7ec3f0 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Modified queries in TeamParticipantNode to use teams_participant instead of teams_user&lt;br /&gt;
|Aligns with the changes made in teams_participant model to add new participant association.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/d5cacfa663e1358a522f52d676f7c6cb7a7ec3f0 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Updated associations to reference TeamUserNode in entire repository&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
We added a new spec file for the teams_participant model which was missing and fixed team_participant_controller_spec. Also as an additional step, we fixed model and controller tests for direct associations: Team, User, and Participant.&lt;br /&gt;
&lt;br /&gt;
===Code coverage===&lt;br /&gt;
&lt;br /&gt;
'''Before refactoring: 0%'''&lt;br /&gt;
&lt;br /&gt;
'''After refactoring: 100%'''&lt;br /&gt;
&lt;br /&gt;
[[File:teams-participant-code-cov.png|800px|center|Code coverage for &amp;lt;code&amp;gt;teams_participant.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams_participant_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:User_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams_participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Users_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
During the refactoring from TeamsUser to TeamsParticipant, we initially retained the association between teams and users (with user_id as a foreign key) in TeamsParticipant. This approach was for backward compatibility, ensuring that other classes and tests would function without immediate disruption.&lt;br /&gt;
&lt;br /&gt;
The next phase will involve fully removing this direct association between teams and users. Instead, we will maintain only the teams-participant relationship in the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
This update will require modifying all references to TeamsParticipant across models and controllers, and adjusting logic to work with Participant instead of User. Certain cases do need user-specific fields previously stored within TeamsParticipant. With the user association deprecated, these areas will need updated logic to retrieve the user associated with each participant. This ensures continued functionality and accuracy of the code. Corresponding updates will also be necessary in the spec files to align with the changes.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jay, Patel&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
# [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0OSS Projects on Expertiza])&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Github]&lt;br /&gt;
# [https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page Expertiza Wiki]&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=158772</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb (Phase 2 - Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=158772"/>
		<updated>2024-11-10T22:45:07Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: /* Phase1 Improvements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design Pattern==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use Cases==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Solutions/Details of Changes Made==&lt;br /&gt;
&lt;br /&gt;
===Phase 1 Improvements===&lt;br /&gt;
&lt;br /&gt;
* Renamed TeamsUser to TeamsParticipant to modify application logic to join Teams with Participants instead of Users&lt;br /&gt;
* Updated associations in immediate neighbor classes i.e Teams, Users and Participants to ensure correctness and consistency in the data model&lt;br /&gt;
* Renamed method names for increased readability and removed redundant methods from the TeamsParticipant class&lt;br /&gt;
* Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity, improving overall maintainability of the codebase&lt;br /&gt;
* Renamed TeamUserNode to TeamParticipantNode for correctness, to align with the new design of Participation association in TeamsParticipant&lt;br /&gt;
* Added migrations to add foreign key for Participant in TeamsParticipant table and updated indexes for the same&lt;br /&gt;
&lt;br /&gt;
===Phase 2 Plan===&lt;br /&gt;
&lt;br /&gt;
* Update associations in all the models that were previously using TeamsUser to implement them with TeamsParticipant&lt;br /&gt;
* Modify implementations of all models, views, and controllers to use Participant with TeamsParticipant class instead of User&lt;br /&gt;
* This future involves modifying queries to retrieve participant and user objects that are passed to the TeamsParticipant class as commands to their methods&lt;br /&gt;
* Deprecate user_id foreign key from TeamsParticipant to completely remove the association of User from TeamsParticant, only linking Participants to Teams&lt;br /&gt;
* Update all the test cases to work with this implementation and mock DB calls&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Files Added/Modified==&lt;br /&gt;
&lt;br /&gt;
Changed files in &amp;lt;code&amp;gt;Model&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
==== Changes to &amp;lt;code&amp;gt;app/models/teams_user.rb&amp;lt;/code&amp;gt; ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamsUser to TeamsParticipant  &lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Updated associations to reference Participants&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Removed &amp;lt;code&amp;gt;get_team_members&amp;lt;/code&amp;gt; from teams_participant model&lt;br /&gt;
|The method was empty without any logic so it was just a placeholder method without any usage across the project.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|Renamed methods: &amp;lt;code&amp;gt;remove_team_if_participants_empty&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;remove_team_participant&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;first_participant_for_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for clarity&lt;br /&gt;
|Improves code readability for new programmers.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity&lt;br /&gt;
|To reduce Cognitive Complexity and making the model more maintainable and efficient&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Changes to &amp;lt;code&amp;gt;app/models/team_user_node.rb&amp;lt;/code&amp;gt; ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamUserNode to TeamParticipantNode&lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users for node associations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/d5cacfa663e1358a522f52d676f7c6cb7a7ec3f0 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Modified queries in TeamParticipantNode to use teams_participant instead of teams_user&lt;br /&gt;
|Aligns with the changes made in teams_participant model to add new participant association.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/d5cacfa663e1358a522f52d676f7c6cb7a7ec3f0 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Updated associations to reference TeamUserNode in entire repository&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
We added a new spec file for the teams_participant model which was missing and fixed team_participant_controller_spec. Also as an additional step, we fixed model and controller tests for direct associations: Team, User, and Participant.&lt;br /&gt;
&lt;br /&gt;
===Code coverage===&lt;br /&gt;
&lt;br /&gt;
'''Before refactoring: 0%'''&lt;br /&gt;
&lt;br /&gt;
'''After refactoring: 100%'''&lt;br /&gt;
&lt;br /&gt;
[[File:teams-participant-code-cov.png|800px|center|Code coverage for &amp;lt;code&amp;gt;teams_participant.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams_participant_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:User_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams_participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Users_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
During the refactoring from TeamsUser to TeamsParticipant, we initially retained the association between teams and users (with user_id as a foreign key) in TeamsParticipant. This approach was for backward compatibility, ensuring that other classes and tests would function without immediate disruption.&lt;br /&gt;
&lt;br /&gt;
The next phase will involve fully removing this direct association between teams and users. Instead, we will maintain only the teams-participant relationship in the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
This update will require modifying all references to TeamsParticipant across models and controllers, and adjusting logic to work with Participant instead of User. Certain cases do need user-specific fields previously stored within TeamsParticipant. With the user association deprecated, these areas will need updated logic to retrieve the user associated with each participant. This ensures continued functionality and accuracy of the code. Corresponding updates will also be necessary in the spec files to align with the changes.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jay, Patel&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
# [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0OSS Projects on Expertiza])&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Github]&lt;br /&gt;
# [https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page Expertiza Wiki]&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=158771</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb (Phase 2 - Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=158771"/>
		<updated>2024-11-10T22:44:33Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: /* Phase2 Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design Pattern==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use Cases==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Solutions/Details of Changes Made==&lt;br /&gt;
&lt;br /&gt;
==Phase1 Improvements==&lt;br /&gt;
&lt;br /&gt;
* Renamed TeamsUser to TeamsParticipant to modify application logic to join Teams with Participants instead of Users&lt;br /&gt;
* Updated associations in immediate neighbor classes i.e Teams, Users and Participants to ensure correctness and consistency in the data model&lt;br /&gt;
* Renamed method names for increased readability and removed redundant methods from the TeamsParticipant class&lt;br /&gt;
* Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity, improving overall maintainability of the codebase&lt;br /&gt;
* Renamed TeamUserNode to TeamParticipantNode for correctness, to align with the new design of Participation association in TeamsParticipant&lt;br /&gt;
* Added migrations to add foreign key for Participant in TeamsParticipant table and updated indexes for the same&lt;br /&gt;
&lt;br /&gt;
===Phase2 Plan===&lt;br /&gt;
&lt;br /&gt;
* Update associations in all the models that were previously using TeamsUser to implement them with TeamsParticipant&lt;br /&gt;
* Modify implementations of all models, views, and controllers to use Participant with TeamsParticipant class instead of User&lt;br /&gt;
* This future involves modifying queries to retrieve participant and user objects that are passed to the TeamsParticipant class as commands to their methods&lt;br /&gt;
* Deprecate user_id foreign key from TeamsParticipant to completely remove the association of User from TeamsParticant, only linking Participants to Teams&lt;br /&gt;
* Update all the test cases to work with this implementation and mock DB calls&lt;br /&gt;
&lt;br /&gt;
===Files Modified===&lt;br /&gt;
&lt;br /&gt;
Changed files in &amp;lt;code&amp;gt;Model&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
==== Changes to &amp;lt;code&amp;gt;app/models/teams_user.rb&amp;lt;/code&amp;gt; ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamsUser to TeamsParticipant  &lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Updated associations to reference Participants&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Removed &amp;lt;code&amp;gt;get_team_members&amp;lt;/code&amp;gt; from teams_participant model&lt;br /&gt;
|The method was empty without any logic so it was just a placeholder method without any usage across the project.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|Renamed methods: &amp;lt;code&amp;gt;remove_team_if_participants_empty&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;remove_team_participant&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;first_participant_for_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for clarity&lt;br /&gt;
|Improves code readability for new programmers.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity&lt;br /&gt;
|To reduce Cognitive Complexity and making the model more maintainable and efficient&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Changes to &amp;lt;code&amp;gt;app/models/team_user_node.rb&amp;lt;/code&amp;gt; ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamUserNode to TeamParticipantNode&lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users for node associations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/d5cacfa663e1358a522f52d676f7c6cb7a7ec3f0 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Modified queries in TeamParticipantNode to use teams_participant instead of teams_user&lt;br /&gt;
|Aligns with the changes made in teams_participant model to add new participant association.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/d5cacfa663e1358a522f52d676f7c6cb7a7ec3f0 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Updated associations to reference TeamUserNode in entire repository&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
We added a new spec file for the teams_participant model which was missing and fixed team_participant_controller_spec. Also as an additional step, we fixed model and controller tests for direct associations: Team, User, and Participant.&lt;br /&gt;
&lt;br /&gt;
===Code coverage===&lt;br /&gt;
&lt;br /&gt;
'''Before refactoring: 0%'''&lt;br /&gt;
&lt;br /&gt;
'''After refactoring: 100%'''&lt;br /&gt;
&lt;br /&gt;
[[File:teams-participant-code-cov.png|800px|center|Code coverage for &amp;lt;code&amp;gt;teams_participant.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams_participant_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:User_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams_participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Users_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
During the refactoring from TeamsUser to TeamsParticipant, we initially retained the association between teams and users (with user_id as a foreign key) in TeamsParticipant. This approach was for backward compatibility, ensuring that other classes and tests would function without immediate disruption.&lt;br /&gt;
&lt;br /&gt;
The next phase will involve fully removing this direct association between teams and users. Instead, we will maintain only the teams-participant relationship in the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
This update will require modifying all references to TeamsParticipant across models and controllers, and adjusting logic to work with Participant instead of User. Certain cases do need user-specific fields previously stored within TeamsParticipant. With the user association deprecated, these areas will need updated logic to retrieve the user associated with each participant. This ensures continued functionality and accuracy of the code. Corresponding updates will also be necessary in the spec files to align with the changes.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jay, Patel&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
# [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0OSS Projects on Expertiza])&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Github]&lt;br /&gt;
# [https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page Expertiza Wiki]&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=158770</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb (Phase 2 - Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=158770"/>
		<updated>2024-11-10T22:44:03Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: /* Phase1 Improvements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design Pattern==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use Cases==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Solutions/Details of Changes Made==&lt;br /&gt;
&lt;br /&gt;
==Phase1 Improvements==&lt;br /&gt;
&lt;br /&gt;
* Renamed TeamsUser to TeamsParticipant to modify application logic to join Teams with Participants instead of Users&lt;br /&gt;
* Updated associations in immediate neighbor classes i.e Teams, Users and Participants to ensure correctness and consistency in the data model&lt;br /&gt;
* Renamed method names for increased readability and removed redundant methods from the TeamsParticipant class&lt;br /&gt;
* Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity, improving overall maintainability of the codebase&lt;br /&gt;
* Renamed TeamUserNode to TeamParticipantNode for correctness, to align with the new design of Participation association in TeamsParticipant&lt;br /&gt;
* Added migrations to add foreign key for Participant in TeamsParticipant table and updated indexes for the same&lt;br /&gt;
&lt;br /&gt;
==Phase2 Plan==&lt;br /&gt;
&lt;br /&gt;
- Update associations in all the models that were previously using TeamsUser to implement them with TeamsParticipant&lt;br /&gt;
- Modify implementations of all models, views, and controllers to use Participant with TeamsParticipant class instead of User&lt;br /&gt;
- This future involves modifying queries to retrieve participant and user objects that are passed to the TeamsParticipant class as commands to their methods&lt;br /&gt;
- Deprecate user_id foreign key from TeamsParticipant to completely remove the association of User from TeamsParticant, only linking Participants to Teams&lt;br /&gt;
- Update all the test cases to work with this implementation and mock DB calls&lt;br /&gt;
&lt;br /&gt;
===Files Modified===&lt;br /&gt;
&lt;br /&gt;
Changed files in &amp;lt;code&amp;gt;Model&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
==== Changes to &amp;lt;code&amp;gt;app/models/teams_user.rb&amp;lt;/code&amp;gt; ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamsUser to TeamsParticipant  &lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Updated associations to reference Participants&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Removed &amp;lt;code&amp;gt;get_team_members&amp;lt;/code&amp;gt; from teams_participant model&lt;br /&gt;
|The method was empty without any logic so it was just a placeholder method without any usage across the project.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|Renamed methods: &amp;lt;code&amp;gt;remove_team_if_participants_empty&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;remove_team_participant&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;first_participant_for_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for clarity&lt;br /&gt;
|Improves code readability for new programmers.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity&lt;br /&gt;
|To reduce Cognitive Complexity and making the model more maintainable and efficient&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Changes to &amp;lt;code&amp;gt;app/models/team_user_node.rb&amp;lt;/code&amp;gt; ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamUserNode to TeamParticipantNode&lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users for node associations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/d5cacfa663e1358a522f52d676f7c6cb7a7ec3f0 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Modified queries in TeamParticipantNode to use teams_participant instead of teams_user&lt;br /&gt;
|Aligns with the changes made in teams_participant model to add new participant association.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/d5cacfa663e1358a522f52d676f7c6cb7a7ec3f0 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Updated associations to reference TeamUserNode in entire repository&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
We added a new spec file for the teams_participant model which was missing and fixed team_participant_controller_spec. Also as an additional step, we fixed model and controller tests for direct associations: Team, User, and Participant.&lt;br /&gt;
&lt;br /&gt;
===Code coverage===&lt;br /&gt;
&lt;br /&gt;
'''Before refactoring: 0%'''&lt;br /&gt;
&lt;br /&gt;
'''After refactoring: 100%'''&lt;br /&gt;
&lt;br /&gt;
[[File:teams-participant-code-cov.png|800px|center|Code coverage for &amp;lt;code&amp;gt;teams_participant.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams_participant_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:User_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams_participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Users_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
During the refactoring from TeamsUser to TeamsParticipant, we initially retained the association between teams and users (with user_id as a foreign key) in TeamsParticipant. This approach was for backward compatibility, ensuring that other classes and tests would function without immediate disruption.&lt;br /&gt;
&lt;br /&gt;
The next phase will involve fully removing this direct association between teams and users. Instead, we will maintain only the teams-participant relationship in the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
This update will require modifying all references to TeamsParticipant across models and controllers, and adjusting logic to work with Participant instead of User. Certain cases do need user-specific fields previously stored within TeamsParticipant. With the user association deprecated, these areas will need updated logic to retrieve the user associated with each participant. This ensures continued functionality and accuracy of the code. Corresponding updates will also be necessary in the spec files to align with the changes.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jay, Patel&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
# [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0OSS Projects on Expertiza])&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Github]&lt;br /&gt;
# [https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page Expertiza Wiki]&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=158769</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb (Phase 2 - Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=158769"/>
		<updated>2024-11-10T22:42:55Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: /* Solutions/Details of Changes Made */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design Pattern==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use Cases==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Solutions/Details of Changes Made==&lt;br /&gt;
&lt;br /&gt;
==Phase1 Improvements==&lt;br /&gt;
&lt;br /&gt;
- Renamed TeamsUser to TeamsParticipant to modify application logic to join Teams with Participants instead of Users&lt;br /&gt;
- Updated associations in immediate neighbor classes i.e Teams, Users and Participants to ensure correctness and consistency in the data model&lt;br /&gt;
- Renamed method names for increased readability and removed redundant methods from the TeamsParticipant class&lt;br /&gt;
- Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity, improving overall maintainability of the codebase&lt;br /&gt;
- Renamed TeamUserNode to TeamParticipantNode for correctness, to align with the new design of Participation association in TeamsParticipant&lt;br /&gt;
- Added migrations to add foreign key for Participant in TeamsParticipant table and updated indexes for the same&lt;br /&gt;
&lt;br /&gt;
==Phase2 Plan==&lt;br /&gt;
&lt;br /&gt;
- Update associations in all the models that were previously using TeamsUser to implement them with TeamsParticipant&lt;br /&gt;
- Modify implementations of all models, views, and controllers to use Participant with TeamsParticipant class instead of User&lt;br /&gt;
- This future involves modifying queries to retrieve participant and user objects that are passed to the TeamsParticipant class as commands to their methods&lt;br /&gt;
- Deprecate user_id foreign key from TeamsParticipant to completely remove the association of User from TeamsParticant, only linking Participants to Teams&lt;br /&gt;
- Update all the test cases to work with this implementation and mock DB calls&lt;br /&gt;
&lt;br /&gt;
===Files Modified===&lt;br /&gt;
&lt;br /&gt;
Changed files in &amp;lt;code&amp;gt;Model&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
==== Changes to &amp;lt;code&amp;gt;app/models/teams_user.rb&amp;lt;/code&amp;gt; ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamsUser to TeamsParticipant  &lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Updated associations to reference Participants&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Removed &amp;lt;code&amp;gt;get_team_members&amp;lt;/code&amp;gt; from teams_participant model&lt;br /&gt;
|The method was empty without any logic so it was just a placeholder method without any usage across the project.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|Renamed methods: &amp;lt;code&amp;gt;remove_team_if_participants_empty&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;remove_team_participant&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;first_participant_for_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for clarity&lt;br /&gt;
|Improves code readability for new programmers.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity&lt;br /&gt;
|To reduce Cognitive Complexity and making the model more maintainable and efficient&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Changes to &amp;lt;code&amp;gt;app/models/team_user_node.rb&amp;lt;/code&amp;gt; ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamUserNode to TeamParticipantNode&lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users for node associations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/d5cacfa663e1358a522f52d676f7c6cb7a7ec3f0 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Modified queries in TeamParticipantNode to use teams_participant instead of teams_user&lt;br /&gt;
|Aligns with the changes made in teams_participant model to add new participant association.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/d5cacfa663e1358a522f52d676f7c6cb7a7ec3f0 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Updated associations to reference TeamUserNode in entire repository&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
We added a new spec file for the teams_participant model which was missing and fixed team_participant_controller_spec. Also as an additional step, we fixed model and controller tests for direct associations: Team, User, and Participant.&lt;br /&gt;
&lt;br /&gt;
===Code coverage===&lt;br /&gt;
&lt;br /&gt;
'''Before refactoring: 0%'''&lt;br /&gt;
&lt;br /&gt;
'''After refactoring: 100%'''&lt;br /&gt;
&lt;br /&gt;
[[File:teams-participant-code-cov.png|800px|center|Code coverage for &amp;lt;code&amp;gt;teams_participant.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams_participant_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:User_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams_participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Users_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
During the refactoring from TeamsUser to TeamsParticipant, we initially retained the association between teams and users (with user_id as a foreign key) in TeamsParticipant. This approach was for backward compatibility, ensuring that other classes and tests would function without immediate disruption.&lt;br /&gt;
&lt;br /&gt;
The next phase will involve fully removing this direct association between teams and users. Instead, we will maintain only the teams-participant relationship in the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
This update will require modifying all references to TeamsParticipant across models and controllers, and adjusting logic to work with Participant instead of User. Certain cases do need user-specific fields previously stored within TeamsParticipant. With the user association deprecated, these areas will need updated logic to retrieve the user associated with each participant. This ensures continued functionality and accuracy of the code. Corresponding updates will also be necessary in the spec files to align with the changes.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jay, Patel&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
# [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0OSS Projects on Expertiza])&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Github]&lt;br /&gt;
# [https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page Expertiza Wiki]&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=158766</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb (Phase 2 - Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=158766"/>
		<updated>2024-11-10T22:21:33Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design Pattern==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use Cases==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Solutions/Details of Changes Made==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Files Modified===&lt;br /&gt;
&lt;br /&gt;
Changed files in &amp;lt;code&amp;gt;Model&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
==== Changes to &amp;lt;code&amp;gt;app/models/teams_user.rb&amp;lt;/code&amp;gt; ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamsUser to TeamsParticipant  &lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Updated associations to reference Participants&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Removed &amp;lt;code&amp;gt;get_team_members&amp;lt;/code&amp;gt; from teams_participant model&lt;br /&gt;
|The method was empty without any logic so it was just a placeholder method without any usage across the project.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|Renamed methods: &amp;lt;code&amp;gt;remove_team_if_participants_empty&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;remove_team_participant&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;first_participant_for_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for clarity&lt;br /&gt;
|Improves code readability for new programmers.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity&lt;br /&gt;
|To reduce Cognitive Complexity and making the model more maintainable and efficient&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Changes to &amp;lt;code&amp;gt;app/models/team_user_node.rb&amp;lt;/code&amp;gt; ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamUserNode to TeamParticipantNode&lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users for node associations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/d5cacfa663e1358a522f52d676f7c6cb7a7ec3f0 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Modified queries in TeamParticipantNode to use teams_participant instead of teams_user&lt;br /&gt;
|Aligns with the changes made in teams_participant model to add new participant association.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/d5cacfa663e1358a522f52d676f7c6cb7a7ec3f0 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Updated associations to reference TeamUserNode in entire repository&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
We added a new spec file for the teams_participant model which was missing and fixed team_participant_controller_spec. Also as an additional step, we fixed model and controller tests for direct associations: Team, User, and Participant.&lt;br /&gt;
&lt;br /&gt;
===Code coverage===&lt;br /&gt;
&lt;br /&gt;
'''Before refactoring: 0%'''&lt;br /&gt;
&lt;br /&gt;
'''After refactoring: 100%'''&lt;br /&gt;
&lt;br /&gt;
[[File:teams-participant-code-cov.png|800px|center|Code coverage for &amp;lt;code&amp;gt;teams_participant.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams_participant_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:User_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams_participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Users_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
During the refactoring from TeamsUser to TeamsParticipant, we initially retained the association between teams and users (with user_id as a foreign key) in TeamsParticipant. This approach was for backward compatibility, ensuring that other classes and tests would function without immediate disruption.&lt;br /&gt;
&lt;br /&gt;
The next phase will involve fully removing this direct association between teams and users. Instead, we will maintain only the teams-participant relationship in the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
This update will require modifying all references to TeamsParticipant across models and controllers, and adjusting logic to work with Participant instead of User. Certain cases do need user-specific fields previously stored within TeamsParticipant. With the user association deprecated, these areas will need updated logic to retrieve the user associated with each participant. This ensures continued functionality and accuracy of the code. Corresponding updates will also be necessary in the spec files to align with the changes.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jay, Patel&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
# [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0OSS Projects on Expertiza])&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Github]&lt;br /&gt;
# [https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page Expertiza Wiki]&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=158765</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb (Phase 2 - Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb_(Phase_2_-_Design_Document)&amp;diff=158765"/>
		<updated>2024-11-10T22:21:13Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: Template&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design Pattern==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use Cases==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Solutions/Details of Changes Made==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Files Modified===&lt;br /&gt;
&lt;br /&gt;
Changed files in &amp;lt;code&amp;gt;Model&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
==== Changes to &amp;lt;code&amp;gt;app/models/teams_user.rb&amp;lt;/code&amp;gt; ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamsUser to TeamsParticipant  &lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Updated associations to reference Participants&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Removed &amp;lt;code&amp;gt;get_team_members&amp;lt;/code&amp;gt; from teams_participant model&lt;br /&gt;
|The method was empty without any logic so it was just a placeholder method without any usage across the project.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|Renamed methods: &amp;lt;code&amp;gt;remove_team_if_participants_empty&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;remove_team_participant&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;first_participant_for_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for clarity&lt;br /&gt;
|Improves code readability for new programmers.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity&lt;br /&gt;
|To reduce Cognitive Complexity and making the model more maintainable and efficient&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Changes to &amp;lt;code&amp;gt;app/models/team_user_node.rb&amp;lt;/code&amp;gt; ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamUserNode to TeamParticipantNode&lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users for node associations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/d5cacfa663e1358a522f52d676f7c6cb7a7ec3f0 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Modified queries in TeamParticipantNode to use teams_participant instead of teams_user&lt;br /&gt;
|Aligns with the changes made in teams_participant model to add new participant association.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/d5cacfa663e1358a522f52d676f7c6cb7a7ec3f0 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Updated associations to reference TeamUserNode in entire repository&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test Cases==&lt;br /&gt;
&lt;br /&gt;
We added a new spec file for the teams_participant model which was missing and fixed team_participant_controller_spec. Also as an additional step, we fixed model and controller tests for direct associations: Team, User, and Participant.&lt;br /&gt;
&lt;br /&gt;
===Code coverage===&lt;br /&gt;
&lt;br /&gt;
'''Before refactoring: 0%'''&lt;br /&gt;
&lt;br /&gt;
'''After refactoring: 100%'''&lt;br /&gt;
&lt;br /&gt;
[[File:teams-participant-code-cov.png|800px|center|Code coverage for &amp;lt;code&amp;gt;teams_participant.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams_participant_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:User_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams_participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Users_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
During the refactoring from TeamsUser to TeamsParticipant, we initially retained the association between teams and users (with user_id as a foreign key) in TeamsParticipant. This approach was for backward compatibility, ensuring that other classes and tests would function without immediate disruption.&lt;br /&gt;
&lt;br /&gt;
The next phase will involve fully removing this direct association between teams and users. Instead, we will maintain only the teams-participant relationship in the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
This update will require modifying all references to TeamsParticipant across models and controllers, and adjusting logic to work with Participant instead of User. Certain cases do need user-specific fields previously stored within TeamsParticipant. With the user association deprecated, these areas will need updated logic to retrieve the user associated with each participant. This ensures continued functionality and accuracy of the code. Corresponding updates will also be necessary in the spec files to align with the changes.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jay, Patel&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
# [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0OSS Projects on Expertiza])&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Github]&lt;br /&gt;
# [https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page Expertiza Wiki]&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb&amp;diff=158252</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb&amp;diff=158252"/>
		<updated>2024-10-30T02:30:30Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
&lt;br /&gt;
The main role of teams_user class is to handle functionalities that deal with a team associated with an assignment/course and the participants (users associated with a course/assignment) in the team. The functionalities include retrieving a user’s name, deleting a user from the team, deleting the team if no participants are left in the team, adding a member to the team, finding the team ID for a user with a specific assignment, etc. Overall, it encapsulates the logic required to manage participants’ in teams within the context of assignments/courses in Expertiza.&lt;br /&gt;
&lt;br /&gt;
==Refactor==&lt;br /&gt;
&lt;br /&gt;
The refactoring process involved careful analysis of existing methods, removal of redundancies, and restructuring code to maintain clarity and efficiency. Significant focus was placed on simplifying method names, enhancing documentation, and aligning with object-oriented principles.&lt;br /&gt;
&lt;br /&gt;
The refactor aims to address the inappropriate association of teams directly with users rather than participants, ensuring consistency with the application's architecture. The changes involve:&lt;br /&gt;
&lt;br /&gt;
* Renaming TeamsUser to TeamsParticipant.&lt;br /&gt;
* Updating associations and references in related models: Team, User, and Participant.&lt;br /&gt;
* Removing empty or unnecessary methods and renaming others for clarity.&lt;br /&gt;
* Reducing the code and conditional complexity of the model&lt;br /&gt;
* Identifying code smells and refactoring for efficiency.&lt;br /&gt;
* Writing tests for all of the methods.&lt;br /&gt;
* Ensuring adherence to SOLID and DRY principles.&lt;br /&gt;
&lt;br /&gt;
===Files Modified===&lt;br /&gt;
&lt;br /&gt;
Changed files in &amp;lt;code&amp;gt;Model&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
==== Changes to &amp;lt;code&amp;gt;app/models/teams_user.rb&amp;lt;/code&amp;gt; ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamsUser to TeamsParticipant  &lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Updated associations to reference Participants&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Removed &amp;lt;code&amp;gt;get_team_members&amp;lt;/code&amp;gt; from teams_participant model&lt;br /&gt;
|The method was empty without any logic so it was just a placeholder method without any usage across the project.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|Renamed methods: &amp;lt;code&amp;gt;remove_team_if_participants_empty&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;remove_team_participant&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;first_participant_for_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for clarity&lt;br /&gt;
|Improves code readability for new programmers.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity&lt;br /&gt;
|To reduce Cognitive Complexity and making the model more maintainable and efficient&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Changes to &amp;lt;code&amp;gt;app/models/team_user_node.rb&amp;lt;/code&amp;gt; ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamUserNode to TeamParticipantNode&lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users for node associations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/d5cacfa663e1358a522f52d676f7c6cb7a7ec3f0 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Modified queries in TeamParticipantNode to use teams_participant instead of teams_user&lt;br /&gt;
|Aligns with the changes made in teams_participant model to add new participant association.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/d5cacfa663e1358a522f52d676f7c6cb7a7ec3f0 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Updated associations to reference TeamUserNode in entire repository&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test Cases==&lt;br /&gt;
&lt;br /&gt;
We added a new spec file for the teams_participant model which was missing and fixed team_participant_controller_spec. Also as an additional step, we fixed model and controller tests for direct associations: Team, User, and Participant.&lt;br /&gt;
&lt;br /&gt;
===Code coverage===&lt;br /&gt;
&lt;br /&gt;
'''Before refactoring: 0%'''&lt;br /&gt;
&lt;br /&gt;
'''After refactoring: 100%'''&lt;br /&gt;
&lt;br /&gt;
[[File:teams-participant-code-cov.png|800px|center|Code coverage for &amp;lt;code&amp;gt;teams_participant.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams_participant_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:User_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams_participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Users_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
During the refactoring from TeamsUser to TeamsParticipant, we initially retained the association between teams and users (with user_id as a foreign key) in TeamsParticipant. This approach was for backward compatibility, ensuring that other classes and tests would function without immediate disruption.&lt;br /&gt;
&lt;br /&gt;
The next phase will involve fully removing this direct association between teams and users. Instead, we will maintain only the teams-participant relationship in the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
This update will require modifying all references to TeamsParticipant across models and controllers, and adjusting logic to work with Participant instead of User. Certain cases do need user-specific fields previously stored within TeamsParticipant. With the user association deprecated, these areas will need updated logic to retrieve the user associated with each participant. This ensures continued functionality and accuracy of the code. Corresponding updates will also be necessary in the spec files to align with the changes.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jayesh, Kiron&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
# [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0OSS Projects on Expertiza])&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Github]&lt;br /&gt;
# [https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page Expertiza Wiki]&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb&amp;diff=158242</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb&amp;diff=158242"/>
		<updated>2024-10-30T02:29:26Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: /* Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
&lt;br /&gt;
The main role of teams_user class is to handle functionalities that deal with a team associated with an assignment/course and the participants (users associated with a course/assignment) in the team. The functionalities include retrieving a user’s name, deleting a user from the team, deleting the team if no participants are left in the team, adding a member to the team, finding the team ID for a user with a specific assignment, etc. Overall, it encapsulates the logic required to manage participants’ in teams within the context of assignments/courses in Expertiza.&lt;br /&gt;
&lt;br /&gt;
==Refactor==&lt;br /&gt;
&lt;br /&gt;
The refactoring process involved careful analysis of existing methods, removal of redundancies, and restructuring code to maintain clarity and efficiency. Significant focus was placed on simplifying method names, enhancing documentation, and aligning with object-oriented principles.&lt;br /&gt;
&lt;br /&gt;
The refactor aims to address the inappropriate association of teams directly with users rather than participants, ensuring consistency with the application's architecture. The changes involve:&lt;br /&gt;
&lt;br /&gt;
* Renaming TeamsUser to TeamsParticipant.&lt;br /&gt;
* Updating associations and references in related models: Team, User, and Participant.&lt;br /&gt;
* Removing empty or unnecessary methods and renaming others for clarity.&lt;br /&gt;
* Reducing the code and conditional complexity of the model&lt;br /&gt;
* Identifying code smells and refactoring for efficiency.&lt;br /&gt;
* Writing tests for all of the methods.&lt;br /&gt;
* Ensuring adherence to SOLID and DRY principles.&lt;br /&gt;
&lt;br /&gt;
===Files Modified===&lt;br /&gt;
&lt;br /&gt;
Changed files in &amp;lt;code&amp;gt;Model&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
==== Changes to &amp;lt;code&amp;gt;app/models/teams_user.rb&amp;lt;/code&amp;gt; ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamsUser to TeamsParticipant  &lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Updated associations to reference Participants&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Removed &amp;lt;code&amp;gt;get_team_members&amp;lt;/code&amp;gt; from teams_participant model&lt;br /&gt;
|The method was empty without any logic so it was just a placeholder method without any usage across the project.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|Renamed methods: &amp;lt;code&amp;gt;remove_team_if_participants_empty&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;remove_team_participant&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;first_participant_for_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for clarity&lt;br /&gt;
|Improves code readability for new programmers.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity&lt;br /&gt;
|To reduce Cognitive Complexity and making the model more maintainable and efficient&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Changes to &amp;lt;code&amp;gt;app/models/team_user_node.rb&amp;lt;/code&amp;gt; ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamUserNode to TeamParticipantNode&lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users for node associations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/d5cacfa663e1358a522f52d676f7c6cb7a7ec3f0 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Modified queries in TeamParticipantNode to use teams_participant instead of teams_user&lt;br /&gt;
|Aligns with the changes made in teams_participant model to add new participant association.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/d5cacfa663e1358a522f52d676f7c6cb7a7ec3f0 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Updated associations to reference TeamUserNode in entire repository&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test Cases==&lt;br /&gt;
&lt;br /&gt;
We added a new spec file for the teams_participant model which was missing and fixed team_participant_controller_spec. Also as an additional step, we fixed model and controller tests for direct associations: Team, User, and Participant.&lt;br /&gt;
&lt;br /&gt;
====Code coverage====&lt;br /&gt;
&lt;br /&gt;
Before refactoring: 0%&lt;br /&gt;
&lt;br /&gt;
After refactoring: 100%&lt;br /&gt;
&lt;br /&gt;
[[File:teams-participant-code-cov.png|800px|center|Code coverage for &amp;lt;code&amp;gt;teams_participant.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams_participant_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:User_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams_participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Users_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
During the refactoring from TeamsUser to TeamsParticipant, we initially retained the association between teams and users (with user_id as a foreign key) in TeamsParticipant. This approach was for backward compatibility, ensuring that other classes and tests would function without immediate disruption.&lt;br /&gt;
&lt;br /&gt;
The next phase will involve fully removing this direct association between teams and users. Instead, we will maintain only the teams-participant relationship in the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
This update will require modifying all references to TeamsParticipant across models and controllers, and adjusting logic to work with Participant instead of User. Certain cases do need user-specific fields previously stored within TeamsParticipant. With the user association deprecated, these areas will need updated logic to retrieve the user associated with each participant. This ensures continued functionality and accuracy of the code. Corresponding updates will also be necessary in the spec files to align with the changes.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jayesh, Kiron&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
# [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0OSS Projects on Expertiza])&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Github]&lt;br /&gt;
# [https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page Expertiza Wiki]&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Teams-participant-code-cov.png&amp;diff=158234</id>
		<title>File:Teams-participant-code-cov.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Teams-participant-code-cov.png&amp;diff=158234"/>
		<updated>2024-10-30T02:27:47Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Teams_participant_spec.png&amp;diff=158227</id>
		<title>File:Teams participant spec.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Teams_participant_spec.png&amp;diff=158227"/>
		<updated>2024-10-30T02:26:25Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb&amp;diff=157908</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb&amp;diff=157908"/>
		<updated>2024-10-29T23:47:08Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
&lt;br /&gt;
The main role of teams_user class is to handle functionalities that deal with a team associated with an assignment/course and the participants (users associated with a course/assignment) in the team. The functionalities include retrieving a user’s name, deleting a user from the team, deleting the team if no participants are left in the team, adding a member to the team, finding the team ID for a user with a specific assignment, etc. Overall, it encapsulates the logic required to manage participants’ in teams within the context of assignments/courses in Expertiza.&lt;br /&gt;
&lt;br /&gt;
==Refactor==&lt;br /&gt;
&lt;br /&gt;
The refactoring process involved careful analysis of existing methods, removal of redundancies, and restructuring code to maintain clarity and efficiency. Significant focus was placed on simplifying method names, enhancing documentation, and aligning with object-oriented principles.&lt;br /&gt;
&lt;br /&gt;
The refactor aims to address the inappropriate association of teams directly with users rather than participants, ensuring consistency with the application's architecture. The changes involve:&lt;br /&gt;
&lt;br /&gt;
* Renaming TeamsUser to TeamsParticipant.&lt;br /&gt;
* Updating associations and references in related models: Team, User, and Participant.&lt;br /&gt;
* Removing empty or unnecessary methods and renaming others for clarity.&lt;br /&gt;
* Reducing the code and conditional complexity of the model&lt;br /&gt;
* Identifying code smells and refactoring for efficiency.&lt;br /&gt;
* Writing tests for all of the methods.&lt;br /&gt;
* Ensuring adherence to SOLID and DRY principles.&lt;br /&gt;
&lt;br /&gt;
===Files Modified===&lt;br /&gt;
&lt;br /&gt;
Changed files in &amp;lt;code&amp;gt;Model&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
==== Changes to &amp;lt;code&amp;gt;app/models/teams_user.rb&amp;lt;/code&amp;gt; ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamsUser to TeamsParticipant  &lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Updated associations to reference Participants&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Removed &amp;lt;code&amp;gt;get_team_members&amp;lt;/code&amp;gt; from teams_participant model&lt;br /&gt;
|The method was empty without any logic so it was just a placeholder method without any usage across the project.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|Renamed methods: &amp;lt;code&amp;gt;remove_team_if_participants_empty&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;remove_team_participant&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;first_participant_for_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for clarity&lt;br /&gt;
|Improves code readability for new programmers.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity&lt;br /&gt;
|To reduce Cognitive Complexity and making the model more maintainable and efficient&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Changes to &amp;lt;code&amp;gt;app/models/team_user_node.rb&amp;lt;/code&amp;gt; ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamUserNode to TeamParticipantNode&lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users for node associations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/d5cacfa663e1358a522f52d676f7c6cb7a7ec3f0 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Modified queries in TeamParticipantNode to use teams_participant instead of teams_user&lt;br /&gt;
|Aligns with the changes made in teams_participant model to add new participant association.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/d5cacfa663e1358a522f52d676f7c6cb7a7ec3f0 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Updated associations to reference TeamUserNode in entire repository&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test Cases==&lt;br /&gt;
&lt;br /&gt;
We added a new spec file for the teams_participant model which was missing and fixed team_participant_controller_spec. Also as an additional step, we fixed model and controller tests for direct associations: Team, User, and Participant.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:User_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams_participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Users_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
During the refactoring from TeamsUser to TeamsParticipant, we initially retained the association between teams and users (with user_id as a foreign key) in TeamsParticipant. This approach was for backward compatibility, ensuring that other classes and tests would function without immediate disruption.&lt;br /&gt;
&lt;br /&gt;
The next phase will involve fully removing this direct association between teams and users. Instead, we will maintain only the teams-participant relationship in the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
This update will require modifying all references to TeamsParticipant across models and controllers, and adjusting logic to work with Participant instead of User. Certain cases do need user-specific fields previously stored within TeamsParticipant. With the user association deprecated, these areas will need updated logic to retrieve the user associated with each participant. This ensures continued functionality and accuracy of the code. Corresponding updates will also be necessary in the spec files to align with the changes.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jayesh, Kiron&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
# [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0OSS Projects on Expertiza])&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Github]&lt;br /&gt;
# [https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page Expertiza Wiki]&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb&amp;diff=157897</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb&amp;diff=157897"/>
		<updated>2024-10-29T23:34:30Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: /* Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
&lt;br /&gt;
The main role of teams_user class is to handle functionalities that deal with a team associated with an assignment/course and the participants (users associated with a course/assignment) in the team. The functionalities include retrieving a user’s name, deleting a user from the team, deleting the team if no participants are left in the team, adding a member to the team, finding the team ID for a user with a specific assignment, etc. Overall, it encapsulates the logic required to manage participants’ in teams within the context of assignments/courses in Expertiza.&lt;br /&gt;
&lt;br /&gt;
==Refactor==&lt;br /&gt;
&lt;br /&gt;
The refactoring process involved careful analysis of existing methods, removal of redundancies, and restructuring code to maintain clarity and efficiency. Significant focus was placed on simplifying method names, enhancing documentation, and aligning with object-oriented principles.&lt;br /&gt;
&lt;br /&gt;
The refactor aims to address the inappropriate association of teams directly with users rather than participants, ensuring consistency with the application's architecture. The changes involve:&lt;br /&gt;
&lt;br /&gt;
* Renaming TeamsUser to TeamsParticipant.&lt;br /&gt;
* Updating associations and references in related models: Team, User, and Participant.&lt;br /&gt;
* Removing empty or unnecessary methods and renaming others for clarity.&lt;br /&gt;
* Reducing the code and conditional complexity of the model&lt;br /&gt;
* Identifying code smells and refactoring for efficiency.&lt;br /&gt;
* Writing tests for all of the methods.&lt;br /&gt;
* Ensuring adherence to SOLID and DRY principles.&lt;br /&gt;
&lt;br /&gt;
====Files Modified====&lt;br /&gt;
&lt;br /&gt;
Changed files in &amp;lt;code&amp;gt;Model&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
=== Changes to &amp;lt;code&amp;gt;app/models/teams_user.rb&amp;lt;/code&amp;gt; ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamsUser to TeamsParticipant  &lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Updated associations to reference Participants&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Removed &amp;lt;code&amp;gt;get_team_members&amp;lt;/code&amp;gt; from teams_participant model&lt;br /&gt;
|The method was empty without any logic so it was just a placeholder method without any usage across the project.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|Renamed methods: &amp;lt;code&amp;gt;remove_team_if_participants_empty&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;remove_team_participant&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;first_participant_for_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for clarity&lt;br /&gt;
|Improves code readability for new programmers.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity&lt;br /&gt;
|To reduce Cognitive Complexity and making the model more maintainable and efficient&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test Cases==&lt;br /&gt;
&lt;br /&gt;
We added a new spec file for the teams_participant model which was missing and fixed team_participant_controller_spec. Also as an additional step, we fixed model and controller tests for direct associations: Team, User, and Participant.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:User_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_model_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''teams_participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams_participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''team_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Team_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''user_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Users_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;'''participant_controller'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Participant_controller_spec.png|1000px|center|Test passing for &amp;lt;code&amp;gt;team_spec.rb&amp;lt;/code&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
During the refactoring from TeamsUser to TeamsParticipant, we initially retained the association between teams and users (with user_id as a foreign key) in TeamsParticipant. This approach was for backward compatibility, ensuring that other classes and tests would function without immediate disruption.&lt;br /&gt;
&lt;br /&gt;
The next phase will involve fully removing this direct association between teams and users. Instead, we will maintain only the teams-participant relationship in the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
This update will require modifying all references to TeamsParticipant across models and controllers, and adjusting logic to work with Participant instead of User. Certain cases do need user-specific fields previously stored within TeamsParticipant. With the user association deprecated, these areas will need updated logic to retrieve the user associated with each participant. This ensures continued functionality and accuracy of the code. Corresponding updates will also be necessary in the spec files to align with the changes.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jayesh, Kiron&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
# [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0OSS Projects on Expertiza])&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Github]&lt;br /&gt;
# [https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page Expertiza Wiki]&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Teams_participant_controller_spec.png&amp;diff=157896</id>
		<title>File:Teams participant controller spec.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Teams_participant_controller_spec.png&amp;diff=157896"/>
		<updated>2024-10-29T23:33:32Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Users_controller_spec.png&amp;diff=157892</id>
		<title>File:Users controller spec.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Users_controller_spec.png&amp;diff=157892"/>
		<updated>2024-10-29T23:32:24Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Team_controller_spec.png&amp;diff=157890</id>
		<title>File:Team controller spec.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Team_controller_spec.png&amp;diff=157890"/>
		<updated>2024-10-29T23:31:57Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Participant_controller_spec.png&amp;diff=157887</id>
		<title>File:Participant controller spec.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Participant_controller_spec.png&amp;diff=157887"/>
		<updated>2024-10-29T23:31:28Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Participant_model_spec.png&amp;diff=157882</id>
		<title>File:Participant model spec.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Participant_model_spec.png&amp;diff=157882"/>
		<updated>2024-10-29T23:30:50Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:User_model_spec.png&amp;diff=157876</id>
		<title>File:User model spec.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:User_model_spec.png&amp;diff=157876"/>
		<updated>2024-10-29T23:29:52Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Team_model_spec.png&amp;diff=157872</id>
		<title>File:Team model spec.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Team_model_spec.png&amp;diff=157872"/>
		<updated>2024-10-29T23:28:09Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb&amp;diff=157622</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb&amp;diff=157622"/>
		<updated>2024-10-29T20:48:25Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
&lt;br /&gt;
The main role of teams_user class is to handle functionalities that deal with a team associated with an assignment/course and the participants (users associated with a course/assignment) in the team. The functionalities include retrieving a user’s name, deleting a user from the team, deleting the team if no participants are left in the team, adding a member to the team, finding the team ID for a user with a specific assignment, etc. Overall, it encapsulates the logic required to manage participants’ in teams within the context of assignments/courses in Expertiza.&lt;br /&gt;
&lt;br /&gt;
==Refactor==&lt;br /&gt;
&lt;br /&gt;
The refactoring process involved careful analysis of existing methods, removal of redundancies, and restructuring code to maintain clarity and efficiency. Significant focus was placed on simplifying method names, enhancing documentation, and aligning with object-oriented principles.&lt;br /&gt;
&lt;br /&gt;
The refactor aims to address the inappropriate association of teams directly with users rather than participants, ensuring consistency with the application's architecture. The changes involve:&lt;br /&gt;
&lt;br /&gt;
* Renaming TeamsUser to TeamsParticipant.&lt;br /&gt;
* Updating associations and references in related models: Team, User, and Participant.&lt;br /&gt;
* Removing empty or unnecessary methods and renaming others for clarity.&lt;br /&gt;
* Reducing the code and conditional complexity of the model&lt;br /&gt;
* Identifying code smells and refactoring for efficiency.&lt;br /&gt;
* Writing tests for all of the methods.&lt;br /&gt;
* Ensuring adherence to SOLID and DRY principles.&lt;br /&gt;
&lt;br /&gt;
====Files Modified====&lt;br /&gt;
&lt;br /&gt;
Changed files in &amp;lt;code&amp;gt;Model&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
=== Changes to &amp;lt;code&amp;gt;app/models/teams_user.rb&amp;lt;/code&amp;gt; ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamsUser to TeamsParticipant  &lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Updated associations to reference Participants&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Removed &amp;lt;code&amp;gt;get_team_members&amp;lt;/code&amp;gt; from teams_participant model&lt;br /&gt;
|The method was empty without any logic so it was just a placeholder method without any usage across the project.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|Renamed methods: &amp;lt;code&amp;gt;remove_team_if_participants_empty&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;remove_team_participant&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;first_participant_for_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for clarity&lt;br /&gt;
|Improves code readability for new programmers.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity&lt;br /&gt;
|To reduce Cognitive Complexity and making the model more maintainable and efficient&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test Cases==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
During the refactoring from TeamsUser to TeamsParticipant, we initially retained the association between teams and users (with user_id as a foreign key) in TeamsParticipant. This approach was for backward compatibility, ensuring that other classes and tests would function without immediate disruption.&lt;br /&gt;
&lt;br /&gt;
The next phase will involve fully removing this direct association between teams and users. Instead, we will maintain only the teams-participant relationship in the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
This update will require modifying all references to TeamsParticipant across models and controllers, and adjusting logic to work with Participant instead of User. Certain cases do need user-specific fields previously stored within TeamsParticipant. With the user association deprecated, these areas will need updated logic to retrieve the user associated with each participant. This ensures continued functionality and accuracy of the code. Corresponding updates will also be necessary in the spec files to align with the changes.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jayesh, Kiron&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
# [https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0OSS Projects on Expertiza])&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Github]&lt;br /&gt;
# [https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page Expertiza Wiki]&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb&amp;diff=157619</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb&amp;diff=157619"/>
		<updated>2024-10-29T20:45:25Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: /* Next Steps */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[Expertiza](http://expertiza.ncsu.edu/) is a [Ruby on Rails](http://rubyonrails.org/) based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
&lt;br /&gt;
The main role of teams_user class is to handle functionalities that deal with a team associated with an assignment/course and the participants (users associated with a course/assignment) in the team. The functionalities include retrieving a user’s name, deleting a user from the team, deleting the team if no participants are left in the team, adding a member to the team, finding the team ID for a user with a specific assignment, etc. Overall, it encapsulates the logic required to manage participants’ in teams within the context of assignments/courses in Expertiza.&lt;br /&gt;
&lt;br /&gt;
==Refactor==&lt;br /&gt;
&lt;br /&gt;
The refactoring process involved careful analysis of existing methods, removal of redundancies, and restructuring code to maintain clarity and efficiency. Significant focus was placed on simplifying method names, enhancing documentation, and aligning with object-oriented principles.&lt;br /&gt;
&lt;br /&gt;
The refactor aims to address the inappropriate association of teams directly with users rather than participants, ensuring consistency with the application's architecture. The changes involve:&lt;br /&gt;
&lt;br /&gt;
* Renaming TeamsUser to TeamsParticipant.&lt;br /&gt;
* Updating associations and references in related models: Team, User, and Participant.&lt;br /&gt;
* Removing empty or unnecessary methods and renaming others for clarity.&lt;br /&gt;
* Reducing the code and conditional complexity of the model&lt;br /&gt;
* Identifying code smells and refactoring for efficiency.&lt;br /&gt;
* Writing tests for all of the methods.&lt;br /&gt;
* Ensuring adherence to SOLID and DRY principles.&lt;br /&gt;
&lt;br /&gt;
====Files Modified====&lt;br /&gt;
&lt;br /&gt;
Changed files in &amp;lt;code&amp;gt;Model&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
=== Changes to &amp;lt;code&amp;gt;app/models/teams_user.rb&amp;lt;/code&amp;gt; ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamsUser to TeamsParticipant  &lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Updated associations to reference Participants&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Removed &amp;lt;code&amp;gt;get_team_members&amp;lt;/code&amp;gt; from teams_participant model&lt;br /&gt;
|The method was empty without any logic so it was just a placeholder method without any usage across the project.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|Renamed methods: &amp;lt;code&amp;gt;remove_team_if_participants_empty&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;remove_team_participant&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;first_participant_for_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for clarity&lt;br /&gt;
|Improves code readability for new programmers.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity&lt;br /&gt;
|To reduce Cognitive Complexity and making the model more maintainable and efficient&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test Cases==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
During the refactoring from TeamsUser to TeamsParticipant, we initially retained the association between teams and users (with user_id as a foreign key) in TeamsParticipant. This approach was for backward compatibility, ensuring that other classes and tests would function without immediate disruption.&lt;br /&gt;
&lt;br /&gt;
The next phase will involve fully removing this direct association between teams and users. Instead, we will maintain only the teams-participant relationship in the TeamsParticipant table.&lt;br /&gt;
&lt;br /&gt;
This update will require modifying all references to TeamsParticipant across models and controllers, and adjusting logic to work with Participant instead of User. Certain cases do need user-specific fields previously stored within TeamsParticipant. With the user association deprecated, these areas will need updated logic to retrieve the user associated with each participant. This ensures continued functionality and accuracy of the code. Corresponding updates will also be necessary in the spec files to align with the changes.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jayesh, Kiron&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [&amp;quot;Expertiza&amp;quot;](https://expertiza.ncsu.edu/)&lt;br /&gt;
# [&amp;quot;OSS Projects on Expertiza&amp;quot;](https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0)&lt;br /&gt;
# [&amp;quot;Github&amp;quot;](https://github.com/expertiza/expertiza)&lt;br /&gt;
# [&amp;quot;Expertiza VCL Server&amp;quot;](http://)&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb&amp;diff=157606</id>
		<title>CSC/ECE 517 Fall 2024 - E2456. Refactor teams user.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2456._Refactor_teams_user.rb&amp;diff=157606"/>
		<updated>2024-10-29T20:35:51Z</updated>

		<summary type="html">&lt;p&gt;Ppmanbhe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc).&lt;br /&gt;
The National Science Foundation supports the Expertiza project.&lt;br /&gt;
It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
[Expertiza](http://expertiza.ncsu.edu/) is a [Ruby on Rails](http://rubyonrails.org/) based open source project.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The TeamsUser class in the Expertiza repository serves as a join model between the Team and Participant classes, establishing a many-to-many relationship. Its primary purpose is to manage team memberships within the context of assignments or courses, facilitating functionalities such as retrieving a user's name, deleting users or teams, and managing participant associations.&lt;br /&gt;
&lt;br /&gt;
The primary issue with the TeamsUser class is that it associates teams directly with users rather than with participants. In the context of the application, participants are users who are specifically associated with an assignment or a course. Since teams are formed within the scope of assignments or courses, handling team memberships through participants is more appropriate. Almost everywhere else, an assignment uses Participant objects rather than User objects. The exception is when it comes to Teams. It would simplify the design to use TeamsParticipants instead of TeamsUsers. &lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
&lt;br /&gt;
The main role of teams_user class is to handle functionalities that deal with a team associated with an assignment/course and the participants (users associated with a course/assignment) in the team. The functionalities include retrieving a user’s name, deleting a user from the team, deleting the team if no participants are left in the team, adding a member to the team, finding the team ID for a user with a specific assignment, etc. Overall, it encapsulates the logic required to manage participants’ in teams within the context of assignments/courses in Expertiza.&lt;br /&gt;
&lt;br /&gt;
==Refactor==&lt;br /&gt;
&lt;br /&gt;
The refactoring process involved careful analysis of existing methods, removal of redundancies, and restructuring code to maintain clarity and efficiency. Significant focus was placed on simplifying method names, enhancing documentation, and aligning with object-oriented principles.&lt;br /&gt;
&lt;br /&gt;
The refactor aims to address the inappropriate association of teams directly with users rather than participants, ensuring consistency with the application's architecture. The changes involve:&lt;br /&gt;
&lt;br /&gt;
* Renaming TeamsUser to TeamsParticipant.&lt;br /&gt;
* Updating associations and references in related models: Team, User, and Participant.&lt;br /&gt;
* Removing empty or unnecessary methods and renaming others for clarity.&lt;br /&gt;
* Reducing the code and conditional complexity of the model&lt;br /&gt;
* Identifying code smells and refactoring for efficiency.&lt;br /&gt;
* Writing tests for all of the methods.&lt;br /&gt;
* Ensuring adherence to SOLID and DRY principles.&lt;br /&gt;
&lt;br /&gt;
====Files Modified====&lt;br /&gt;
&lt;br /&gt;
Changed files in &amp;lt;code&amp;gt;Model&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
=== Changes to &amp;lt;code&amp;gt;app/models/teams_user.rb&amp;lt;/code&amp;gt; ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%;&lt;br /&gt;
! &amp;amp;nbsp;#&amp;amp;nbsp; !! Change !! Rationale !! Commit Link&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Renamed TeamsUser to TeamsParticipant  &lt;br /&gt;
|Aligns with application logic that utilizes Participants rather than Users.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|style=&amp;quot;width: 30%&amp;quot;| Updated associations to reference Participants&lt;br /&gt;
|Ensures consistency across the application and correctness in related models for foreign key relations.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/3de17ae82cb55d35de419d4f4b8c881e1b9f86c5 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Removed &amp;lt;code&amp;gt;get_team_members&amp;lt;/code&amp;gt; from teams_participant model&lt;br /&gt;
|The method was empty without any logic so it was just a placeholder method without any usage across the project.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|Renamed methods: &amp;lt;code&amp;gt;remove_team_if_participants_empty&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;remove_team_participant&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;first_participant_for_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for clarity&lt;br /&gt;
|Improves code readability for new programmers.&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|Refactored methods: &amp;lt;code&amp;gt;add_accepted_invitee_to_team&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;find_team_id&amp;lt;/code&amp;gt; for efficiency and reducing complexity&lt;br /&gt;
|To reduce Cognitive Complexity and making the model more maintainable and efficient&lt;br /&gt;
|[https://github.com/pranavmanbhekar-ncsu/expertiza/commit/5041383721fd3c150f3065b3b3d9646784794257 Commit]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test Cases==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
We are yet to discuss the scope of this project and whether it can be extended to other functionalities in Expertiza.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
====Mentor====&lt;br /&gt;
&lt;br /&gt;
* Jayesh, Kiron&lt;br /&gt;
&lt;br /&gt;
====Members====&lt;br /&gt;
&lt;br /&gt;
* Agarwal, Arjit&lt;br /&gt;
* Manbhekar, Pranav&lt;br /&gt;
* Singhania, Chinmay&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# [&amp;quot;Expertiza&amp;quot;](https://expertiza.ncsu.edu/)&lt;br /&gt;
# [&amp;quot;OSS Projects on Expertiza&amp;quot;](https://docs.google.com/document/d/1fB9nHsop_yptjcj3CFn80BcZjXcSDbzcWwKvBDUTVrQ/edit?tab=t.0)&lt;br /&gt;
# [&amp;quot;Github&amp;quot;](https://github.com/expertiza/expertiza)&lt;br /&gt;
# [&amp;quot;Expertiza VCL Server&amp;quot;](http://)&lt;/div&gt;</summary>
		<author><name>Ppmanbhe</name></author>
	</entry>
</feed>