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

fix: Fix empty submisisons creation for team assessments #1202

Merged
merged 6 commits into from
Oct 14, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/cadet/assessments/submission.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ defmodule Cadet.Assessments.Submission do
|> validate_xor_relationship
|> validate_required(@required_fields)
|> foreign_key_constraint(:student_id)
|> foreign_key_constraint(:team_id)
|> foreign_key_constraint(:assessment_id)
|> foreign_key_constraint(:unsubmitted_by_id)
end
Expand Down
52 changes: 35 additions & 17 deletions lib/cadet/jobs/autograder/grading_job.ex
Original file line number Diff line number Diff line change
Expand Up @@ -112,36 +112,54 @@ defmodule Cadet.Autograder.GradingJob do
|> where([_, tm], tm.student_id == ^student_id)
|> Repo.one()

if !team do
# Student is not in any team
# Create new team just for the student
team =
%Team{}
|> Team.changeset(%{
assessment_id: assessment.id
team =
if team do
team
else
# Student is not in any team
# Create new team just for the student
team =
%Team{}
|> Team.changeset(%{
assessment_id: assessment.id
})
|> Repo.insert!()

%TeamMember{}
|> TeamMember.changeset(%{
team_id: team.id,
student_id: student_id
})
|> Repo.insert!()

%TeamMember{}
|> TeamMember.changeset(%{
team_id: team.id,
student_id: student_id
})
|> Repo.insert!()
end
team
end

find_or_create_team_submission(team.id, assessment)
else
# Individual assessment
%Submission{}
|> Submission.changeset(%{
team_id: team.id,
student_id: student_id,
assessment: assessment,
status: :submitted
})
|> Repo.insert!()
end
end

defp find_or_create_team_submission(team_id, assessment) when is_ecto_id(team_id) do
submission =
Submission
|> where(team_id: ^team_id, assessment_id: ^assessment.id)
|> Repo.one()

if submission do
submission
else
# Individual assessment
%Submission{}
|> Submission.changeset(%{
student_id: student_id,
team_id: team_id,
assessment: assessment,
status: :submitted
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule Cadet.Repo.Migrations.CreateTeamsSubmissionConstraint do
use Ecto.Migration

def change do
create(index(:submissions, :team_id))
create(unique_index(:submissions, [:assessment_id, :team_id]))
end
end
Loading