Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2404: Refactor student_teams functionality #2770

Open
wants to merge 94 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
64bdf4a
Renaming teams_users table to teams_participants
Mar 24, 2024
bf31d23
Merge pull request #1 from abhigna98/ChangingSchema
ameghana Mar 24, 2024
a6a05b2
Creating participant_id column
Mar 24, 2024
b01b3f3
Merge pull request #2 from abhigna98/ChangingSchema
ameghana Mar 24, 2024
e72aa67
Updating participant_id
Mar 24, 2024
d92f445
Merge pull request #3 from abhigna98/ChangingSchema
ameghana Mar 24, 2024
aa6a606
Refactor for participant id
Mar 24, 2024
73dc777
BugFix
ameghana Mar 24, 2024
e5aa71e
Merge branch ChangingSchema into main
Mar 24, 2024
a03c577
Added changes to spec files
Mar 24, 2024
146ad3f
Refactoring the teams rendering in /views/student_teams/view.html.erb
Mar 24, 2024
f4b9322
Merge pull request #4 from abhigna98/RefactorTeamsRendering
ameghana Mar 24, 2024
6c310aa
Bug fixes in spec files
Mar 24, 2024
e43904b
Updated CRUD Functionalities and remaned teams_users_controller
Mar 24, 2024
ec4f8a0
Updated signed_up_team to fetch data from ActiveRecord methods
Mar 24, 2024
3d46d29
Merge pull request #5 from abhigna98/CRUDFunctionalities
ameghana Mar 24, 2024
7573f97
Merge pull request #6 from abhigna98/ChangingTests
ameghana Mar 24, 2024
9ff4e31
Merge pull request #7 from abhigna98/SignedUpteam
ameghana Mar 24, 2024
458c004
Delete db/migrate/20230415194444_add_participant_id_and_populate.rb
ameghana Mar 25, 2024
f5c1eb3
Refactored create method in Teams Participants
Apr 20, 2024
28bae3c
'Fixed methods violating DRY principle
Apr 20, 2024
a674c73
Merge pull request #8 from abhigna98/FixingDRYViolation
ameghana Apr 20, 2024
ce26eae
Fixed build related to Lint
ameghana Apr 20, 2024
1200991
Merge pull request #9 from abhigna98/buildFixes
ameghana Apr 20, 2024
94da337
Fixed build related to CodeQL
ameghana Apr 20, 2024
2bef650
Merge pull request #10 from abhigna98/buildFixes
ameghana Apr 20, 2024
56d576c
Fixed build related to TestControllers
ameghana Apr 20, 2024
d14ead0
Merge pull request #11 from abhigna98/buildFixes
ameghana Apr 20, 2024
2c95eaa
Edited tests
Apr 22, 2024
514a91d
fixed a few spellings
Apr 22, 2024
c4400ff
added changes to spec files
Apr 23, 2024
768f711
Removed old commented create method
abhigna98 Apr 23, 2024
c71b52d
Refactoring review_mapping_controller.rb
ameghana Apr 24, 2024
8f37dbb
Refactoring student_teams_controller.rb
ameghana Apr 24, 2024
d6b5a85
Refactoring suggestion_controller.rb
ameghana Apr 24, 2024
2ee6560
Refactoring assignment_helper.rb
ameghana Apr 24, 2024
6d5ec36
Refactoring manage_team_helper.rb
ameghana Apr 24, 2024
aabf90f
Refactoring review_mapping_helper.rb
ameghana Apr 24, 2024
db730bb
Refactoring mail_worker.rb
ameghana Apr 24, 2024
318f1f6
Refactoring assignment.rb
ameghana Apr 24, 2024
2e7687d
Refactoring assignment_participant.rb
ameghana Apr 24, 2024
9a2aec5
Refactoring assignment_team.rb
ameghana Apr 24, 2024
0039e98
Refactoring cake.rb
ameghana Apr 24, 2024
47bef09
Refactoring course_team.rb
ameghana Apr 24, 2024
323299a
Refactoring invitation.rb
ameghana Apr 24, 2024
9de3d01
Refactoring mentor_management.rb
ameghana Apr 24, 2024
0d820c6
Refactoring participant.rb
ameghana Apr 24, 2024
7a27303
Refactoring sign_up_sheet.rb
ameghana Apr 24, 2024
a4120c3
Refactoring review_response_map.rb
ameghana Apr 24, 2024
bb2f39e
Refactoring tag_prompt_deployment.rb
ameghana Apr 24, 2024
54533bb
Refactoring team_user_node.rb
ameghana Apr 24, 2024
f9a4351
Refactoring _calibration.html.erb
ameghana Apr 24, 2024
df4a697
Refactoring list.html.erb
ameghana Apr 24, 2024
74fab28
Refactoring participants_popup.html.erb
ameghana Apr 24, 2024
6a1031d
Refactoring _teammate_review_report.html.erb
ameghana Apr 24, 2024
0e6c684
Refactoring response.html.erb
ameghana Apr 24, 2024
af8b989
Refactoring _list_review_mappings.html.erb
ameghana Apr 24, 2024
1251c92
Refactoring show_team.html.erb
ameghana Apr 24, 2024
94c6f68
Update _hyperlink.html.erb
ameghana Apr 24, 2024
dc8a790
Refactoring _self_review.html.erb
ameghana Apr 24, 2024
d87381c
Refactoring list.html.erb
ameghana Apr 24, 2024
36c2785
Refactoring _teams_actions.html.erb
ameghana Apr 24, 2024
2223623
Update _teams_users_actions.html.erb
ameghana Apr 24, 2024
daa5f9f
Refactoring 002_initialize_custom.rb
ameghana Apr 24, 2024
f963b09
Refactoring 019_create_teams_users.rb
ameghana Apr 24, 2024
5b5e345
Refactoring 066_create_team_user_nodes.rb
ameghana Apr 24, 2024
590718c
Refactoring 102_standardize_review_mappings.rb
ameghana Apr 24, 2024
6123987
Refactoring 20131103014327_create_participant_score_views.rb
ameghana Apr 24, 2024
abe599a
Refactoring 20141111010259_add_index_to_response_maps.rb
ameghana Apr 24, 2024
4706d15
Refactoring 20141204022200_add_team_index_to_teams_users.rb
ameghana Apr 24, 2024
e6e7c5c
Refactoring 20150527105416_convert_all_individual_assignments_to_one_…
ameghana Apr 24, 2024
da20305
Refactoring 20211110161054_add_duty_id_to_teams_users.rb
ameghana Apr 24, 2024
1e23302
Refactoring 20220405141744_add_pair_programming_status_to_teams_users.rb
ameghana Apr 24, 2024
15e02cb
Refactoring 020_teams_users.rb
ameghana Apr 24, 2024
516e7dd
Refactoring airbrake_exception_errors_controller_tests_spec.rb
ameghana Apr 24, 2024
1f33a88
Refactoring assessment360_controller_spec.rb
ameghana Apr 24, 2024
5bffc3b
Refactoring grades_controller_spec.rb
ameghana Apr 24, 2024
363b575
Refactoring invitations_controller_spec.rb
ameghana Apr 24, 2024
8521a85
Refactoring lottery_controller_spec.rb
ameghana Apr 24, 2024
88eb27e
Refactoring pair_programming_controller_spec.rb
ameghana Apr 24, 2024
67e2280
Refactoring review_mapping_controller_spec.rb
ameghana Apr 24, 2024
eb1927c
Refactoring sign_up_sheet_controller_spec.rb
ameghana Apr 24, 2024
e2e7485
Refactoring suggestion_controller_spec.rb
ameghana Apr 24, 2024
69aac40
Refactoring users_controller_spec.rb
ameghana Apr 24, 2024
c64a515
Refactoring factories.rb
ameghana Apr 24, 2024
309f2ec
Refactoring assignment_team_member_spec.rb
ameghana Apr 24, 2024
fc041c9
Refactoring airbrake_expection_errors_unit_tests_spec.rb
ameghana Apr 24, 2024
2f39d8d
Refactoring assignment_participant_spec.rb
ameghana Apr 24, 2024
f9e8c19
Refactoring cake_spec.rb
ameghana Apr 24, 2024
19dfead
Refactoring invitation_spec.rb
ameghana Apr 24, 2024
281d72a
Refactoring review_response_map_spec.rb
ameghana Apr 24, 2024
10e334e
Refactoring sign_up_sheet_spec.rb
ameghana Apr 24, 2024
f4782a5
Refactoring tag_prompt_deployment_spec.rb
ameghana Apr 24, 2024
cb236ed
Merge pull request #12 from abhigna98/RefactorPhase2
ameghana Apr 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/assessment360_controller.rb
Expand Up @@ -106,7 +106,7 @@ def course_student_grade_summary
# break out of the loop if there are no participants in the assignment
next if assignment.participants.find_by(user_id: user_id).nil?
# break out of the loop if the participant has no team
next if TeamsUser.team_id(assignment_id, user_id).nil?
next if TeamsParticipant.team_id(assignment_id, user_id).nil?

assignment_participant = Participant.find_by(user_id: user_id, parent_id: assignment_id)
penalties = calculate_penalty(assignment_participant.id)
Expand Down Expand Up @@ -134,7 +134,7 @@ def assignment_grade_summary(cp, assignment_id, penalties)
topic_id = SignedUpTeam.topic_id(assignment_id, user_id)
@topics[cp.id][assignment_id] = SignUpTopic.find_by(id: topic_id)
# instructor grade is stored in the team model, which is found by finding the user's team for the assignment
team_id = TeamsUser.team_id(assignment_id, user_id)
team_id = TeamsParticipant.team_id(assignment_id, user_id)
team = Team.find(team_id)
@assignment_grades[cp.id][assignment_id] = team[:grade_for_submission] ? (team[:grade_for_submission] - penalties[:submission]).round(2) : nil
return if @assignment_grades[cp.id][assignment_id].nil?
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/grades_controller.rb
Expand Up @@ -57,7 +57,7 @@ def view

def view_my_scores
@participant = AssignmentParticipant.find(params[:id])
@team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)
@team_id = TeamsParticipant.team_id(@participant.parent_id, @participant.user_id)
return if redirect_when_disallowed

@assignment = @participant.assignment
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/invitations_controller.rb
Expand Up @@ -129,7 +129,7 @@ def check_team_before_invitation
end

# participant information about student you are trying to invite to the team
team_member = TeamsUser.where('team_id = ? and user_id = ?', @team.id, @user.id)
team_member = TeamsParticipant.where('team_id = ? and user_id = ?', @team.id, @user.id)
# check if invited user is already in the team

return if team_member.empty?
Expand Down Expand Up @@ -160,6 +160,6 @@ def invitation_accept

@student = Participant.find(params[:student_id])
# Remove the users previous team since they are accepting an invite for possibly a new team.
TeamsUser.remove_team(@student.user_id, params[:team_id])
TeamsParticipant.remove_team(@student.user_id, params[:team_id])
end
end
2 changes: 1 addition & 1 deletion app/controllers/join_team_requests_controller.rb
Expand Up @@ -89,7 +89,7 @@

def check_team_status
# check if the advertisement is from a team member and if so disallow requesting invitations
team_member = TeamsUser.where(['team_id =? and user_id =?', params[:team_id], session[:user][:id]])
team_member = TeamsParticipant.where(['team_id =? and user_id =?', params[:team_id], session[:user][:id]])
Fixed Show fixed Hide fixed
team = Team.find(params[:team_id])
return flash[:error] = 'This team is full.' if team.full?
return flash[:error] = 'You are already a member of this team.' unless team_member.empty?
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/lottery_controller.rb
Expand Up @@ -131,8 +131,8 @@ def match_new_teams_to_topics(assignment)
# and we also need to think about, how to sort teams when they have the same team size and number of bids
# maybe we can use timestamps in this case
unassigned_teams.sort! do |t1, t2|
[TeamsUser.where(team_id: t2.id).size, Bid.where(team_id: t1.id).size] <=>
[TeamsUser.where(team_id: t1.id).size, Bid.where(team_id: t2.id).size]
[TeamsParticipant.where(team_id: t2.id).size, Bid.where(team_id: t1.id).size] <=>
[TeamsParticipant.where(team_id: t1.id).size, Bid.where(team_id: t2.id).size]
end

teams_bidding_info = construct_teams_bidding_info(unassigned_teams, sign_up_topics)
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/pair_programming_controller.rb
Expand Up @@ -6,24 +6,24 @@ def action_allowed?
end

def send_invitations
users = TeamsUser.where(team_id: params[:team_id])
users = TeamsParticipant.where(team_id: params[:team_id])
users.each { |user| user.update_attributes(pair_programming_status: "W") }
TeamsUser.find_by(team_id: params[:team_id], user_id: current_user.id).update_attributes(pair_programming_status: "A")
TeamsParticipant.find_by(team_id: params[:team_id], user_id: current_user.id).update_attributes(pair_programming_status: "A")
# ExpertizaLogger.info "Accepting Invitation #{params[:inv_id]}: #{accepted}"
Team.find(params[:team_id]).update_attributes(pair_programming_request: 1)
flash[:success] = "Invitations have been sent successfully!"
redirect_to view_student_teams_path student_id: params[:student_id]
end

def accept
user = TeamsUser.find_by(team_id: params[:team_id], user_id: current_user.id)
user = TeamsParticipant.find_by(team_id: params[:team_id], user_id: current_user.id)
user.update_attributes(pair_programming_status: "A")
flash[:success] = "Pair Programming Request Accepted Successfully!"
redirect_to view_student_teams_path student_id: params[:student_id]
end

def decline
user = TeamsUser.find_by(team_id: params[:team_id], user_id: current_user.id)
user = TeamsParticipant.find_by(team_id: params[:team_id], user_id: current_user.id)
user.update_attributes(pair_programming_status: "D")
Team.find(params[:team_id]).update_attributes(pair_programming_request: 0)
flash[:success] = "Pair Programming Request Declined!"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/popup_controller.rb
Expand Up @@ -37,7 +37,7 @@ def team_users_popup
@sum = 0
@team = Team.find(params[:id])
@assignment = Assignment.find(@team.parent_id)
@team_users = TeamsUser.where(team_id: params[:id])
@team_users = TeamsParticipant.where(team_id: params[:id])

# id2 is a response_map id
unless params[:id2].nil?
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/review_mapping_controller.rb
Expand Up @@ -57,7 +57,7 @@ def add_reviewer
user_id = User.where(name: params[:user][:name]).first.id
# If instructor want to assign one student to review his/her own artifact,
# it should be counted as "self-review" and we need to make /app/views/submitted_content/_selfreview.html.erb work.
if TeamsUser.exists?(team_id: params[:contributor_id], user_id: user_id)
if TeamsParticipant.exists?(team_id: params[:contributor_id], user_id: user_id)
flash[:error] = 'You cannot assign this student to review his/her own artifact.'
else
# Team lazy initialization
Expand Down Expand Up @@ -342,7 +342,7 @@ def automatic_review_mapping
if teams.empty? && max_team_size == 1
participants.each do |participant|
user = participant.user
next if TeamsUser.team_id(assignment_id, user.id)
next if TeamsParticipant.team_id(assignment_id, user.id)

if assignment.auto_assign_mentor
team = MentoredTeam.create_team_and_node(assignment_id)
Expand Down Expand Up @@ -485,7 +485,7 @@ def assign_reviewers_for_team(assignment_id, review_strategy, participants_hash)

participants_with_insufficient_review_num.each do |participant_id|
teams_hash.each_key do |team_id, _num_review_received|
next if TeamsUser.exists?(team_id: team_id,
next if TeamsParticipant.exists?(team_id: team_id,
user_id: Participant.find(participant_id).user_id)

participant = AssignmentParticipant.find(participant_id)
Expand Down Expand Up @@ -513,10 +513,10 @@ def peer_review_strategy(assignment_id, review_strategy, participants_hash)
if !team.equal? teams.last
# need to even out the # of reviews for teams
while selected_participants.size < review_strategy.reviews_per_team
num_participants_this_team = TeamsUser.where(team_id: team.id).size
num_participants_this_team = TeamsParticipant.where(team_id: team.id).size
# If there are some submitters or reviewers in this team, they are not treated as normal participants.
# They should be removed from 'num_participants_this_team'
TeamsUser.where(team_id: team.id).each do |team_user|
TeamsParticipant.where(team_id: team.id).each do |team_user|
temp_participant = Participant.where(user_id: team_user.user_id, parent_id: assignment_id).first
num_participants_this_team -= 1 unless temp_participant.can_review && temp_participant.can_submit
end
Expand All @@ -536,7 +536,7 @@ def peer_review_strategy(assignment_id, review_strategy, participants_hash)
# if participants_with_min_assigned_reviews is blank
if_condition_1 = participants_with_min_assigned_reviews.empty?
# or only one element in participants_with_min_assigned_reviews, prohibit one student to review his/her own artifact
if_condition_2 = ((participants_with_min_assigned_reviews.size == 1) && TeamsUser.exists?(team_id: team.id, user_id: participants[participants_with_min_assigned_reviews[0]].user_id))
if_condition_2 = ((participants_with_min_assigned_reviews.size == 1) && TeamsParticipant.exists?(team_id: team.id, user_id: participants[participants_with_min_assigned_reviews[0]].user_id))
rand_num = if if_condition_1 || if_condition_2
# use original method to get random number
rand(0..num_participants - 1)
Expand All @@ -546,7 +546,7 @@ def peer_review_strategy(assignment_id, review_strategy, participants_hash)
end
end
# prohibit one student to review his/her own artifact
next if TeamsUser.exists?(team_id: team.id, user_id: participants[rand_num].user_id)
next if TeamsParticipant.exists?(team_id: team.id, user_id: participants[rand_num].user_id)

if_condition_1 = (participants_hash[participants[rand_num].id] < review_strategy.reviews_per_student)
if_condition_2 = (!selected_participants.include? participants[rand_num].id)
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/sign_up_sheet_controller.rb
Expand Up @@ -289,7 +289,7 @@ def delete_signup_as_instructor
# find participant using assignment using team and topic ids
team = Team.find(params[:id])
assignment = Assignment.find(team.parent_id)
user = TeamsUser.find_by(team_id: team.id).user
user = TeamsParticipant.find_by(team_id: team.id).user
participant = AssignmentParticipant.find_by(user_id: user.id, parent_id: assignment.id)
drop_topic_deadline = assignment.due_dates.find_by(deadline_type_id: 6)
if !participant.team.submitted_files.empty? || !participant.team.hyperlinks.empty?
Expand Down Expand Up @@ -411,7 +411,7 @@ def show_team
end
@results.each do |result|
@team_members = ''
TeamsUser.where(team_id: result[:team_id]).each do |teamuser|
TeamsParticipant.where(team_id: result[:team_id]).each do |teamuser|
@team_members += User.find(teamuser.user_id).name + ' '
end
end
Expand All @@ -421,7 +421,7 @@ def show_team

def switch_original_topic_to_approved_suggested_topic
assignment = AssignmentParticipant.find(params[:id]).assignment
team_id = TeamsUser.team_id(assignment.id, session[:user].id)
team_id = TeamsParticipant.team_id(assignment.id, session[:user].id)

# Tmp variable to store topic id before change
original_topic_id = SignedUpTeam.topic_id(assignment.id.to_i, session[:user].id)
Expand All @@ -441,7 +441,7 @@ def switch_original_topic_to_approved_suggested_topic
# check the waitlist of original topic. Let the first waitlisted team hold the topic, if exists.
waitlisted_teams = SignedUpTeam.where(topic_id: original_topic_id, is_waitlisted: 1)
if waitlisted_teams.present?
waitlisted_first_team_first_user_id = TeamsUser.where(team_id: waitlisted_teams.first.team_id).first.user_id
waitlisted_first_team_first_user_id = TeamsParticipant.where(team_id: waitlisted_teams.first.team_id).first.user_id
SignUpSheet.signup_team(assignment.id, waitlisted_first_team_first_user_id, original_topic_id)
end
redirect_to action: 'list', id: params[:id]
Expand Down
98 changes: 98 additions & 0 deletions app/models/teams_participant.rb
@@ -0,0 +1,98 @@
class TeamsParticipant < ApplicationRecord
belongs_to :user
belongs_to :participant
belongs_to :team
has_one :team_user_node, foreign_key: 'node_object_id', dependent: :destroy
has_paper_trail

# Enhances readability by providing a clearer method name and leveraging Ruby's conditional expressions
def display_name(ip_address = nil)
display_name = user.name(ip_address)
display_name += ' (Mentor)' if MentorManagement.user_a_mentor?(user)
display_name
end

# Simplifies the delete method while preserving logic
def remove
TeamUserNode.find_by(node_object_id: id)&.destroy
destroy
team.destroy if team.teams_users.empty?
end

def get_team_members(team_id)
# Method body if needed
end

# Class methods for handling team and user associations and queries
class << self
# Streamlines the removal process
def remove_team(user_id, team_id)
find_by(team_id: team_id, user_id: user_id)&.destroy
end

def first_by_team_id(team_id)
where(team_id: team_id).first
end

def team_empty?(team_id)
where(team_id: team_id).blank?
end

def add_member_to_invited_team(invitee_user_id, invited_user_id, assignment_id)
can_add_member = false
where(user_id: invitee_user_id).each do |team|
new_team = AssignmentTeam.find_by(id: team.team_id, parent_id: assignment_id)
can_add_member = new_team.add_member(User.find(invited_user_id), assignment_id) unless new_team.nil?
end
can_add_member
end

def team_id(assignment_id, user_id)
find_team_id_for_user_and_assignment(assignment_id, user_id)
end

def find_by_team_and_user(team_id, user_id)
find_by_team_id_and_user_id_or_participant_id(team_id, user_id)
end

def where_users_and_assignment(user_ids, assignment_id)
participants = Participant.where(user_id: user_ids, parent_id: assignment_id)
where(user_id: user_ids).or(where(participant_id: participants.ids))
end

private

def find_team_id_for_user_and_assignment(assignment_id, user_id)
return nil if assignment_id.nil?

participant_id = Assignment.find(assignment_id).participants.find_by(user_id: user_id).id
where(user_id: user_id).or(where(participant_id: participant_id)).find_each do |team_user|
return team_user.team_id if team_user.team.parent_id == assignment_id
end

nil
end

def find_by_team_id_and_user_id_or_participant_id(team_id, user_id)
team_user = find_by(team_id: team_id, user_id: user_id)
return team_user if team_user.present?

participant_id = find_by_user_and_assignment(user_id, Team.find(team_id).parent_id)&.id
find_by(team_id: team_id, participant_id: participant_id) unless participant_id.nil?
end
end

def user
participant&.user || super
end

def user_id
user&.id || super
end

# Encapsulates the query logic within a helper method
def self.find_by_user_and_assignment(user_id, assignment_id)
Assignment.find(assignment_id)&.participants&.find_by(user_id: user_id)
end
end

1 change: 1 addition & 0 deletions app/models/teams_user.rb
@@ -1,4 +1,5 @@
class TeamsUser < ApplicationRecord
self.table_name = 'teams_participants'
belongs_to :user
belongs_to :team
has_one :team_user_node, foreign_key: 'node_object_id', dependent: :destroy
Expand Down
@@ -0,0 +1,5 @@
class RenameTeamsUsersToTeamsParticipants < ActiveRecord::Migration[5.1]
def change
rename_table :teams_users, :teams_participants
end
end
@@ -0,0 +1,7 @@
class AddParticipantIdToTeamsParticipants < ActiveRecord::Migration[5.1]
def change
unless column_exists?(:teams_participants, :participant_id)
add_column :teams_participants, :participant_id, :integer
end
end
end
@@ -0,0 +1,27 @@
class PopulateParticipantIdInTeamsParticipants < ActiveRecord::Migration[5.1]
def up
TeamsParticipant.find_each do |teams_participant|
next unless Team.exists?(id: teams_participant.team_id)

associated_team = Team.find(teams_participant.team_id)
# Assuming `parent_id` in `teams` table refers to an `assignment_id`
corresponding_assignment_id = associated_team.parent_id

# Locate a participant with matching `user_id` and `parent_id` (assignment)
matching_participant = Participant.find_by(user_id: teams_participant.user_id, parent_id: corresponding_assignment_id)

if matching_participant
# Populate the participant_id in teams_participants with the identified participant's ID
teams_participant.update_column(:participant_id, matching_participant.id)
else
# Actions or logs for cases where no corresponding participant is found
Rails.logger.info "No matching participant found for TeamsParticipant ID: #{teams_participant.id}"
end
end
end

def down
# Reset the participant_id column for all records if the migration is rolled back
TeamsParticipant.update_all(participant_id: nil)
end
end
16 changes: 8 additions & 8 deletions db/schema.rb
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20231203230237) do
ActiveRecord::Schema.define(version: 20240324044135) do

create_table "account_requests", id: :integer, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t|
t.string "name"
Expand Down Expand Up @@ -528,7 +528,7 @@
t.float "Hamer", limit: 24, default: 1.0
t.float "Lauw", limit: 24, default: 0.0
t.integer "duty_id"
t.boolean "can_mentor"
t.boolean "can_mentor", default: false
t.index ["duty_id"], name: "index_participants_on_duty_id"
t.index ["user_id"], name: "fk_participant_users"
end
Expand Down Expand Up @@ -937,13 +937,13 @@
t.integer "pair_programming_request", limit: 1
end

create_table "teams_users", id: :integer, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t|
create_table "teams_participants", id: :integer, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t|
t.integer "team_id"
t.integer "user_id"
t.integer "duty_id"
t.string "pair_programming_status", limit: 1
t.integer "participant_id"
t.index ["duty_id"], name: "index_teams_users_on_duty_id"
t.index ["duty_id"], name: "index_teams_participants_on_duty_id"
t.index ["participant_id"], name: "fk_rails_7192605c92"
t.index ["team_id"], name: "fk_users_teams"
t.index ["user_id"], name: "fk_teams_users"
Expand Down Expand Up @@ -1078,8 +1078,8 @@
add_foreign_key "tag_prompt_deployments", "assignments"
add_foreign_key "tag_prompt_deployments", "questionnaires"
add_foreign_key "tag_prompt_deployments", "tag_prompts"
add_foreign_key "teams_users", "duties"
add_foreign_key "teams_users", "participants"
add_foreign_key "teams_users", "teams", name: "fk_users_teams"
add_foreign_key "teams_users", "users", name: "fk_teams_users"
add_foreign_key "teams_participants", "duties"
add_foreign_key "teams_participants", "participants"
add_foreign_key "teams_participants", "teams", name: "fk_users_teams"
add_foreign_key "teams_participants", "users", name: "fk_teams_users"
end