Skip to content

Commit 2afa68c

Browse files
authored
Merge branch 'source-academy:master' into No-GC-For-Staff
2 parents a217204 + c3ad8ba commit 2afa68c

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

lib/cadet/accounts/teams.ex

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,4 +324,24 @@ defmodule Cadet.Accounts.Teams do
324324

325325
length(submission) > 0
326326
end
327+
328+
@doc """
329+
Get the first member of a team.
330+
331+
## Parameters
332+
333+
* `team_id` - The team id of the team to get the first member from.
334+
335+
## Returns
336+
337+
Returns the first member of the team.
338+
339+
"""
340+
341+
def get_first_member(team_id) do
342+
TeamMember
343+
|> where([tm], tm.team_id == ^team_id)
344+
|> limit(1)
345+
|> Repo.one()
346+
end
327347
end

lib/cadet/assessments/assessments.ex

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ defmodule Cadet.Assessments do
1212
Notification,
1313
Notifications,
1414
User,
15+
Teams,
1516
Team,
1617
TeamMember,
1718
CourseRegistration,
@@ -305,7 +306,7 @@ defmodule Cadet.Assessments do
305306
is_grading_published =
306307
Submission
307308
|> where(assessment_id: ^id)
308-
|> where(student_id: ^course_reg.id)
309+
|> where([s], s.student_id == ^course_reg.id or s.team_id == ^team_id)
309310
|> select([s], s.is_grading_published)
310311
|> Repo.one()
311312

@@ -1211,6 +1212,14 @@ defmodule Cadet.Assessments do
12111212
# allows staff to unpublish own assessment
12121213
bypass = role in @bypass_closed_roles and submission.student_id == course_reg_id
12131214

1215+
# assumption: if team assessment, all team members are under the same avenger
1216+
effective_student_id =
1217+
if is_nil(submission.student_id) do
1218+
Teams.get_first_member(submission.team_id).student_id
1219+
else
1220+
submission.student_id
1221+
end
1222+
12141223
with {:submission_found?, true} <- {:submission_found?, is_map(submission)},
12151224
{:status, :submitted} <- {:status, submission.status},
12161225
{:is_manually_graded?, true} <-
@@ -1219,7 +1228,7 @@ defmodule Cadet.Assessments do
12191228
{:allowed_to_publish?, true} <-
12201229
{:allowed_to_publish?,
12211230
role == :admin or bypass or
1222-
Cadet.Accounts.Query.avenger_of?(cr, submission.student_id)} do
1231+
Cadet.Accounts.Query.avenger_of?(cr, effective_student_id)} do
12231232
{:ok, submission}
12241233
end
12251234
end
@@ -1241,9 +1250,17 @@ defmodule Cadet.Assessments do
12411250
|> Submission.changeset(%{is_grading_published: false})
12421251
|> Repo.update()
12431252

1253+
# assumption: if team assessment, all team members are under the same avenger
1254+
effective_student_id =
1255+
if is_nil(submission.student_id) do
1256+
Teams.get_first_member(submission.team_id).student_id
1257+
else
1258+
submission.student_id
1259+
end
1260+
12441261
Notifications.handle_unpublish_grades_notifications(
12451262
submission.assessment.id,
1246-
Repo.get(CourseRegistration, submission.student_id)
1263+
Repo.get(CourseRegistration, effective_student_id)
12471264
)
12481265

12491266
{:ok, nil}

mix.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
"csv": {:hex, :csv, "3.2.1", "6d401f1ed33acb2627682a9ab6021e96d33ca6c1c6bccc243d8f7e2197d032f5", [:mix], [], "hexpm", "8f55a0524923ae49e97ff2642122a2ce7c61e159e7fe1184670b2ce847aee6c8"},
2323
"db_connection": {:hex, :db_connection, "2.7.0", "b99faa9291bb09892c7da373bb82cba59aefa9b36300f6145c5f201c7adf48ec", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "dcf08f31b2701f857dfc787fbad78223d61a32204f217f15e881dd93e4bdd3ff"},
2424
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
25-
"dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"},
25+
"dialyxir": {:hex, :dialyxir, "1.4.4", "fb3ce8741edeaea59c9ae84d5cec75da00fa89fe401c72d6e047d11a61f65f70", [:mix], [{:erlex, ">= 0.2.7", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "cd6111e8017ccd563e65621a4d9a4a1c5cd333df30cebc7face8029cacb4eff6"},
2626
"distillery": {:hex, :distillery, "2.1.1", "f9332afc2eec8a1a2b86f22429e068ef35f84a93ea1718265e740d90dd367814", [:mix], [{:artificery, "~> 0.2", [hex: :artificery, repo: "hexpm", optional: false]}], "hexpm", "bbc7008b0161a6f130d8d903b5b3232351fccc9c31a991f8fcbf2a12ace22995"},
2727
"ecto": {:hex, :ecto, "3.11.2", "e1d26be989db350a633667c5cda9c3d115ae779b66da567c68c80cfb26a8c9ee", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3c38bca2c6f8d8023f2145326cc8a80100c3ffe4dcbd9842ff867f7fc6156c65"},
2828
"ecto_enum": {:hex, :ecto_enum, "1.4.0", "d14b00e04b974afc69c251632d1e49594d899067ee2b376277efd8233027aec8", [:mix], [{:ecto, ">= 3.0.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "> 3.0.0", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:mariaex, ">= 0.0.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm", "8fb55c087181c2b15eee406519dc22578fa60dd82c088be376d0010172764ee4"},
2929
"ecto_sql": {:hex, :ecto_sql, "3.11.3", "4eb7348ff8101fbc4e6bbc5a4404a24fecbe73a3372d16569526b0cf34ebc195", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.11.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.16 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e5f36e3d736b99c7fee3e631333b8394ade4bafe9d96d35669fca2d81c2be928"},
3030
"eiconv": {:hex, :eiconv, "1.0.0", "ee1e47ee37799a05beff7a68d61f63cccc93101833c4fb94b454c23b12a21629", [:rebar3], [], "hexpm", "8c80851decf72fc4571a70278d7932e9a87437770322077ecf797533fbb792cd"},
31-
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
31+
"erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"},
3232
"esaml": {:hex, :esaml, "4.6.0", "8fb5a3a0d56ccfce3e081a2f72b29058511047a2abbafb64cb6f595bf7465124", [:rebar3], [{:cowboy, "< 3.0.0", [hex: :cowboy, repo: "hexpm", optional: false]}], "hexpm", "d34d0b259cd8ac8215fd2c333fac9dbbb91b5f5da5a9304508612ff3ac0afa7a"},
3333
"ex2ms": {:hex, :ex2ms, "1.7.0", "45b9f523d0b777667ded60070d82d871a37e294f0b6c5b8eca86771f00f82ee1", [:mix], [], "hexpm", "2589eee51f81f1b1caa6d08c990b1ad409215fe6f64c73f73c67d36ed10be827"},
3434
"ex_aws": {:hex, :ex_aws, "2.5.5", "5dc378eff99c3c46c917b7a96a75ad0d4c300ab7250df668d0819bcd18c0213d", [:mix], [{:configparser_ex, "~> 4.0", [hex: :configparser_ex, repo: "hexpm", optional: true]}, {:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:jsx, "~> 2.8 or ~> 3.0", [hex: :jsx, repo: "hexpm", optional: true]}, {:mime, "~> 1.2 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:req, "~> 0.3", [hex: :req, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.7", [hex: :sweet_xml, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ed7ee39c56012c56600e021953c6487ecce9c49320ec3b4655a15d785f221ca6"},

0 commit comments

Comments
 (0)