From 096b72804de04140e5fefd7843ceb54ab51c169b Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Fri, 4 Oct 2024 17:48:44 +0800 Subject: [PATCH 1/4] Create helper method --- lib/cadet/accounts/teams.ex | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/cadet/accounts/teams.ex b/lib/cadet/accounts/teams.ex index 347a36e06..9cfecbfef 100644 --- a/lib/cadet/accounts/teams.ex +++ b/lib/cadet/accounts/teams.ex @@ -324,4 +324,24 @@ defmodule Cadet.Accounts.Teams do length(submission) > 0 end + + @doc """ + Get the first member of a team. + + ## Parameters + + * `team_id` - The team id of the team to get the first member from. + + ## Returns + + Returns the first member of the team. + + """ + + def get_first_member(team_id) do + TeamMember + |> where([tm], tm.team_id == ^team_id) + |> limit(1) + |> Repo.one() + end end From 28fc352ba14ca2e43f132174bfeffa3eaa1bc159 Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Fri, 4 Oct 2024 17:49:39 +0800 Subject: [PATCH 2/4] Use effective student ID when publishing grading --- lib/cadet/assessments/assessments.ex | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/cadet/assessments/assessments.ex b/lib/cadet/assessments/assessments.ex index 875a0095b..8224ceb88 100644 --- a/lib/cadet/assessments/assessments.ex +++ b/lib/cadet/assessments/assessments.ex @@ -12,6 +12,7 @@ defmodule Cadet.Assessments do Notification, Notifications, User, + Teams, Team, TeamMember, CourseRegistration, @@ -1211,6 +1212,13 @@ defmodule Cadet.Assessments do # allows staff to unpublish own assessment bypass = role in @bypass_closed_roles and submission.student_id == course_reg_id + effective_student_id = + if is_nil(submission.student_id) do + Teams.get_first_member(submission.team_id).student_id + else + submission.student_id + end + with {:submission_found?, true} <- {:submission_found?, is_map(submission)}, {:status, :submitted} <- {:status, submission.status}, {:is_manually_graded?, true} <- @@ -1219,7 +1227,7 @@ defmodule Cadet.Assessments do {:allowed_to_publish?, true} <- {:allowed_to_publish?, role == :admin or bypass or - Cadet.Accounts.Query.avenger_of?(cr, submission.student_id)} do + Cadet.Accounts.Query.avenger_of?(cr, effective_student_id)} do {:ok, submission} end end From d3a05af62ae582001fc5f74cad6a482f4d055adc Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Fri, 4 Oct 2024 18:10:00 +0800 Subject: [PATCH 3/4] Fix publish status --- lib/cadet/assessments/assessments.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cadet/assessments/assessments.ex b/lib/cadet/assessments/assessments.ex index 8224ceb88..f3034a8a2 100644 --- a/lib/cadet/assessments/assessments.ex +++ b/lib/cadet/assessments/assessments.ex @@ -306,7 +306,7 @@ defmodule Cadet.Assessments do is_grading_published = Submission |> where(assessment_id: ^id) - |> where(student_id: ^course_reg.id) + |> where([s], s.student_id == ^course_reg.id or s.team_id == ^team_id) |> select([s], s.is_grading_published) |> Repo.one() From 5406e959d14be88c0a024dd8edca6b607ce24882 Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Fri, 4 Oct 2024 18:18:18 +0800 Subject: [PATCH 4/4] Add comment --- lib/cadet/assessments/assessments.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/cadet/assessments/assessments.ex b/lib/cadet/assessments/assessments.ex index f3034a8a2..500d6c776 100644 --- a/lib/cadet/assessments/assessments.ex +++ b/lib/cadet/assessments/assessments.ex @@ -1212,6 +1212,7 @@ defmodule Cadet.Assessments do # allows staff to unpublish own assessment bypass = role in @bypass_closed_roles and submission.student_id == course_reg_id + # assumption: if team assessment, all team members are under the same avenger effective_student_id = if is_nil(submission.student_id) do Teams.get_first_member(submission.team_id).student_id