From 00e2df59521dff852cd645fae9de314380cfe924 Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Fri, 18 Apr 2025 02:44:23 +0800 Subject: [PATCH 01/17] Upgrade Ubuntu runner version --- .github/workflows/cd.yml | 2 +- .github/workflows/ci.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 3d21f509c..c41408193 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -21,7 +21,7 @@ on: jobs: ci: name: Build release - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest env: MIX_ENV: prod GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index df06b98e4..908421a25 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ on: jobs: ci: name: Run CI - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest env: MIX_ENV: test GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From b13cb6c649084a5bc0394dccbed89fb3caddd419 Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Fri, 18 Apr 2025 02:45:29 +0800 Subject: [PATCH 02/17] Update README --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8b30d1591..1c1ed1901 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,9 @@ Cadet is the web application powering Source Academy. ### System requirements -1. Elixir 1.13.3+ (current version: 1.13.4) -2. Erlang/OTP 23.2.1+ (current version: 25.3.2) -3. PostgreSQL 12+ (tested to be working up to 14.5) +1. Elixir 1.18+ (current version: 1.18.3) +2. Erlang/OTP 27+ (current version: 27.3.3) +3. PostgreSQL 12+ (tested to be working up to 17) It is probably okay to use a different version of PostgreSQL or Erlang/OTP, but using a different version of Elixir may result in differences in e.g. `mix format`. From bcfd69b42f7ba252e04a696d8bc91b4b6d320f78 Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Fri, 18 Apr 2025 02:50:33 +0800 Subject: [PATCH 03/17] Update PostgreSQL install instructions --- README.md | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 1c1ed1901..d8d70bee3 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,16 @@ Cadet is the web application powering Source Academy. It is probably okay to use a different version of PostgreSQL or Erlang/OTP, but using a different version of Elixir may result in differences in e.g. `mix format`. +> ## Setting up PostgreSQL +> +> The simplest way to get started is to use Docker. Simply [install Docker](https://docs.docker.com/get-docker/) and run the following command: +> +> ```bash +> $ docker run --name sa-backend-db -e POSTGRES_HOST_AUTH_METHOD=trust -e -p 5432:5432 -d postgres +> ``` +> +> This configures PostgreSQL on port 5432. You can then connect to the database using `localhost:5432` as the host and `postgres` as the username. Note: `-e POSTGRES_HOST_AUTH_METHOD=trust` is used to disable password authentication for local development; since we are only accesing the database locally from our own machine, it is safe to do so. + ### Setting up your local development environment 1. Set up the development secrets (replace the values appropriately) @@ -29,8 +39,6 @@ It is probably okay to use a different version of PostgreSQL or Erlang/OTP, but $ vim config/dev.secrets.exs ``` - - To use NUSNET authentication, specify the NUS ADFS OAuth2 URL. (Ask for it.) Note that the frontend will supply the ADFS client ID and redirect URL (so you will need that too, but not here). - 2. Install Elixir dependencies ```bash @@ -49,19 +57,6 @@ It is probably okay to use a different version of PostgreSQL or Erlang/OTP, but $ mix ecto.setup ``` - If you encounter error message about invalid password for the user "postgres". - You should reset the "postgres" password: - - ```bash - $ sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';" - ``` - - and restart postgres service: - - ```bash - $ sudo service postgresql restart - ``` - By default, the database is populated with 10 students and 5 assessments. Each student will have a submission to the corresponding submission. This can be changed in `priv/repo/seeds.exs` with the variables `number_of_students`, `number_of_assessments` and `number_of_questions`. Save the changes and run: ```bash From 743fdd1b934b3ce8ee547100c33ed01036c99e12 Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Fri, 18 Apr 2025 02:51:59 +0800 Subject: [PATCH 04/17] Upgrade PostgreSQL version in CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 908421a25..47dfdc5ce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: OTP_VERSION: 25.3.2 services: postgres: - image: postgres:14.2 + image: postgres:17.4 env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres From 1e6cf7d0346bb97947e95e3bab21c73593831d3d Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Fri, 18 Apr 2025 02:52:29 +0800 Subject: [PATCH 05/17] Reformat codebase post Elixir version upgrade --- lib/cadet/devices/devices.ex | 6 +++++- .../admin_controllers/admin_assets_controller.ex | 8 ++++++-- .../admin_controllers/admin_courses_controller.ex | 6 +++++- .../admin_controllers/admin_grading_controller.ex | 4 +++- lib/cadet_web/admin_views/admin_assessments_view.ex | 4 +++- lib/cadet_web/views/assessments_view.ex | 4 +++- test/cadet_web/helpers/controller_helper_test.exs | 6 ++++-- 7 files changed, 29 insertions(+), 9 deletions(-) diff --git a/lib/cadet/devices/devices.ex b/lib/cadet/devices/devices.ex index 7862b8792..daaf117be 100644 --- a/lib/cadet/devices/devices.ex +++ b/lib/cadet/devices/devices.ex @@ -72,7 +72,11 @@ defmodule Cadet.Devices do with {:ok, device} <- maybe_insert_device(type, secret), {:ok, registration} <- %DeviceRegistration{} - |> DeviceRegistration.changeset(%{user_id: user_id, device_id: device.id, title: title}) + |> DeviceRegistration.changeset(%{ + user_id: user_id, + device_id: device.id, + title: title + }) |> Repo.insert() do {:ok, registration |> Repo.preload(:device)} end diff --git a/lib/cadet_web/admin_controllers/admin_assets_controller.ex b/lib/cadet_web/admin_controllers/admin_assets_controller.ex index 3316cfffa..4f35b15d1 100644 --- a/lib/cadet_web/admin_controllers/admin_assets_controller.ex +++ b/lib/cadet_web/admin_controllers/admin_assets_controller.ex @@ -96,7 +96,9 @@ defmodule CadetWeb.AdminAssetsController do parameters do folderName(:path, :string, "Folder name", required: true) - fileName(:path, :string, "File path in folder, which may contain subfolders", required: true) + fileName(:path, :string, "File path in folder, which may contain subfolders", + required: true + ) end security([%{JWT: []}]) @@ -115,7 +117,9 @@ defmodule CadetWeb.AdminAssetsController do parameters do folderName(:path, :string, "Folder name", required: true) - fileName(:path, :string, "File path in folder, which may contain subfolders", required: true) + fileName(:path, :string, "File path in folder, which may contain subfolders", + required: true + ) end security([%{JWT: []}]) diff --git a/lib/cadet_web/admin_controllers/admin_courses_controller.ex b/lib/cadet_web/admin_controllers/admin_courses_controller.ex index 7220a4d80..bdda2c868 100644 --- a/lib/cadet_web/admin_controllers/admin_courses_controller.ex +++ b/lib/cadet_web/admin_controllers/admin_courses_controller.ex @@ -143,7 +143,11 @@ defmodule CadetWeb.AdminCoursesController do title("AdminSublanguage") properties do - chapter(:integer, "Chapter number from 1 to 4", required: true, minimum: 1, maximum: 4) + chapter(:integer, "Chapter number from 1 to 4", + required: true, + minimum: 1, + maximum: 4 + ) variant(Schema.ref(:SourceVariant), "Variant name", required: true) end diff --git a/lib/cadet_web/admin_controllers/admin_grading_controller.ex b/lib/cadet_web/admin_controllers/admin_grading_controller.ex index aa93cd30f..9e7507bd7 100644 --- a/lib/cadet_web/admin_controllers/admin_grading_controller.ex +++ b/lib/cadet_web/admin_controllers/admin_grading_controller.ex @@ -378,7 +378,9 @@ defmodule CadetWeb.AdminGradingController do required: true ) - student(Schema.ref(:StudentInfo), "Student who created the submission", required: true) + student(Schema.ref(:StudentInfo), "Student who created the submission", + required: true + ) unsubmittedBy(Schema.ref(:GraderInfo)) unsubmittedAt(:string, "Last unsubmitted at", format: "date-time", required: false) diff --git a/lib/cadet_web/admin_views/admin_assessments_view.ex b/lib/cadet_web/admin_views/admin_assessments_view.ex index 33af48629..00bc81849 100644 --- a/lib/cadet_web/admin_views/admin_assessments_view.ex +++ b/lib/cadet_web/admin_views/admin_assessments_view.ex @@ -64,7 +64,9 @@ defmodule CadetWeb.AdminAssessmentsView do end def render("leaderboard.json", %{leaderboard: leaderboard}) do - render_many(leaderboard, CadetWeb.AdminAssessmentsView, "contestEntry.json", as: :contestEntry) + render_many(leaderboard, CadetWeb.AdminAssessmentsView, "contestEntry.json", + as: :contestEntry + ) end def render("contestEntry.json", %{contestEntry: contestEntry}) do diff --git a/lib/cadet_web/views/assessments_view.ex b/lib/cadet_web/views/assessments_view.ex index 7542c25c9..bee2efbc9 100644 --- a/lib/cadet_web/views/assessments_view.ex +++ b/lib/cadet_web/views/assessments_view.ex @@ -68,7 +68,9 @@ defmodule CadetWeb.AssessmentsView do end def render("leaderboard.json", %{leaderboard: leaderboard}) do - render_many(leaderboard, CadetWeb.AdminAssessmentsView, "contestEntry.json", as: :contestEntry) + render_many(leaderboard, CadetWeb.AdminAssessmentsView, "contestEntry.json", + as: :contestEntry + ) end def render("contestEntry.json", %{contestEntry: contestEntry}) do diff --git a/test/cadet_web/helpers/controller_helper_test.exs b/test/cadet_web/helpers/controller_helper_test.exs index e158aecaa..f8f430643 100644 --- a/test/cadet_web/helpers/controller_helper_test.exs +++ b/test/cadet_web/helpers/controller_helper_test.exs @@ -16,12 +16,14 @@ defmodule CadetWeb.ControllerHelperTest do assert_called(Conn.send_resp(:conn, :no_content, "")) end - test_with_mock "sends 204 with {:ok} and empty string", Conn, send_resp: fn _, _, _ -> nil end do + test_with_mock "sends 204 with {:ok} and empty string", Conn, + send_resp: fn _, _, _ -> nil end do handle_standard_result({:ok, nil}, :conn, "") assert_called(Conn.send_resp(:conn, :no_content, "")) end - test_with_mock "sends 204 with :ok and empty string", Conn, send_resp: fn _, _, _ -> nil end do + test_with_mock "sends 204 with :ok and empty string", Conn, + send_resp: fn _, _, _ -> nil end do handle_standard_result(:ok, :conn, "") assert_called(Conn.send_resp(:conn, :no_content, "")) end From a4723e29b10a6f40e7bc675c849a14e425775bcc Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Fri, 18 Apr 2025 02:53:09 +0800 Subject: [PATCH 06/17] Upgrade Elixir, Erlang versions in CI --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 47dfdc5ce..3c27c7962 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,8 +23,8 @@ jobs: env: MIX_ENV: test GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - ELIXIR_VERSION: 1.13.4 - OTP_VERSION: 25.3.2 + ELIXIR_VERSION: 1.18.3 + OTP_VERSION: 27.3.3 services: postgres: image: postgres:17.4 From 6ceb1b19c9307590f666d365af573c220b14085f Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Fri, 18 Apr 2025 02:56:56 +0800 Subject: [PATCH 07/17] Upgrade credo version to fix failing check --- mix.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mix.lock b/mix.lock index c7229a16a..560b408f1 100644 --- a/mix.lock +++ b/mix.lock @@ -17,7 +17,7 @@ "cowboy": {:hex, :cowboy, "2.13.0", "09d770dd5f6a22cc60c071f432cd7cb87776164527f205c5a6b0f24ff6b38990", [:make, :rebar3], [{:cowlib, ">= 2.14.0 and < 3.0.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, ">= 1.8.0 and < 3.0.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "e724d3a70995025d654c1992c7b11dbfea95205c047d86ff9bf1cda92ddc5614"}, "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"}, "cowlib": {:hex, :cowlib, "2.14.0", "623791c56c1cc9df54a71a9c55147a401549917f00a2e48a6ae12b812c586ced", [:make, :rebar3], [], "hexpm", "0af652d1550c8411c3b58eed7a035a7fb088c0b86aff6bc504b0bc3b7f791aa2"}, - "credo": {:hex, :credo, "1.7.1", "6e26bbcc9e22eefbff7e43188e69924e78818e2fe6282487d0703652bc20fd62", [:mix], [{:bunt, "~> 0.2.1", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "e9871c6095a4c0381c89b6aa98bc6260a8ba6addccf7f6a53da8849c748a58a2"}, + "credo": {:hex, :credo, "1.7.12", "9e3c20463de4b5f3f23721527fcaf16722ec815e70ff6c60b86412c695d426c1", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "8493d45c656c5427d9c729235b99d498bd133421f3e0a683e5c1b561471291e5"}, "crontab": {:hex, :crontab, "1.1.13", "3bad04f050b9f7f1c237809e42223999c150656a6b2afbbfef597d56df2144c5", [:mix], [{:ecto, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm", "d67441bec989640e3afb94e123f45a2bc42d76e02988c9613885dc3d01cf7085"}, "csv": {:hex, :csv, "3.2.2", "452f96414b39a176b7c390af6d8b78f15130dc6167fe3b836729131f515d843e", [:mix], [], "hexpm", "cbf256ff74a3fa01d9ec420d07b19c90d410ed9fe5b6d6e1bc7662edf35bc574"}, "db_connection": {:hex, :db_connection, "2.7.0", "b99faa9291bb09892c7da373bb82cba59aefa9b36300f6145c5f201c7adf48ec", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "dcf08f31b2701f857dfc787fbad78223d61a32204f217f15e881dd93e4bdd3ff"}, @@ -46,7 +46,7 @@ "expo": {:hex, :expo, "0.4.1", "1c61d18a5df197dfda38861673d392e642649a9cef7694d2f97a587b2cfb319b", [:mix], [], "hexpm", "2ff7ba7a798c8c543c12550fa0e2cbc81b95d4974c65855d8d15ba7b37a1ce47"}, "exvcr": {:hex, :exvcr, "0.16.0", "11579f43c88ae81f57c82ce4f09e3ebda4c40117c859ed39e61a653c3a0b4ff4", [:mix], [{:exjsx, "~> 4.0", [hex: :exjsx, repo: "hexpm", optional: false]}, {:finch, "~> 0.16", [hex: :finch, repo: "hexpm", optional: true]}, {:httpoison, "~> 1.0 or ~> 2.0", [hex: :httpoison, repo: "hexpm", optional: true]}, {:httpotion, "~> 3.1", [hex: :httpotion, repo: "hexpm", optional: true]}, {:ibrowse, "4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:meck, "~> 0.9", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm", "8f576af22369942f7a1482baff1f31e2f45983cf6fac45d49d2bd2e84b4d5be8"}, "faker": {:hex, :faker, "0.18.0", "943e479319a22ea4e8e39e8e076b81c02827d9302f3d32726c5bf82f430e6e14", [:mix], [], "hexpm", "bfbdd83958d78e2788e99ec9317c4816e651ad05e24cfd1196ce5db5b3e81797"}, - "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, + "file_system": {:hex, :file_system, "1.1.0", "08d232062284546c6c34426997dd7ef6ec9f8bbd090eb91780283c9016840e8f", [:mix], [], "hexpm", "bfcf81244f416871f2a2e15c1b515287faa5db9c6bcf290222206d120b3d43f6"}, "gen_smtp": {:hex, :gen_smtp, "1.2.0", "9cfc75c72a8821588b9b9fe947ae5ab2aed95a052b81237e0928633a13276fd3", [:rebar3], [{:ranch, ">= 1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "5ee0375680bca8f20c4d85f58c2894441443a743355430ff33a783fe03296779"}, "gen_stage": {:hex, :gen_stage, "1.2.1", "19d8b5e9a5996d813b8245338a28246307fd8b9c99d1237de199d21efc4c76a1", [:mix], [], "hexpm", "83e8be657fa05b992ffa6ac1e3af6d57aa50aace8f691fcf696ff02f8335b001"}, "gettext": {:hex, :gettext, "0.22.2", "6bfca374de34ecc913a28ba391ca184d88d77810a3e427afa8454a71a51341ac", [:mix], [{:expo, "~> 0.4.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "8a2d389673aea82d7eae387e6a2ccc12660610080ae7beb19452cfdc1ec30f60"}, From 5079f20288d97b017a8db4eab431c639e7a238e5 Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Fri, 18 Apr 2025 03:00:37 +0800 Subject: [PATCH 08/17] Fix exit status causing failing check --- .credo.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.credo.exs b/.credo.exs index 9828a7ad2..a3658e4fd 100644 --- a/.credo.exs +++ b/.credo.exs @@ -83,7 +83,7 @@ {Credo.Check.Readability.ModuleNames}, {Credo.Check.Readability.ParenthesesOnZeroArityDefs}, {Credo.Check.Readability.ParenthesesInCondition}, - {Credo.Check.Readability.PredicateFunctionNames}, + {Credo.Check.Readability.PredicateFunctionNames, exit_status: 0}, {Credo.Check.Readability.PreferImplicitTry}, {Credo.Check.Readability.RedundantBlankLines}, {Credo.Check.Readability.StringSigils}, From 0e7ab7dabe122e3776b445f9cb1022615fb841cb Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Fri, 18 Apr 2025 04:13:06 +0800 Subject: [PATCH 09/17] Fix changeset tests --- .../admin_controllers/admin_sourcecast_controller_test.exs | 2 +- .../admin_controllers/admin_stories_controller_test.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cadet_web/admin_controllers/admin_sourcecast_controller_test.exs b/test/cadet_web/admin_controllers/admin_sourcecast_controller_test.exs index b38657283..84000e85f 100644 --- a/test/cadet_web/admin_controllers/admin_sourcecast_controller_test.exs +++ b/test/cadet_web/admin_controllers/admin_sourcecast_controller_test.exs @@ -180,7 +180,7 @@ defmodule CadetWeb.AdminSourcecastControllerTest do conn = post(conn, build_url(course_id), %{"sourcecast" => %{}}) assert response(conn, 400) =~ - "audio can't be blank\nplaybackData can't be blank\ntitle can't be blank" + "title can't be blank\naudio can't be blank\nplaybackData can't be blank" end end diff --git a/test/cadet_web/admin_controllers/admin_stories_controller_test.exs b/test/cadet_web/admin_controllers/admin_stories_controller_test.exs index 700adb570..4af5102c8 100644 --- a/test/cadet_web/admin_controllers/admin_stories_controller_test.exs +++ b/test/cadet_web/admin_controllers/admin_stories_controller_test.exs @@ -122,7 +122,7 @@ defmodule CadetWeb.AdminStoriesControllerTest do conn = post(conn, build_url(course_id), %{"story" => %{}}) assert response(conn, 400) == - "close_at can't be blank\nfilenames can't be blank\nopen_at can't be blank\ntitle can't be blank" + "title can't be blank\nclose_at can't be blank\nopen_at can't be blank\nfilenames can't be blank" end end From a00b536ddb90735e220c2436bda47a8d963d24a6 Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Fri, 18 Apr 2025 04:24:30 +0800 Subject: [PATCH 10/17] Fix log tests --- test/cadet/jobs/log_test.exs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/cadet/jobs/log_test.exs b/test/cadet/jobs/log_test.exs index 8a7e67c89..7d859df83 100644 --- a/test/cadet/jobs/log_test.exs +++ b/test/cadet/jobs/log_test.exs @@ -20,7 +20,10 @@ defmodule Cadet.Jobs.LogEntryTest do test "returns true (job runs) when log entry old enough" do %LogEntry{ name: @name, - last_run: Timex.subtract(DateTime.truncate(Timex.now(), :second), Duration.from_hours(25)) + last_run: + Timex.now() + |> Timex.subtract(Duration.from_hours(25)) + |> DateTime.truncate(:second) } |> Repo.insert!() @@ -37,7 +40,10 @@ defmodule Cadet.Jobs.LogEntryTest do test "returns false (job does not run) when log entry too recent" do %LogEntry{ name: @name, - last_run: Timex.subtract(DateTime.truncate(Timex.now(), :second), Duration.from_hours(23)) + last_run: + Timex.now() + |> Timex.subtract(Duration.from_hours(23)) + |> DateTime.truncate(:second) } |> Repo.insert!() From 786579885ffbe8f0f6bb7d6d5af144868ecd9943 Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Fri, 18 Apr 2025 05:02:51 +0800 Subject: [PATCH 11/17] Fix dialyzer issues --- lib/cadet/assessments/assessments.ex | 13 ++----------- .../admin_controllers/admin_assets_controller.ex | 2 +- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/lib/cadet/assessments/assessments.ex b/lib/cadet/assessments/assessments.ex index 244ebc742..251c03dd8 100644 --- a/lib/cadet/assessments/assessments.ex +++ b/lib/cadet/assessments/assessments.ex @@ -941,7 +941,7 @@ defmodule Cadet.Assessments do raw_answer, force_submit ) do - with {:ok, team} <- find_team(question.assessment.id, cr_id), + with {:ok, _team} <- find_team(question.assessment.id, cr_id), {: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 @@ -2692,7 +2692,7 @@ defmodule Cadet.Assessments do def has_last_modified_answer?( question = %Question{}, - cr = %CourseRegistration{id: cr_id}, + cr = %CourseRegistration{id: _cr_id}, last_modified_at, force_submit ) do @@ -2703,15 +2703,6 @@ defmodule Cadet.Assessments do else {:status, _} -> {:error, {:forbidden, "Assessment submission already finalised"}} - - {:error, :race_condition} -> - {:error, {:internal_server_error, "Please try again later."}} - - {:error, :invalid_vote} -> - {:error, {:bad_request, "Invalid vote! Vote is not saved."}} - - _ -> - {:error, {:bad_request, "Missing or invalid parameter(s)"}} end end diff --git a/lib/cadet_web/admin_controllers/admin_assets_controller.ex b/lib/cadet_web/admin_controllers/admin_assets_controller.ex index 4f35b15d1..97d49600b 100644 --- a/lib/cadet_web/admin_controllers/admin_assets_controller.ex +++ b/lib/cadet_web/admin_controllers/admin_assets_controller.ex @@ -22,7 +22,7 @@ defmodule CadetWeb.AdminAssetsController do case Assets.delete_object(Courses.assets_prefix(course_reg.course), foldername, filename) do {:error, {status, message}} -> conn |> put_status(status) |> text(message) - _ -> conn |> put_status(204) |> text('') + _ -> conn |> put_status(204) |> text("") end end From cd58e808f9c59e64f2e7dcb1cbcfbab01ab4b030 Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Fri, 18 Apr 2025 15:11:17 +0800 Subject: [PATCH 12/17] Fix dependencies --- mix.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mix.lock b/mix.lock index 560b408f1..c5c155bdf 100644 --- a/mix.lock +++ b/mix.lock @@ -31,9 +31,9 @@ "erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"}, "esaml": {:hex, :esaml, "4.6.0", "8fb5a3a0d56ccfce3e081a2f72b29058511047a2abbafb64cb6f595bf7465124", [:rebar3], [{:cowboy, "< 3.0.0", [hex: :cowboy, repo: "hexpm", optional: false]}], "hexpm", "d34d0b259cd8ac8215fd2c333fac9dbbb91b5f5da5a9304508612ff3ac0afa7a"}, "ex2ms": {:hex, :ex2ms, "1.7.0", "45b9f523d0b777667ded60070d82d871a37e294f0b6c5b8eca86771f00f82ee1", [:mix], [], "hexpm", "2589eee51f81f1b1caa6d08c990b1ad409215fe6f64c73f73c67d36ed10be827"}, - "ex_aws": {:hex, :ex_aws, "2.5.8", "0393cfbc5e4a9e7017845451a015d836a670397100aa4c86901980e2a2c5f7d4", [: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", "8f79777b7932168956c8cc3a6db41f5783aa816eb50de356aed3165a71e5f8c3"}, + "ex_aws": {:hex, :ex_aws, "2.5.9", "8e2455172f0e5cbe2f56dd68de514f0dae6bb26d6b6e2f435a06434cf9dbb412", [: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.5.10 or ~> 0.6 or ~> 1.0", [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", "cbdb6ffb0e6c6368de05ed8641fe1376298ba23354674428e5b153a541f23359"}, "ex_aws_lambda": {:hex, :ex_aws_lambda, "2.1.0", "f28bffae6dde34ba17ef815ef50a82a1e7f3af26d36fe31dbda3a7657e0de449", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: false]}], "hexpm", "25608630b8b45fe22b0237696662f88be724bc89f77ee42708a5871511f531a0"}, - "ex_aws_s3": {:hex, :ex_aws_s3, "2.4.0", "ce8decb6b523381812798396bc0e3aaa62282e1b40520125d1f4eff4abdff0f4", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: false]}, {:sweet_xml, ">= 0.0.0", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm", "85dda6e27754d94582869d39cba3241d9ea60b6aa4167f9c88e309dc687e56bb"}, + "ex_aws_s3": {:hex, :ex_aws_s3, "2.5.7", "e571424d2f345299753382f3a01b005c422b1a460a8bc3ed47659b3d3ef91e9e", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: false]}, {:sweet_xml, ">= 0.0.0", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm", "858e51241e50181e29aa2bc128fef548873a3a9cd580471f57eda5b64dec937f"}, "ex_aws_secretsmanager": {:hex, :ex_aws_secretsmanager, "2.0.0", "deff8c12335f0160882afeb9687e55a97fddcd7d9a82fc3a6fbb270797374773", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: false]}], "hexpm", "8b2838af536c32263ff797012b29e87bad73ef34f43cfa60ebca8e84576f6d45"}, "ex_aws_sts": {:hex, :ex_aws_sts, "2.3.0", "ce48c4cba7f1595a7d544458d0202ca313124026dba7b1a0021bbb1baa3d66d0", [:mix], [{:ex_aws, "~> 2.2", [hex: :ex_aws, repo: "hexpm", optional: false]}], "hexpm", "f14e4c7da3454514bf253b331e9422d25825485c211896ab3b81d2a4bdbf62f5"}, "ex_json_schema": {:hex, :ex_json_schema, "0.7.4", "09eb5b0c8184e5702bc89625a9d0c05c7a0a845d382e9f6f406a0fc1c9a8cc3f", [:mix], [], "hexpm", "45c67fa840f0d719a2b5578126dc29bcdc1f92499c0f61bcb8a3bcb5935f9684"}, From d2bf00fc785f5e2499788134b1c189a881698578 Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Thu, 15 May 2025 00:25:50 +0800 Subject: [PATCH 13/17] Update CD workflow --- .github/workflows/cd.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index c41408193..0e8d69233 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -25,8 +25,8 @@ jobs: env: MIX_ENV: prod GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - ELIXIR_VERSION: 1.13.4 - OTP_VERSION: 25.3.2 + ELIXIR_VERSION: 1.18.3 + OTP_VERSION: 27.3.3 steps: - uses: rlespinasse/github-slug-action@v3.x - uses: actions/checkout@v4 From 1e068fe786b090d2272bffa84821d649a11b85fc Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Fri, 13 Jun 2025 18:43:54 +0800 Subject: [PATCH 14/17] Revert S3 dependency change --- mix.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.lock b/mix.lock index fc0529b68..64591ae8c 100644 --- a/mix.lock +++ b/mix.lock @@ -33,7 +33,7 @@ "ex2ms": {:hex, :ex2ms, "1.7.0", "45b9f523d0b777667ded60070d82d871a37e294f0b6c5b8eca86771f00f82ee1", [:mix], [], "hexpm", "2589eee51f81f1b1caa6d08c990b1ad409215fe6f64c73f73c67d36ed10be827"}, "ex_aws": {:hex, :ex_aws, "2.5.9", "8e2455172f0e5cbe2f56dd68de514f0dae6bb26d6b6e2f435a06434cf9dbb412", [: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.5.10 or ~> 0.6 or ~> 1.0", [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", "cbdb6ffb0e6c6368de05ed8641fe1376298ba23354674428e5b153a541f23359"}, "ex_aws_lambda": {:hex, :ex_aws_lambda, "2.1.0", "f28bffae6dde34ba17ef815ef50a82a1e7f3af26d36fe31dbda3a7657e0de449", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: false]}], "hexpm", "25608630b8b45fe22b0237696662f88be724bc89f77ee42708a5871511f531a0"}, - "ex_aws_s3": {:hex, :ex_aws_s3, "2.5.7", "e571424d2f345299753382f3a01b005c422b1a460a8bc3ed47659b3d3ef91e9e", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: false]}, {:sweet_xml, ">= 0.0.0", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm", "858e51241e50181e29aa2bc128fef548873a3a9cd580471f57eda5b64dec937f"}, + "ex_aws_s3": {:hex, :ex_aws_s3, "2.4.0", "ce8decb6b523381812798396bc0e3aaa62282e1b40520125d1f4eff4abdff0f4", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: false]}, {:sweet_xml, ">= 0.0.0", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm", "85dda6e27754d94582869d39cba3241d9ea60b6aa4167f9c88e309dc687e56bb"}, "ex_aws_secretsmanager": {:hex, :ex_aws_secretsmanager, "2.0.0", "deff8c12335f0160882afeb9687e55a97fddcd7d9a82fc3a6fbb270797374773", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: false]}], "hexpm", "8b2838af536c32263ff797012b29e87bad73ef34f43cfa60ebca8e84576f6d45"}, "ex_aws_sts": {:hex, :ex_aws_sts, "2.3.0", "ce48c4cba7f1595a7d544458d0202ca313124026dba7b1a0021bbb1baa3d66d0", [:mix], [{:ex_aws, "~> 2.2", [hex: :ex_aws, repo: "hexpm", optional: false]}], "hexpm", "f14e4c7da3454514bf253b331e9422d25825485c211896ab3b81d2a4bdbf62f5"}, "ex_json_schema": {:hex, :ex_json_schema, "0.7.4", "09eb5b0c8184e5702bc89625a9d0c05c7a0a845d382e9f6f406a0fc1c9a8cc3f", [:mix], [], "hexpm", "45c67fa840f0d719a2b5578126dc29bcdc1f92499c0f61bcb8a3bcb5935f9684"}, From 374c3ada33e4d30310561e04ddecb3170a1b84ef Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Fri, 13 Jun 2025 19:18:22 +0800 Subject: [PATCH 15/17] Fix more dialyzer issues --- lib/cadet_web/admin_controllers/admin_assets_controller.ex | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/cadet_web/admin_controllers/admin_assets_controller.ex b/lib/cadet_web/admin_controllers/admin_assets_controller.ex index 97d49600b..0c92cef03 100644 --- a/lib/cadet_web/admin_controllers/admin_assets_controller.ex +++ b/lib/cadet_web/admin_controllers/admin_assets_controller.ex @@ -41,7 +41,6 @@ defmodule CadetWeb.AdminAssetsController do filename ) do {:error, {status, message}} -> conn |> put_status(status) |> text(message) - resp -> render(conn, "show.json", resp: resp) end end From d7cff856c38c4dd7c65a2d44387834265f2d6208 Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Fri, 13 Jun 2025 19:28:18 +0800 Subject: [PATCH 16/17] Revert "Fix more dialyzer issues" This reverts commit 374c3ada33e4d30310561e04ddecb3170a1b84ef. --- lib/cadet_web/admin_controllers/admin_assets_controller.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/cadet_web/admin_controllers/admin_assets_controller.ex b/lib/cadet_web/admin_controllers/admin_assets_controller.ex index 0c92cef03..97d49600b 100644 --- a/lib/cadet_web/admin_controllers/admin_assets_controller.ex +++ b/lib/cadet_web/admin_controllers/admin_assets_controller.ex @@ -41,6 +41,7 @@ defmodule CadetWeb.AdminAssetsController do filename ) do {:error, {status, message}} -> conn |> put_status(status) |> text(message) + resp -> render(conn, "show.json", resp: resp) end end From 86c60eeb110447075139d01836f2f0f71343318e Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Fri, 13 Jun 2025 19:59:16 +0800 Subject: [PATCH 17/17] Fix dialyzer warning properly --- lib/cadet_web/admin_controllers/admin_assets_controller.ex | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/cadet_web/admin_controllers/admin_assets_controller.ex b/lib/cadet_web/admin_controllers/admin_assets_controller.ex index 97d49600b..4ff25d0bd 100644 --- a/lib/cadet_web/admin_controllers/admin_assets_controller.ex +++ b/lib/cadet_web/admin_controllers/admin_assets_controller.ex @@ -26,6 +26,11 @@ defmodule CadetWeb.AdminAssetsController do end end + # Ignore the dialyzer warning, just ctrl click the + # `Assets.upload_to_s3` function to see the type, + # it clearly returns a string URL + @dialyzer {:no_match, upload: 2} + def upload(conn, %{ "upload" => upload_params, "filename" => filename,