Skip to content
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
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