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 team publish grading #1195

Merged
merged 4 commits into from
Oct 4, 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
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 @@
Notification,
Notifications,
User,
Teams,
Team,
TeamMember,
CourseRegistration,
Expand Down Expand Up @@ -305,7 +306,7 @@
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 @@ -940,7 +941,7 @@
raw_answer,
force_submit
) do
with {:ok, team} <- find_team(question.assessment.id, cr_id),

Check warning on line 944 in lib/cadet/assessments/assessments.ex

View workflow job for this annotation

GitHub Actions / Run CI

variable "team" is unused (if the variable is not meant to be used, prefix it with an underscore)
{:ok, submission} <- find_or_create_submission(cr, question.assessment),
{:status, true} <- {:status, force_submit or submission.status != :submitted},
{:ok, _answer} <- insert_or_update_answer(submission, question, raw_answer, cr_id) do
Expand Down Expand Up @@ -1211,6 +1212,14 @@
# 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 @@
{: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 Expand Up @@ -2679,7 +2688,7 @@

def has_last_modified_answer?(
question = %Question{},
cr = %CourseRegistration{id: cr_id},

Check warning on line 2691 in lib/cadet/assessments/assessments.ex

View workflow job for this annotation

GitHub Actions / Run CI

variable "cr_id" is unused (if the variable is not meant to be used, prefix it with an underscore)
last_modified_at,
force_submit
) do
Expand Down
Loading