Skip to content

Commit b410b5f

Browse files
Improved Assessment Configurability in Ground Control (#1093)
* rename hasTokenCounter to hasVotingFeature under assessmentConfig * Added hasVotingFeatures to assessment config * Added hasVotingFeature to assessmentConfig * Added hasTokenCounter and hasVotingFeatures to assessments * hasTokenCounter and hasVotingFeatures to be updated to ones in assessment config when uploaded * Added hasTokenCounter and hasVotingFeatures to be shown when assessment is requested * Added hasTokenCounter into swaggers * Changed test cases to include hasVotingFeatures and hasTokenCounter * Added a way to change hasTokenCounter and hasVotingFeatures from the frontEnd * fixed format * fixed format * fixed alias format * added new test case to ensure hasTokenCounter and hasVotingFeatures can be changed * Seperated nil checks to be for indivudual field instead --------- Co-authored-by: Richard Dominick <34370238+RichDom2185@users.noreply.github.com>
1 parent 5edaa6a commit b410b5f

15 files changed

+167
-9
lines changed

lib/cadet/assessments/assessment.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ defmodule Cadet.Assessments.Assessment do
3333
field(:reading, :string)
3434
field(:password, :string, default: nil)
3535
field(:max_team_size, :integer, default: 1)
36+
field(:has_token_counter, :boolean, default: false)
37+
field(:has_voting_features, :boolean, default: false)
3638

3739
belongs_to(:config, AssessmentConfig)
3840
belongs_to(:course, Course)
@@ -43,7 +45,7 @@ defmodule Cadet.Assessments.Assessment do
4345

4446
@required_fields ~w(title open_at close_at number course_id config_id max_team_size)a
4547
@optional_fields ~w(reading summary_short summary_long
46-
is_published story cover_picture access password)a
48+
is_published story cover_picture access password has_token_counter has_voting_features)a
4749
@optional_file_fields ~w(mission_pdf)a
4850

4951
def changeset(assessment, params) do

lib/cadet/courses/assessment_config.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ defmodule Cadet.Courses.AssessmentConfig do
1313
field(:show_grading_summary, :boolean, default: true)
1414
field(:is_manually_graded, :boolean, default: true)
1515
field(:has_token_counter, :boolean, default: false)
16+
field(:has_voting_features, :boolean, default: false)
1617
# used by frontend to determine display styles
1718
field(:early_submission_xp, :integer, default: 0)
1819
field(:hours_before_early_xp_decay, :integer, default: 0)
@@ -24,7 +25,7 @@ defmodule Cadet.Courses.AssessmentConfig do
2425

2526
@required_fields ~w(course_id)a
2627
@optional_fields ~w(order type early_submission_xp
27-
hours_before_early_xp_decay show_grading_summary is_manually_graded has_token_counter)a
28+
hours_before_early_xp_decay show_grading_summary is_manually_graded has_voting_features has_token_counter)a
2829

2930
def changeset(assessment_config, params) do
3031
assessment_config

lib/cadet/jobs/xml_parser.ex

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ defmodule Cadet.Updater.XMLParser do
55

66
use Cadet, [:display]
77

8+
import Ecto.Query
89
import SweetXml
910

10-
alias Cadet.Assessments
11+
alias Cadet.{Repo, Courses.AssessmentConfig, Assessments}
1112

1213
require Logger
1314

@@ -80,6 +81,11 @@ defmodule Cadet.Updater.XMLParser do
8081

8182
close_at = Timex.shift(open_at, days: 7)
8283

84+
assessment_config =
85+
AssessmentConfig
86+
|> where(id: ^assessment_config_id)
87+
|> Repo.one()
88+
8389
assessment_params =
8490
xml
8591
|> xpath(
@@ -99,6 +105,8 @@ defmodule Cadet.Updater.XMLParser do
99105
|> Map.put(:close_at, close_at)
100106
|> Map.put(:course_id, course_id)
101107
|> Map.put(:config_id, assessment_config_id)
108+
|> Map.put(:has_token_counter, assessment_config.has_token_counter)
109+
|> Map.put(:has_voting_features, assessment_config.has_voting_features)
102110
|> (&if(&1.access === "public",
103111
do: Map.put(&1, :password, nil),
104112
else: &1

lib/cadet_web/admin_controllers/admin_assessments_controller.ex

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ defmodule CadetWeb.AdminAssessmentsController do
8383
close_at = params |> Map.get("closeAt")
8484
is_published = params |> Map.get("isPublished")
8585
max_team_size = params |> Map.get("maxTeamSize")
86+
has_token_counter = params |> Map.get("hasTokenCounter")
87+
has_voting_features = params |> Map.get("hasVotingFeatures")
8688

8789
updated_assessment =
8890
if is_nil(is_published) do
@@ -98,6 +100,20 @@ defmodule CadetWeb.AdminAssessmentsController do
98100
Map.put(updated_assessment, :max_team_size, max_team_size)
99101
end
100102

103+
updated_assessment =
104+
if is_nil(has_token_counter) do
105+
updated_assessment
106+
else
107+
Map.put(updated_assessment, :has_token_counter, has_token_counter)
108+
end
109+
110+
updated_assessment =
111+
if is_nil(has_voting_features) do
112+
updated_assessment
113+
else
114+
Map.put(updated_assessment, :has_voting_features, has_voting_features)
115+
end
116+
101117
with {:ok, assessment} <- check_dates(open_at, close_at, updated_assessment),
102118
{:ok, _nil} <- Assessments.update_assessment(assessment_id, assessment) do
103119
text(conn, "OK")

lib/cadet_web/admin_views/admin_assessments_view.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ defmodule CadetWeb.AdminAssessmentsView do
2828
isPublished: :is_published,
2929
questionCount: :question_count,
3030
gradedCount: &(&1.graded_count || 0),
31-
maxTeamSize: :max_team_size
31+
maxTeamSize: :max_team_size,
32+
hasVotingFeatures: :has_voting_features,
33+
hasTokenCounter: :has_token_counter
3234
})
3335
end
3436

@@ -44,6 +46,7 @@ defmodule CadetWeb.AdminAssessmentsView do
4446
number: :number,
4547
reading: :reading,
4648
longSummary: :summary_long,
49+
hasTokenCounter: :has_token_counter,
4750
missionPDF: &Cadet.Assessments.Upload.url({&1.mission_pdf, &1}),
4851
questions:
4952
&Enum.map(&1.questions, fn question ->

lib/cadet_web/admin_views/admin_courses_view.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ defmodule CadetWeb.AdminCoursesView do
1212
displayInDashboard: :show_grading_summary,
1313
isManuallyGraded: :is_manually_graded,
1414
earlySubmissionXp: :early_submission_xp,
15+
hasVotingFeatures: :has_voting_features,
1516
hasTokenCounter: :has_token_counter,
1617
hoursBeforeEarlyXpDecay: :hours_before_early_xp_decay
1718
})

lib/cadet_web/controllers/assessments_controller.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ defmodule CadetWeb.AssessmentsController do
174174
required: true
175175
)
176176

177+
hasTokenCounter(:boolean, "Does the assessment have Token Counter enabled?")
178+
177179
maxXp(
178180
:integer,
179181
"The maximum XP for this assessment",
@@ -216,6 +218,7 @@ defmodule CadetWeb.AssessmentsController do
216218
story(:string, "The story that should be shown for this assessment")
217219
reading(:string, "The reading for this assessment")
218220
longSummary(:string, "Long summary", required: true)
221+
hasTokenCounter(:boolean, "Does the assessment have Token Counter enabled?")
219222
missionPDF(:string, "The URL to the assessment pdf")
220223

221224
questions(Schema.ref(:Questions), "The list of questions for this assessment")

lib/cadet_web/views/assessments_view.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ defmodule CadetWeb.AssessmentsView do
2929
isPublished: :is_published,
3030
questionCount: :question_count,
3131
gradedCount: &(&1.graded_count || 0),
32-
maxTeamSize: :max_team_size
32+
maxTeamSize: :max_team_size,
33+
hasVotingFeatures: :has_voting_features,
34+
hasTokenCounter: :has_token_counter
3335
})
3436
end
3537

@@ -45,6 +47,7 @@ defmodule CadetWeb.AssessmentsView do
4547
number: :number,
4648
reading: :reading,
4749
longSummary: :summary_long,
50+
hasTokenCounter: :has_token_counter,
4851
missionPDF: &Cadet.Assessments.Upload.url({&1.mission_pdf, &1}),
4952
questions:
5053
&Enum.map(&1.questions, fn question ->

lib/cadet_web/views/user_view.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ defmodule CadetWeb.UserView do
125125
type: :type,
126126
displayInDashboard: :show_grading_summary,
127127
isManuallyGraded: :is_manually_graded,
128+
hasVotingFeatures: :has_voting_features,
128129
hasTokenCounter: :has_token_counter,
129130
earlySubmissionXp: :early_submission_xp,
130131
hoursBeforeEarlyXpDecay: :hours_before_early_xp_decay
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
defmodule Cadet.Repo.Migrations.AddHasTokenCounterToggleToAssessment do
2+
use Ecto.Migration
3+
4+
def up do
5+
alter table(:assessments) do
6+
add(:has_token_counter, :boolean, null: false, default: false)
7+
add(:has_voting_features, :boolean, null: false, default: false)
8+
end
9+
end
10+
11+
def down do
12+
alter table(:assessments) do
13+
remove(:has_token_counter)
14+
remove(:has_voting_features)
15+
end
16+
end
17+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
defmodule Cadet.Repo.Migrations.AddHasVotingFeaturesToggleToAssessmentConfig do
2+
use Ecto.Migration
3+
4+
def up do
5+
alter table(:assessment_configs) do
6+
add(:has_voting_features, :boolean, null: false, default: false)
7+
end
8+
end
9+
10+
def down do
11+
alter table(:assessment_configs) do
12+
remove(:has_voting_features)
13+
end
14+
end
15+
end

test/cadet_web/admin_controllers/admin_assessments_controller_test.exs

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ defmodule CadetWeb.AdminAssessmentsControllerTest do
9090
"isPublished" => &1.is_published,
9191
"gradedCount" => 0,
9292
"questionCount" => 9,
93-
"xp" => (800 + 500 + 100) * 3
93+
"xp" => (800 + 500 + 100) * 3,
94+
"hasVotingFeatures" => &1.has_voting_features,
95+
"hasTokenCounter" => &1.has_token_counter
9496
}
9597
)
9698

@@ -137,7 +139,9 @@ defmodule CadetWeb.AdminAssessmentsControllerTest do
137139
"isPublished" => &1.is_published,
138140
"gradedCount" => 0,
139141
"questionCount" => 9,
140-
"xp" => 0
142+
"xp" => 0,
143+
"hasVotingFeatures" => &1.has_voting_features,
144+
"hasTokenCounter" => &1.has_token_counter
141145
}
142146
)
143147

@@ -669,6 +673,76 @@ defmodule CadetWeb.AdminAssessmentsControllerTest do
669673
assert response(conn, 200) == "OK"
670674
assert [assessment.open_at, assessment.close_at] == [new_open_at, close_at]
671675
end
676+
677+
@tag authenticate: :staff
678+
test "successful, set hasTokenCounter and hasVotingFeatures to true", %{conn: conn} do
679+
test_cr = conn.assigns.test_cr
680+
course = test_cr.course
681+
config = insert(:assessment_config, %{course: course})
682+
683+
assessment =
684+
insert(:assessment, %{
685+
course: course,
686+
config: config,
687+
has_token_counter: false,
688+
has_voting_features: false
689+
})
690+
691+
new_has_token_counter = true
692+
new_has_voting_features = true
693+
694+
new_assessment_setting = %{
695+
hasTokenCounter: new_has_token_counter,
696+
hasVotingFeatures: new_has_voting_features
697+
}
698+
699+
conn =
700+
conn
701+
|> post(build_url(course.id, assessment.id), new_assessment_setting)
702+
703+
assessment = Repo.get(Assessment, assessment.id)
704+
assert response(conn, 200) == "OK"
705+
706+
assert [assessment.has_token_counter, assessment.has_voting_features] == [
707+
new_has_token_counter,
708+
new_has_voting_features
709+
]
710+
end
711+
712+
@tag authenticate: :staff
713+
test "successful, set hasTokenCounter and hasVotingFeatures to false", %{conn: conn} do
714+
test_cr = conn.assigns.test_cr
715+
course = test_cr.course
716+
config = insert(:assessment_config, %{course: course})
717+
718+
assessment =
719+
insert(:assessment, %{
720+
course: course,
721+
config: config,
722+
has_token_counter: true,
723+
has_voting_features: true
724+
})
725+
726+
new_has_token_counter = false
727+
new_has_voting_features = false
728+
729+
new_assessment_setting = %{
730+
hasTokenCounter: new_has_token_counter,
731+
hasVotingFeatures: new_has_voting_features
732+
}
733+
734+
conn =
735+
conn
736+
|> post(build_url(course.id, assessment.id), new_assessment_setting)
737+
738+
assessment = Repo.get(Assessment, assessment.id)
739+
assert response(conn, 200) == "OK"
740+
741+
assert [assessment.has_token_counter, assessment.has_voting_features] == [
742+
new_has_token_counter,
743+
new_has_voting_features
744+
]
745+
end
672746
end
673747

674748
defp build_url(course_id), do: "/v2/courses/#{course_id}/admin/assessments/"

test/cadet_web/admin_controllers/admin_courses_controller_test.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ defmodule CadetWeb.AdminCoursesControllerTest do
158158
order: 2,
159159
type: "Mission2",
160160
course: course,
161+
has_voting_features: true,
161162
has_token_counter: true
162163
})
163164

@@ -174,6 +175,7 @@ defmodule CadetWeb.AdminCoursesControllerTest do
174175
"isManuallyGraded" => true,
175176
"type" => "Mission1",
176177
"assessmentConfigId" => config1.id,
178+
"hasVotingFeatures" => false,
177179
"hasTokenCounter" => false
178180
},
179181
%{
@@ -183,6 +185,7 @@ defmodule CadetWeb.AdminCoursesControllerTest do
183185
"isManuallyGraded" => false,
184186
"type" => "Mission2",
185187
"assessmentConfigId" => config2.id,
188+
"hasVotingFeatures" => true,
186189
"hasTokenCounter" => true
187190
},
188191
%{
@@ -192,6 +195,7 @@ defmodule CadetWeb.AdminCoursesControllerTest do
192195
"isManuallyGraded" => true,
193196
"type" => "Mission3",
194197
"assessmentConfigId" => config3.id,
198+
"hasVotingFeatures" => false,
195199
"hasTokenCounter" => false
196200
}
197201
]

test/cadet_web/controllers/assessments_controller_test.exs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ defmodule CadetWeb.AssessmentsControllerTest do
7979
"private" => false,
8080
"isPublished" => &1.is_published,
8181
"gradedCount" => 0,
82-
"questionCount" => 9
82+
"questionCount" => 9,
83+
"hasVotingFeatures" => &1.has_voting_features,
84+
"hasTokenCounter" => &1.has_token_counter
8385
}
8486
)
8587

@@ -163,7 +165,9 @@ defmodule CadetWeb.AssessmentsControllerTest do
163165
"private" => false,
164166
"isPublished" => &1.is_published,
165167
"gradedCount" => 0,
166-
"questionCount" => 9
168+
"questionCount" => 9,
169+
"hasVotingFeatures" => &1.has_voting_features,
170+
"hasTokenCounter" => &1.has_token_counter
167171
}
168172
)
169173

@@ -274,6 +278,8 @@ defmodule CadetWeb.AssessmentsControllerTest do
274278
"private" => false,
275279
"gradedCount" => 0,
276280
"questionCount" => 9,
281+
"hasVotingFeatures" => &1.has_voting_features,
282+
"hasTokenCounter" => &1.has_token_counter,
277283
"isPublished" =>
278284
if &1.config.type == hd(configs).type do
279285
false
@@ -308,6 +314,7 @@ defmodule CadetWeb.AssessmentsControllerTest do
308314
"number" => assessment.number,
309315
"reading" => assessment.reading,
310316
"longSummary" => assessment.summary_long,
317+
"hasTokenCounter" => assessment.has_token_counter,
311318
"missionPDF" => Cadet.Assessments.Upload.url({assessment.mission_pdf, assessment})
312319
}
313320

test/cadet_web/controllers/user_controller_test.exs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ defmodule CadetWeb.UserControllerTest do
123123
"assessmentConfigId" => config1.id,
124124
"earlySubmissionXp" => 200,
125125
"hoursBeforeEarlyXpDecay" => 48,
126+
"hasVotingFeatures" => false,
126127
"hasTokenCounter" => false
127128
},
128129
%{
@@ -132,6 +133,7 @@ defmodule CadetWeb.UserControllerTest do
132133
"assessmentConfigId" => config2.id,
133134
"earlySubmissionXp" => 200,
134135
"hoursBeforeEarlyXpDecay" => 48,
136+
"hasVotingFeatures" => false,
135137
"hasTokenCounter" => false
136138
},
137139
%{
@@ -141,6 +143,7 @@ defmodule CadetWeb.UserControllerTest do
141143
"assessmentConfigId" => config3.id,
142144
"earlySubmissionXp" => 200,
143145
"hoursBeforeEarlyXpDecay" => 48,
146+
"hasVotingFeatures" => false,
144147
"hasTokenCounter" => false
145148
}
146149
]

0 commit comments

Comments
 (0)