Skip to content

Commit

Permalink
Fix team publish grading (#1195)
Browse files Browse the repository at this point in the history
* Create helper method

* Use effective student ID when publishing grading

* Fix publish status

* Add comment
  • Loading branch information
RichDom2185 authored Oct 4, 2024
1 parent 4ab3ea9 commit b840054
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
20 changes: 20 additions & 0 deletions lib/cadet/accounts/teams.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 11 additions & 2 deletions lib/cadet/assessments/assessments.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ defmodule Cadet.Assessments do
Notification,
Notifications,
User,
Teams,
Team,
TeamMember,
CourseRegistration,
Expand Down Expand Up @@ -305,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()

Expand Down Expand Up @@ -1211,6 +1212,14 @@ 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
else
submission.student_id
end

with {:submission_found?, true} <- {:submission_found?, is_map(submission)},
{:status, :submitted} <- {:status, submission.status},
{:is_manually_graded?, true} <-
Expand All @@ -1219,7 +1228,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
Expand Down

0 comments on commit b840054

Please sign in to comment.