Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 2 additions & 60 deletions app/models/assignment_team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class AssignmentTeam < Team
include ReviewAggregator
# Each AssignmentTeam must belong to a specific assignment
belongs_to :assignment, class_name: 'Assignment', foreign_key: 'parent_id'
has_many :review_mappings, class_name: 'ReviewResponseMap', foreign_key: 'reviewee_id'
has_many :review_response_maps, foreign_key: 'reviewee_id'
has_many :responses, through: :review_response_maps, foreign_key: 'map_id'

Expand Down Expand Up @@ -115,45 +114,7 @@ def has_submissions?
# Computes the average review grade for an assignment team.
# This method aggregates scores from all ReviewResponseMaps (i.e., all reviewers of the team).
def aggregate_review_grade
compute_average_review_score(review_mappings)
end

# Adds a participant to this team.
# - Update the participant's team_id (so their direct reference is consistent)
# - Ensure there is a TeamsParticipant join record connecting the participant and this team
def add_participant(participant)
# need to have a check if the team is full then it can not add participant to the team
raise TeamFullError, "Team is full." if full?

# Update the participant's team_id column - will remove the team reference inside participants table later. keeping it for now
# participant.update!(team_id: id)

# Create or reuse the join record to maintain the association
TeamsParticipant.find_or_create_by!(participant_id: participant.id, team_id: id, user_id: participant.user_id)
end

# Removes a participant from this team.
# - Delete the TeamsParticipant join record
# - if the participant sent any invitations while being on the team, they all need to be retracted
# - If the team has no remaining members, destroy the team itself
def remove_participant(participant)
# retract all the invitations the participant sent (if any) while being on the this team
participant.retract_sent_invitations

# Remove the join record if it exists
tp = TeamsParticipant.find_by(team_id: id, participant_id: participant.id)
tp&.destroy

# Update the participant's team_id column - will remove the team reference inside participants table later. keeping it for now
# participant.update!(team_id: nil)

# If no participants remain after removal, delete the team
destroy if participants.empty?
end

# Get the review response map
def review_map_type
'ReviewResponseMap'
compute_average_review_score(review_response_maps)
end

# Adds a participant to this team.
Expand Down Expand Up @@ -186,25 +147,6 @@ def remove_participant(participant)
# participant.update!(team_id: nil)
end

# Use current object (AssignmentTeam) as reviewee and create the ReviewResponseMap record
def assign_reviewer(reviewer)
assignment = Assignment.find(parent_id)
raise 'The assignment cannot be found.' if assignment.nil?

ReviewResponseMap.create(reviewee_id: id, reviewer_id: reviewer.get_reviewer.id, reviewed_object_id: assignment.id, team_reviewing_enabled: assignment.team_reviewing_enabled)
end

# Whether the team has submitted work or not
def has_submissions?
submitted_files.any? || submitted_hyperlinks.present?
end

# Computes the average review grade for an assignment team.
# This method aggregates scores from all ReviewResponseMaps (i.e., all reviewers of the team).
def aggregate_review_grade
compute_average_review_score(review_mappings)
end

protected

# Validates if a user is eligible to join the team
Expand All @@ -224,4 +166,4 @@ def validate_assignment_team_type
end
end

class TeamFullError < StandardError; end
class TeamFullError < StandardError; end
Loading