From 2da51017652557ea5c79fd15feb34fe9d12e1c67 Mon Sep 17 00:00:00 2001 From: Xiang Yu <156517235+DesSnowy@users.noreply.github.com> Date: Wed, 20 Mar 2024 23:39:19 +0800 Subject: [PATCH 01/14] rename hasTokenCounter to hasVotingFeature under assessmentConfig --- lib/cadet/courses/assessment_config.ex | 4 ++-- lib/cadet_web/admin_views/admin_courses_view.ex | 2 +- lib/cadet_web/views/user_view.ex | 2 +- ...17_rename_has_token_counter_to_has_voting_features.exs | 7 +++++++ .../admin_controllers/admin_courses_controller_test.exs | 8 ++++---- test/cadet_web/controllers/user_controller_test.exs | 6 +++--- 6 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 priv/repo/migrations/20240320151717_rename_has_token_counter_to_has_voting_features.exs diff --git a/lib/cadet/courses/assessment_config.ex b/lib/cadet/courses/assessment_config.ex index ec2455b69..ee15a9631 100644 --- a/lib/cadet/courses/assessment_config.ex +++ b/lib/cadet/courses/assessment_config.ex @@ -12,7 +12,7 @@ defmodule Cadet.Courses.AssessmentConfig do field(:type, :string) field(:show_grading_summary, :boolean, default: true) field(:is_manually_graded, :boolean, default: true) - field(:has_token_counter, :boolean, default: false) + field(:has_voting_features, :boolean, default: false) # used by frontend to determine display styles field(:early_submission_xp, :integer, default: 0) field(:hours_before_early_xp_decay, :integer, default: 0) @@ -24,7 +24,7 @@ defmodule Cadet.Courses.AssessmentConfig do @required_fields ~w(course_id)a @optional_fields ~w(order type early_submission_xp - hours_before_early_xp_decay show_grading_summary is_manually_graded has_token_counter)a + hours_before_early_xp_decay show_grading_summary is_manually_graded has_voting_features)a def changeset(assessment_config, params) do assessment_config diff --git a/lib/cadet_web/admin_views/admin_courses_view.ex b/lib/cadet_web/admin_views/admin_courses_view.ex index 4ce97f3c0..f561fa815 100644 --- a/lib/cadet_web/admin_views/admin_courses_view.ex +++ b/lib/cadet_web/admin_views/admin_courses_view.ex @@ -12,7 +12,7 @@ defmodule CadetWeb.AdminCoursesView do displayInDashboard: :show_grading_summary, isManuallyGraded: :is_manually_graded, earlySubmissionXp: :early_submission_xp, - hasTokenCounter: :has_token_counter, + hasVotingFeatures: :has_voting_features, hoursBeforeEarlyXpDecay: :hours_before_early_xp_decay }) end diff --git a/lib/cadet_web/views/user_view.ex b/lib/cadet_web/views/user_view.ex index 35de6c92b..c153e841b 100644 --- a/lib/cadet_web/views/user_view.ex +++ b/lib/cadet_web/views/user_view.ex @@ -125,7 +125,7 @@ defmodule CadetWeb.UserView do type: :type, displayInDashboard: :show_grading_summary, isManuallyGraded: :is_manually_graded, - hasTokenCounter: :has_token_counter, + hasVotingFeatures: :has_voting_features, earlySubmissionXp: :early_submission_xp, hoursBeforeEarlyXpDecay: :hours_before_early_xp_decay }) diff --git a/priv/repo/migrations/20240320151717_rename_has_token_counter_to_has_voting_features.exs b/priv/repo/migrations/20240320151717_rename_has_token_counter_to_has_voting_features.exs new file mode 100644 index 000000000..61f689930 --- /dev/null +++ b/priv/repo/migrations/20240320151717_rename_has_token_counter_to_has_voting_features.exs @@ -0,0 +1,7 @@ +defmodule Cadet.Repo.Migrations.RenameHasTokenCounterToHasVotingFeatures do + use Ecto.Migration + + def change do + rename(table(:assessment_configs), :has_token_counter, to: :has_voting_features) + end +end diff --git a/test/cadet_web/admin_controllers/admin_courses_controller_test.exs b/test/cadet_web/admin_controllers/admin_courses_controller_test.exs index 492d4f8a0..c29ddbb02 100644 --- a/test/cadet_web/admin_controllers/admin_courses_controller_test.exs +++ b/test/cadet_web/admin_controllers/admin_courses_controller_test.exs @@ -158,7 +158,7 @@ defmodule CadetWeb.AdminCoursesControllerTest do order: 2, type: "Mission2", course: course, - has_token_counter: true + has_voting_features: true }) resp = @@ -174,7 +174,7 @@ defmodule CadetWeb.AdminCoursesControllerTest do "isManuallyGraded" => true, "type" => "Mission1", "assessmentConfigId" => config1.id, - "hasTokenCounter" => false + "hasVotingFeatures" => false }, %{ "earlySubmissionXp" => 200, @@ -183,7 +183,7 @@ defmodule CadetWeb.AdminCoursesControllerTest do "isManuallyGraded" => false, "type" => "Mission2", "assessmentConfigId" => config2.id, - "hasTokenCounter" => true + "hasVotingFeatures" => true }, %{ "earlySubmissionXp" => 200, @@ -192,7 +192,7 @@ defmodule CadetWeb.AdminCoursesControllerTest do "isManuallyGraded" => true, "type" => "Mission3", "assessmentConfigId" => config3.id, - "hasTokenCounter" => false + "hasVotingFeatures" => false } ] diff --git a/test/cadet_web/controllers/user_controller_test.exs b/test/cadet_web/controllers/user_controller_test.exs index c16a9b1fc..09bfffb88 100644 --- a/test/cadet_web/controllers/user_controller_test.exs +++ b/test/cadet_web/controllers/user_controller_test.exs @@ -123,7 +123,7 @@ defmodule CadetWeb.UserControllerTest do "assessmentConfigId" => config1.id, "earlySubmissionXp" => 200, "hoursBeforeEarlyXpDecay" => 48, - "hasTokenCounter" => false + "hasVotingFeatures" => false }, %{ "type" => "test type 2", @@ -132,7 +132,7 @@ defmodule CadetWeb.UserControllerTest do "assessmentConfigId" => config2.id, "earlySubmissionXp" => 200, "hoursBeforeEarlyXpDecay" => 48, - "hasTokenCounter" => false + "hasVotingFeatures" => false }, %{ "type" => "test type 3", @@ -141,7 +141,7 @@ defmodule CadetWeb.UserControllerTest do "assessmentConfigId" => config3.id, "earlySubmissionXp" => 200, "hoursBeforeEarlyXpDecay" => 48, - "hasTokenCounter" => false + "hasVotingFeatures" => false } ] } From fe7854cf94ff3077f6825e2019a8d8f6818c83ac Mon Sep 17 00:00:00 2001 From: Xiang Yu <156517235+DesSnowy@users.noreply.github.com> Date: Fri, 22 Mar 2024 01:11:43 +0800 Subject: [PATCH 02/14] Added hasVotingFeatures to assessment config --- lib/cadet/courses/assessment_config.ex | 3 ++- ...oting_features_toggle_to_assessment_config.exs | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 priv/repo/migrations/20240321141522_add_has_voting_features_toggle_to_assessment_config.exs diff --git a/lib/cadet/courses/assessment_config.ex b/lib/cadet/courses/assessment_config.ex index ee15a9631..a9ea941ed 100644 --- a/lib/cadet/courses/assessment_config.ex +++ b/lib/cadet/courses/assessment_config.ex @@ -12,6 +12,7 @@ defmodule Cadet.Courses.AssessmentConfig do field(:type, :string) field(:show_grading_summary, :boolean, default: true) field(:is_manually_graded, :boolean, default: true) + field(:has_token_counter, :boolean, default: false) field(:has_voting_features, :boolean, default: false) # used by frontend to determine display styles field(:early_submission_xp, :integer, default: 0) @@ -24,7 +25,7 @@ defmodule Cadet.Courses.AssessmentConfig do @required_fields ~w(course_id)a @optional_fields ~w(order type early_submission_xp - hours_before_early_xp_decay show_grading_summary is_manually_graded has_voting_features)a + hours_before_early_xp_decay show_grading_summary is_manually_graded has_voting_features has_token_counter)a def changeset(assessment_config, params) do assessment_config diff --git a/priv/repo/migrations/20240321141522_add_has_voting_features_toggle_to_assessment_config.exs b/priv/repo/migrations/20240321141522_add_has_voting_features_toggle_to_assessment_config.exs new file mode 100644 index 000000000..4fe02d730 --- /dev/null +++ b/priv/repo/migrations/20240321141522_add_has_voting_features_toggle_to_assessment_config.exs @@ -0,0 +1,15 @@ +defmodule Cadet.Repo.Migrations.AddHasVotingFeaturesToggleToAssessmentConfig do + use Ecto.Migration + + def up do + alter table(:assessment_configs) do + add(:has_voting_features, :boolean, null: false, default: false) + end + end + + def down do + alter table(:assessment_configs) do + remove(:has_voting_features) + end + end +end From d2bfd924e9be49074143cfccce32c8b3b9e455f4 Mon Sep 17 00:00:00 2001 From: Xiang Yu <156517235+DesSnowy@users.noreply.github.com> Date: Fri, 22 Mar 2024 01:13:03 +0800 Subject: [PATCH 03/14] Added hasVotingFeature to assessmentConfig --- ...717_rename_has_token_counter_to_has_voting_features.exs | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 priv/repo/migrations/20240320151717_rename_has_token_counter_to_has_voting_features.exs diff --git a/priv/repo/migrations/20240320151717_rename_has_token_counter_to_has_voting_features.exs b/priv/repo/migrations/20240320151717_rename_has_token_counter_to_has_voting_features.exs deleted file mode 100644 index 61f689930..000000000 --- a/priv/repo/migrations/20240320151717_rename_has_token_counter_to_has_voting_features.exs +++ /dev/null @@ -1,7 +0,0 @@ -defmodule Cadet.Repo.Migrations.RenameHasTokenCounterToHasVotingFeatures do - use Ecto.Migration - - def change do - rename(table(:assessment_configs), :has_token_counter, to: :has_voting_features) - end -end From cb18e73d13d37184931b9e7e680d464f94588476 Mon Sep 17 00:00:00 2001 From: Xiang Yu <156517235+DesSnowy@users.noreply.github.com> Date: Fri, 22 Mar 2024 01:13:55 +0800 Subject: [PATCH 04/14] Added hasTokenCounter and hasVotingFeatures to assessments --- lib/cadet/assessments/assessment.ex | 6 ++++-- ...d_has_token_counter_toggle_to_assessment.exs | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 priv/repo/migrations/20240320154407_add_has_token_counter_toggle_to_assessment.exs diff --git a/lib/cadet/assessments/assessment.ex b/lib/cadet/assessments/assessment.ex index 77d0ef513..715ded37e 100644 --- a/lib/cadet/assessments/assessment.ex +++ b/lib/cadet/assessments/assessment.ex @@ -32,6 +32,8 @@ defmodule Cadet.Assessments.Assessment do field(:story, :string) field(:reading, :string) field(:password, :string, default: nil) + field(:has_token_counter, :boolean, default: :false) + field(:has_voting_features, :boolean, default: :false) belongs_to(:config, AssessmentConfig) belongs_to(:course, Course) @@ -40,9 +42,9 @@ defmodule Cadet.Assessments.Assessment do timestamps() end - @required_fields ~w(title open_at close_at number course_id config_id)a + @required_fields ~w(title open_at close_at number course_id config_id )a @optional_fields ~w(reading summary_short summary_long - is_published story cover_picture access password)a + is_published story cover_picture access password has_token_counter has_voting_features)a @optional_file_fields ~w(mission_pdf)a def changeset(assessment, params) do diff --git a/priv/repo/migrations/20240320154407_add_has_token_counter_toggle_to_assessment.exs b/priv/repo/migrations/20240320154407_add_has_token_counter_toggle_to_assessment.exs new file mode 100644 index 000000000..6bb8daaed --- /dev/null +++ b/priv/repo/migrations/20240320154407_add_has_token_counter_toggle_to_assessment.exs @@ -0,0 +1,17 @@ +defmodule Cadet.Repo.Migrations.AddHasTokenCounterToggleToAssessment do + use Ecto.Migration + + def up do + alter table(:assessments) do + add(:has_token_counter, :boolean, null: false, default: false) + add(:has_voting_features, :boolean, null: false, default: false) + end + end + + def down do + alter table(:assessments) do + remove(:has_token_counter) + remove(:has_voting_features) + end + end +end From 6012b112e949c9e1bb08c8664d388d18ff284256 Mon Sep 17 00:00:00 2001 From: Xiang Yu <156517235+DesSnowy@users.noreply.github.com> Date: Fri, 22 Mar 2024 01:15:06 +0800 Subject: [PATCH 05/14] hasTokenCounter and hasVotingFeatures to be updated to ones in assessment config when uploaded --- lib/cadet/jobs/xml_parser.ex | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/cadet/jobs/xml_parser.ex b/lib/cadet/jobs/xml_parser.ex index fb1742571..36399aa85 100644 --- a/lib/cadet/jobs/xml_parser.ex +++ b/lib/cadet/jobs/xml_parser.ex @@ -5,8 +5,11 @@ defmodule Cadet.Updater.XMLParser do use Cadet, [:display] + import Ecto.Query import SweetXml + alias Cadet.Repo + alias Cadet.Courses.AssessmentConfig alias Cadet.Assessments require Logger @@ -80,6 +83,11 @@ defmodule Cadet.Updater.XMLParser do close_at = Timex.shift(open_at, days: 7) + assessmentConfig = + AssessmentConfig + |> where(id: ^assessment_config_id) + |> Repo.one() + assessment_params = xml |> xpath( @@ -99,6 +107,8 @@ defmodule Cadet.Updater.XMLParser do |> Map.put(:close_at, close_at) |> Map.put(:course_id, course_id) |> Map.put(:config_id, assessment_config_id) + |> Map.put(:has_token_counter, assessmentConfig.has_token_counter) + |> Map.put(:has_voting_features, assessmentConfig.has_voting_features) |> (&if(&1.access === "public", do: Map.put(&1, :password, nil), else: &1 From ade5541da0b0a8003c72278242dfc3a22f9659d3 Mon Sep 17 00:00:00 2001 From: Xiang Yu <156517235+DesSnowy@users.noreply.github.com> Date: Fri, 22 Mar 2024 01:16:21 +0800 Subject: [PATCH 06/14] Added hasTokenCounter and hasVotingFeatures to be shown when assessment is requested --- lib/cadet_web/admin_views/admin_assessments_view.ex | 5 ++++- lib/cadet_web/admin_views/admin_courses_view.ex | 1 + lib/cadet_web/views/assessments_view.ex | 5 ++++- lib/cadet_web/views/user_view.ex | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/cadet_web/admin_views/admin_assessments_view.ex b/lib/cadet_web/admin_views/admin_assessments_view.ex index 4b1274d5d..9566be027 100644 --- a/lib/cadet_web/admin_views/admin_assessments_view.ex +++ b/lib/cadet_web/admin_views/admin_assessments_view.ex @@ -27,7 +27,9 @@ defmodule CadetWeb.AdminAssessmentsView do private: &password_protected?(&1.password), isPublished: :is_published, questionCount: :question_count, - gradedCount: &(&1.graded_count || 0) + gradedCount: &(&1.graded_count || 0), + hasVotingFeatures: :has_voting_features, + hasTokenCounter: :has_token_counter }) end @@ -43,6 +45,7 @@ defmodule CadetWeb.AdminAssessmentsView do number: :number, reading: :reading, longSummary: :summary_long, + hasTokenCounter: :has_token_counter, missionPDF: &Cadet.Assessments.Upload.url({&1.mission_pdf, &1}), questions: &Enum.map(&1.questions, fn question -> diff --git a/lib/cadet_web/admin_views/admin_courses_view.ex b/lib/cadet_web/admin_views/admin_courses_view.ex index f561fa815..2804eb664 100644 --- a/lib/cadet_web/admin_views/admin_courses_view.ex +++ b/lib/cadet_web/admin_views/admin_courses_view.ex @@ -13,6 +13,7 @@ defmodule CadetWeb.AdminCoursesView do isManuallyGraded: :is_manually_graded, earlySubmissionXp: :early_submission_xp, hasVotingFeatures: :has_voting_features, + hasTokenCounter: :has_token_counter, hoursBeforeEarlyXpDecay: :hours_before_early_xp_decay }) end diff --git a/lib/cadet_web/views/assessments_view.ex b/lib/cadet_web/views/assessments_view.ex index 20aad951f..d712f1cfd 100644 --- a/lib/cadet_web/views/assessments_view.ex +++ b/lib/cadet_web/views/assessments_view.ex @@ -28,7 +28,9 @@ defmodule CadetWeb.AssessmentsView do private: &password_protected?(&1.password), isPublished: :is_published, questionCount: :question_count, - gradedCount: &(&1.graded_count || 0) + gradedCount: &(&1.graded_count || 0), + hasVotingFeatures: :has_voting_features, + hasTokenCounter: :has_token_counter }) end @@ -44,6 +46,7 @@ defmodule CadetWeb.AssessmentsView do number: :number, reading: :reading, longSummary: :summary_long, + hasTokenCounter: :has_token_counter, missionPDF: &Cadet.Assessments.Upload.url({&1.mission_pdf, &1}), questions: &Enum.map(&1.questions, fn question -> diff --git a/lib/cadet_web/views/user_view.ex b/lib/cadet_web/views/user_view.ex index c153e841b..84b5b5392 100644 --- a/lib/cadet_web/views/user_view.ex +++ b/lib/cadet_web/views/user_view.ex @@ -126,6 +126,7 @@ defmodule CadetWeb.UserView do displayInDashboard: :show_grading_summary, isManuallyGraded: :is_manually_graded, hasVotingFeatures: :has_voting_features, + hasTokenCounter: :has_token_counter, earlySubmissionXp: :early_submission_xp, hoursBeforeEarlyXpDecay: :hours_before_early_xp_decay }) From 284da0622a14c9e6544a6861c8547f0855a98f1e Mon Sep 17 00:00:00 2001 From: Xiang Yu <156517235+DesSnowy@users.noreply.github.com> Date: Fri, 22 Mar 2024 01:17:00 +0800 Subject: [PATCH 07/14] Added hasTokenCounter into swaggers --- lib/cadet_web/controllers/assessments_controller.ex | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/cadet_web/controllers/assessments_controller.ex b/lib/cadet_web/controllers/assessments_controller.ex index 5fb0659ec..bc053afe4 100644 --- a/lib/cadet_web/controllers/assessments_controller.ex +++ b/lib/cadet_web/controllers/assessments_controller.ex @@ -174,6 +174,8 @@ defmodule CadetWeb.AssessmentsController do required: true ) + hasTokenCounter(:boolean, "Does the assessment have Token Counter enabled?") + maxXp( :integer, "The maximum XP for this assessment", @@ -214,6 +216,7 @@ defmodule CadetWeb.AssessmentsController do story(:string, "The story that should be shown for this assessment") reading(:string, "The reading for this assessment") longSummary(:string, "Long summary", required: true) + hasTokenCounter(:boolean, "Does the assessment have Token Counter enabled?") missionPDF(:string, "The URL to the assessment pdf") questions(Schema.ref(:Questions), "The list of questions for this assessment") From 96d1dc7bba428d927d02b34e34d4fb03303ebfb4 Mon Sep 17 00:00:00 2001 From: Xiang Yu <156517235+DesSnowy@users.noreply.github.com> Date: Fri, 22 Mar 2024 01:17:23 +0800 Subject: [PATCH 08/14] Changed test cases to include hasVotingFeatures and hasTokenCounter --- .../admin_assessments_controller_test.exs | 8 ++++++-- .../admin_courses_controller_test.exs | 12 ++++++++---- .../controllers/assessments_controller_test.exs | 11 +++++++++-- test/cadet_web/controllers/user_controller_test.exs | 9 ++++++--- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/test/cadet_web/admin_controllers/admin_assessments_controller_test.exs b/test/cadet_web/admin_controllers/admin_assessments_controller_test.exs index f1411ada3..fe693f206 100644 --- a/test/cadet_web/admin_controllers/admin_assessments_controller_test.exs +++ b/test/cadet_web/admin_controllers/admin_assessments_controller_test.exs @@ -89,7 +89,9 @@ defmodule CadetWeb.AdminAssessmentsControllerTest do "isPublished" => &1.is_published, "gradedCount" => 0, "questionCount" => 9, - "xp" => (800 + 500 + 100) * 3 + "xp" => (800 + 500 + 100) * 3, + "hasVotingFeatures" => &1.has_voting_features, + "hasTokenCounter" => &1.has_token_counter } ) @@ -135,7 +137,9 @@ defmodule CadetWeb.AdminAssessmentsControllerTest do "isPublished" => &1.is_published, "gradedCount" => 0, "questionCount" => 9, - "xp" => 0 + "xp" => 0, + "hasVotingFeatures" => &1.has_voting_features, + "hasTokenCounter" => &1.has_token_counter } ) diff --git a/test/cadet_web/admin_controllers/admin_courses_controller_test.exs b/test/cadet_web/admin_controllers/admin_courses_controller_test.exs index c29ddbb02..c9a3096c2 100644 --- a/test/cadet_web/admin_controllers/admin_courses_controller_test.exs +++ b/test/cadet_web/admin_controllers/admin_courses_controller_test.exs @@ -158,7 +158,8 @@ defmodule CadetWeb.AdminCoursesControllerTest do order: 2, type: "Mission2", course: course, - has_voting_features: true + has_voting_features: true, + has_token_counter: true }) resp = @@ -174,7 +175,8 @@ defmodule CadetWeb.AdminCoursesControllerTest do "isManuallyGraded" => true, "type" => "Mission1", "assessmentConfigId" => config1.id, - "hasVotingFeatures" => false + "hasVotingFeatures" => false, + "hasTokenCounter" => false }, %{ "earlySubmissionXp" => 200, @@ -183,7 +185,8 @@ defmodule CadetWeb.AdminCoursesControllerTest do "isManuallyGraded" => false, "type" => "Mission2", "assessmentConfigId" => config2.id, - "hasVotingFeatures" => true + "hasVotingFeatures" => true, + "hasTokenCounter" => true }, %{ "earlySubmissionXp" => 200, @@ -192,7 +195,8 @@ defmodule CadetWeb.AdminCoursesControllerTest do "isManuallyGraded" => true, "type" => "Mission3", "assessmentConfigId" => config3.id, - "hasVotingFeatures" => false + "hasVotingFeatures" => false, + "hasTokenCounter" => false } ] diff --git a/test/cadet_web/controllers/assessments_controller_test.exs b/test/cadet_web/controllers/assessments_controller_test.exs index f9251d09b..1e2c5a49c 100644 --- a/test/cadet_web/controllers/assessments_controller_test.exs +++ b/test/cadet_web/controllers/assessments_controller_test.exs @@ -78,7 +78,9 @@ defmodule CadetWeb.AssessmentsControllerTest do "private" => false, "isPublished" => &1.is_published, "gradedCount" => 0, - "questionCount" => 9 + "questionCount" => 9, + "hasVotingFeatures" => &1.has_voting_features, + "hasTokenCounter" => &1.has_token_counter } ) @@ -161,7 +163,9 @@ defmodule CadetWeb.AssessmentsControllerTest do "private" => false, "isPublished" => &1.is_published, "gradedCount" => 0, - "questionCount" => 9 + "questionCount" => 9, + "hasVotingFeatures" => &1.has_voting_features, + "hasTokenCounter" => &1.has_token_counter } ) @@ -271,6 +275,8 @@ defmodule CadetWeb.AssessmentsControllerTest do "private" => false, "gradedCount" => 0, "questionCount" => 9, + "hasVotingFeatures" => &1.has_voting_features, + "hasTokenCounter" => &1.has_token_counter, "isPublished" => if &1.config.type == hd(configs).type do false @@ -305,6 +311,7 @@ defmodule CadetWeb.AssessmentsControllerTest do "number" => assessment.number, "reading" => assessment.reading, "longSummary" => assessment.summary_long, + "hasTokenCounter" => assessment.has_token_counter, "missionPDF" => Cadet.Assessments.Upload.url({assessment.mission_pdf, assessment}) } diff --git a/test/cadet_web/controllers/user_controller_test.exs b/test/cadet_web/controllers/user_controller_test.exs index 09bfffb88..1b6465af5 100644 --- a/test/cadet_web/controllers/user_controller_test.exs +++ b/test/cadet_web/controllers/user_controller_test.exs @@ -123,7 +123,8 @@ defmodule CadetWeb.UserControllerTest do "assessmentConfigId" => config1.id, "earlySubmissionXp" => 200, "hoursBeforeEarlyXpDecay" => 48, - "hasVotingFeatures" => false + "hasVotingFeatures" => false, + "hasTokenCounter" => false }, %{ "type" => "test type 2", @@ -132,7 +133,8 @@ defmodule CadetWeb.UserControllerTest do "assessmentConfigId" => config2.id, "earlySubmissionXp" => 200, "hoursBeforeEarlyXpDecay" => 48, - "hasVotingFeatures" => false + "hasVotingFeatures" => false, + "hasTokenCounter" => false }, %{ "type" => "test type 3", @@ -141,7 +143,8 @@ defmodule CadetWeb.UserControllerTest do "assessmentConfigId" => config3.id, "earlySubmissionXp" => 200, "hoursBeforeEarlyXpDecay" => 48, - "hasVotingFeatures" => false + "hasVotingFeatures" => false, + "hasTokenCounter" => false } ] } From 96879304cdda1fd08f928ab67862decc707af7c4 Mon Sep 17 00:00:00 2001 From: Xiang Yu <156517235+DesSnowy@users.noreply.github.com> Date: Fri, 22 Mar 2024 10:07:34 +0800 Subject: [PATCH 09/14] Added a way to change hasTokenCounter and hasVotingFeatures from the frontEnd --- .../admin_controllers/admin_assessments_controller.ex | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/cadet_web/admin_controllers/admin_assessments_controller.ex b/lib/cadet_web/admin_controllers/admin_assessments_controller.ex index 4a5076b33..68e8f2483 100644 --- a/lib/cadet_web/admin_controllers/admin_assessments_controller.ex +++ b/lib/cadet_web/admin_controllers/admin_assessments_controller.ex @@ -82,6 +82,8 @@ defmodule CadetWeb.AdminAssessmentsController do open_at = params |> Map.get("openAt") close_at = params |> Map.get("closeAt") is_published = params |> Map.get("isPublished") + has_token_counter = params |> Map.get("hasTokenCounter") + has_voting_features = params |> Map.get("hasVotingFeatures") updated_assessment = if is_nil(is_published) do @@ -90,6 +92,15 @@ defmodule CadetWeb.AdminAssessmentsController do %{:is_published => is_published} end + updated_assessment = + if is_nil(has_token_counter) do + updated_assessment + else + updated_assessment + |> Map.put(:has_token_counter, has_token_counter) + |> Map.put(:has_voting_features, has_voting_features) + end + with {:ok, assessment} <- check_dates(open_at, close_at, updated_assessment), {:ok, _nil} <- Assessments.update_assessment(assessment_id, assessment) do text(conn, "OK") From 0bc248606e1c3ca9eebc9e7db23197bf02040a18 Mon Sep 17 00:00:00 2001 From: Xiang Yu <156517235+DesSnowy@users.noreply.github.com> Date: Fri, 22 Mar 2024 10:07:41 +0800 Subject: [PATCH 10/14] fixed format --- lib/cadet/assessments/assessment.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cadet/assessments/assessment.ex b/lib/cadet/assessments/assessment.ex index 715ded37e..4e692ed7d 100644 --- a/lib/cadet/assessments/assessment.ex +++ b/lib/cadet/assessments/assessment.ex @@ -32,8 +32,8 @@ defmodule Cadet.Assessments.Assessment do field(:story, :string) field(:reading, :string) field(:password, :string, default: nil) - field(:has_token_counter, :boolean, default: :false) - field(:has_voting_features, :boolean, default: :false) + field(:has_token_counter, :boolean, default: false) + field(:has_voting_features, :boolean, default: false) belongs_to(:config, AssessmentConfig) belongs_to(:course, Course) From 394cb5201f98f4e47b8cf9ee65c9d76de78358e8 Mon Sep 17 00:00:00 2001 From: Xiang Yu <156517235+DesSnowy@users.noreply.github.com> Date: Fri, 22 Mar 2024 21:59:47 +0800 Subject: [PATCH 11/14] fixed format --- lib/cadet/jobs/xml_parser.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cadet/jobs/xml_parser.ex b/lib/cadet/jobs/xml_parser.ex index 36399aa85..18392311d 100644 --- a/lib/cadet/jobs/xml_parser.ex +++ b/lib/cadet/jobs/xml_parser.ex @@ -83,7 +83,7 @@ defmodule Cadet.Updater.XMLParser do close_at = Timex.shift(open_at, days: 7) - assessmentConfig = + assessment_config = AssessmentConfig |> where(id: ^assessment_config_id) |> Repo.one() @@ -107,8 +107,8 @@ defmodule Cadet.Updater.XMLParser do |> Map.put(:close_at, close_at) |> Map.put(:course_id, course_id) |> Map.put(:config_id, assessment_config_id) - |> Map.put(:has_token_counter, assessmentConfig.has_token_counter) - |> Map.put(:has_voting_features, assessmentConfig.has_voting_features) + |> Map.put(:has_token_counter, assessment_config.has_token_counter) + |> Map.put(:has_voting_features, assessment_config.has_voting_features) |> (&if(&1.access === "public", do: Map.put(&1, :password, nil), else: &1 From 49ac07db1d5d17a03791ee851c9108162da5512c Mon Sep 17 00:00:00 2001 From: Xiang Yu <156517235+DesSnowy@users.noreply.github.com> Date: Fri, 22 Mar 2024 22:04:54 +0800 Subject: [PATCH 12/14] fixed alias format --- lib/cadet/jobs/xml_parser.ex | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/cadet/jobs/xml_parser.ex b/lib/cadet/jobs/xml_parser.ex index 18392311d..09640b565 100644 --- a/lib/cadet/jobs/xml_parser.ex +++ b/lib/cadet/jobs/xml_parser.ex @@ -8,9 +8,7 @@ defmodule Cadet.Updater.XMLParser do import Ecto.Query import SweetXml - alias Cadet.Repo - alias Cadet.Courses.AssessmentConfig - alias Cadet.Assessments + alias Cadet.{Repo, Courses.AssessmentConfig, Assessments} require Logger From e815717edf028e678c40468439d03f915c786abd Mon Sep 17 00:00:00 2001 From: Xiang Yu <156517235+DesSnowy@users.noreply.github.com> Date: Sun, 24 Mar 2024 23:39:22 +0800 Subject: [PATCH 13/14] added new test case to ensure hasTokenCounter and hasVotingFeatures can be changed --- .../admin_assessments_controller_test.exs | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/test/cadet_web/admin_controllers/admin_assessments_controller_test.exs b/test/cadet_web/admin_controllers/admin_assessments_controller_test.exs index fe693f206..d954ae83c 100644 --- a/test/cadet_web/admin_controllers/admin_assessments_controller_test.exs +++ b/test/cadet_web/admin_controllers/admin_assessments_controller_test.exs @@ -671,6 +671,76 @@ defmodule CadetWeb.AdminAssessmentsControllerTest do assert response(conn, 200) == "OK" assert [assessment.open_at, assessment.close_at] == [new_open_at, close_at] end + + @tag authenticate: :staff + test "successful, set hasTokenCounter and hasVotingFeatures to true", %{conn: conn} do + test_cr = conn.assigns.test_cr + course = test_cr.course + config = insert(:assessment_config, %{course: course}) + + assessment = + insert(:assessment, %{ + course: course, + config: config, + has_token_counter: false, + has_voting_features: false + }) + + new_has_token_counter = true + new_has_voting_features = true + + new_assessment_setting = %{ + hasTokenCounter: new_has_token_counter, + hasVotingFeatures: new_has_voting_features + } + + conn = + conn + |> post(build_url(course.id, assessment.id), new_assessment_setting) + + assessment = Repo.get(Assessment, assessment.id) + assert response(conn, 200) == "OK" + + assert [assessment.has_token_counter, assessment.has_voting_features] == [ + new_has_token_counter, + new_has_voting_features + ] + end + + @tag authenticate: :staff + test "successful, set hasTokenCounter and hasVotingFeatures to false", %{conn: conn} do + test_cr = conn.assigns.test_cr + course = test_cr.course + config = insert(:assessment_config, %{course: course}) + + assessment = + insert(:assessment, %{ + course: course, + config: config, + has_token_counter: true, + has_voting_features: true + }) + + new_has_token_counter = false + new_has_voting_features = false + + new_assessment_setting = %{ + hasTokenCounter: new_has_token_counter, + hasVotingFeatures: new_has_voting_features + } + + conn = + conn + |> post(build_url(course.id, assessment.id), new_assessment_setting) + + assessment = Repo.get(Assessment, assessment.id) + assert response(conn, 200) == "OK" + + assert [assessment.has_token_counter, assessment.has_voting_features] == [ + new_has_token_counter, + new_has_voting_features + ] + end end defp build_url(course_id), do: "/v2/courses/#{course_id}/admin/assessments/" From b7dda287164d160c0a7470deb7e45da2247970f4 Mon Sep 17 00:00:00 2001 From: Xiang Yu <156517235+DesSnowy@users.noreply.github.com> Date: Tue, 26 Mar 2024 23:09:37 +0800 Subject: [PATCH 14/14] Seperated nil checks to be for indivudual field instead --- .../admin_controllers/admin_assessments_controller.ex | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/cadet_web/admin_controllers/admin_assessments_controller.ex b/lib/cadet_web/admin_controllers/admin_assessments_controller.ex index 6d785b6f7..5e27abefe 100644 --- a/lib/cadet_web/admin_controllers/admin_assessments_controller.ex +++ b/lib/cadet_web/admin_controllers/admin_assessments_controller.ex @@ -104,9 +104,14 @@ defmodule CadetWeb.AdminAssessmentsController do if is_nil(has_token_counter) do updated_assessment else + Map.put(updated_assessment, :has_token_counter, has_token_counter) + end + + updated_assessment = + if is_nil(has_voting_features) do updated_assessment - |> Map.put(:has_token_counter, has_token_counter) - |> Map.put(:has_voting_features, has_voting_features) + else + Map.put(updated_assessment, :has_voting_features, has_voting_features) end with {:ok, assessment} <- check_dates(open_at, close_at, updated_assessment),