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

Changes for synchronizing waitlist features with invitation.rb and suggestion_controller.rb #14

Merged
merged 2 commits into from Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion app/controllers/suggestion_controller.rb
Expand Up @@ -120,7 +120,7 @@ def notification
else
if @topic_id.nil?
# clean waitlists
SignedUpTeam.where(team_id: @team_id, is_waitlisted: 1).destroy_all
WaitlistTeam.delete_all_waitlists_for_team(@team_id)
SignedUpTeam.create(topic_id: @signuptopic.id, team_id: @team_id, is_waitlisted: 0)
else
@signuptopic.private_to = @user_id
Expand Down
21 changes: 12 additions & 9 deletions app/models/invitation.rb
Expand Up @@ -4,17 +4,20 @@ class Invitation < ApplicationRecord
# belongs_to :from_user, class_name: "User", foreign_key: "from_id"
belongs_to :from_user, class_name: 'User', foreign_key: 'from_id', inverse_of: false

def self.remove_waitlists_for_team(topic_id, _assignment_id)
# first_waitlisted_signup = SignedUpTeam.where(topic_id: topic_id, is_waitlisted: true).first
first_waitlisted_signup = SignedUpTeam.find_by(topic_id: topic_id, is_waitlisted: true)
# This method is no longer used and the same functionality is provided by
# The method release_topics_selected_by_team_for_assignment in signed_up_team.rb

# def self.remove_waitlists_for_team(topic_id, _assignment_id)
# # first_waitlisted_signup = SignedUpTeam.where(topic_id: topic_id, is_waitlisted: true).first
# first_waitlisted_signup = SignedUpTeam.find_by(topic_id: topic_id, is_waitlisted: true)

# As this user is going to be allocated a confirmed topic, all of his waitlisted topic signups should be purged
first_waitlisted_signup.is_waitlisted = false
first_waitlisted_signup.save
# # As this user is going to be allocated a confirmed topic, all of his waitlisted topic signups should be purged
# first_waitlisted_signup.is_waitlisted = false
# first_waitlisted_signup.save

# Cancel all topics the user is waitlisted for
Waitlist.cancel_all_waitlists(first_waitlisted_signup.team_id, SignUpTopic.find(topic_id).assignment_id)
end
# # Cancel all topics the user is waitlisted for
# Waitlist.cancel_all_waitlists(first_waitlisted_signup.team_id, SignUpTopic.find(topic_id).assignment_id)
# end

# Remove all invites sent by a user for an assignment.
def self.remove_users_sent_invites_for_assignment(user_id, assignment_id)
Expand Down
16 changes: 1 addition & 15 deletions app/models/signed_up_team.rb
Expand Up @@ -54,20 +54,6 @@ def self.find_user_signup_topics(assignment_id, team_id)
end

# If a signup sheet exists then release topics that the given team has selected for the given assignment.
def self.release_topics_selected_by_team_for_assignment(team_id, assignment_id)
old_teams_signups = SignedUpTeam.where(team_id: team_id)

# If the team has signed up for the topic and they are on the waitlist then remove that team from the waitlist.
unless old_teams_signups.nil?
old_teams_signups.each do |old_teams_signup|
if old_teams_signup.is_waitlisted == false # i.e., if the old team was occupying a slot, & thus is releasing a slot ...
first_waitlisted_signup = SignedUpTeam.find_by(topic_id: old_teams_signup.topic_id, is_waitlisted: true)
Invitation.remove_waitlists_for_team(old_teams_signup.topic_id, assignment_id) unless first_waitlisted_signup.nil?
end
old_teams_signup.destroy
end
end
end

# def self.release_topics_selected_by_team_for_assignment(team_id, assignment_id)
# old_teams_signups = SignedUpTeam.where(team_id: team_id)
Expand All @@ -82,7 +68,7 @@ def self.release_topics_selected_by_team_for_assignment(team_id, assignment_id)
# old_teams_signup.destroy
# end
# end
# end
# end

def self.release_topics_selected_by_team_for_assignment(team_id, assignment_id)
delete_all_signed_up_topics_for_team(team_id)
Expand Down
16 changes: 16 additions & 0 deletions app/models/waitlist_team.rb
Expand Up @@ -56,6 +56,18 @@ def self.delete_all_waitlists_for_team(team_id, assignment_id)
return true
end

def self.delete_all_waitlists_for_team(team_id)
waitlisted_topics_for_team = get_all_waitlists_for_team team_id
unless waitlisted_topics_for_team.nil?
waitlisted_topics_for_team.each do |entry|
entry.destroy
end
else
ExpertizaLogger.info LoggerMessage.new('WaitlistTeam', user_id, "Cannot find Team #{team_id} in waitlist.")
end
return true
end

def self.delete_all_waitlists_for_topic(topic_id)
waitlisted_teams_for_topic = get_all_waitlists_for_topic topic_id
unless waitlisted_teams_for_topic.nil?
Expand All @@ -72,6 +84,10 @@ def self.get_all_waitlists_for_team(team_id, assignment_id)
WaitlistTeam.joins(:topic).where(team_id: team_id, sign_up_topics: {assignment_id: assignment_id})
end

def self.get_all_waitlists_for_team(team_id)
WaitlistTeam.where(team_id: team_id)
end

def self.get_all_waitlists_for_topic(topic_id)
WaitlistTeam.where(topic_id: topic_id)
end
Expand Down
17 changes: 9 additions & 8 deletions spec/models/invitation_spec.rb
Expand Up @@ -120,12 +120,13 @@
end
end

describe '#remove_waitlists_for_team' do
it 'removes a currently waitlisted team from the topic waitlist and removes the team from all other waitlists it was on' do
allow(SignedUpTeam).to receive(:find_by).with(topic_id: topic.id, is_waitlisted: true).and_return(signed_up_team)
allow(SignUpTopic).to receive(:find).with(topic.id).and_return(topic)
allow(Waitlist).to receive(:cancel_all_waitlists).with(team.id, topic.assignment_id).and_return([topic])
expect(Invitation.remove_waitlists_for_team(topic.id, assignment.id)).to eq([topic])
end
end
# remove_waitlists_for_team method is removed from invitation.rb
# describe '#remove_waitlists_for_team' do
# it 'removes a currently waitlisted team from the topic waitlist and removes the team from all other waitlists it was on' do
# allow(SignedUpTeam).to receive(:find_by).with(topic_id: topic.id, is_waitlisted: true).and_return(signed_up_team)
# allow(SignUpTopic).to receive(:find).with(topic.id).and_return(topic)
# allow(Waitlist).to receive(:cancel_all_waitlists).with(team.id, topic.assignment_id).and_return([topic])
# expect(Invitation.remove_waitlists_for_team(topic.id, assignment.id)).to eq([topic])
# end
# end
end