• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

source-academy / backend / ad975fd01013a530bdf20eb6afc4fb564b4c7a99

01 Aug 2026 04:43AM UTC coverage: 87.459% (+0.01%) from 87.445%
ad975fd01013a530bdf20eb6afc4fb564b4c7a99

push

github

web-flow
Upgrade most dependencies and modernize codebase (#1363)

* Initial implementation for upgrading most dependencies

* Fix format

* Fix credo raw value pipe chain

* Fix more credo issues

* Fix dialyzer issues

* Fix tests

* Fix bugs as identified by Codex

* Fix credo issues

* Fix invalid migration

* Fix dialyzer

* Read CORS origins from config at compile time

Remove the dead `Code.ensure_loaded?(__MODULE__)` guard, which always
evaluated to false during the endpoint's own compilation and forced
`origins` to "*". Read the config directly with compile_env.

Addresses PR review comments.

* Use :day/:hour units in DateTime.add calls

DateTime.add/4 supports :day and :hour units directly (Elixir >= 1.14),
so drop the manual second multiplications for readability.

Addresses PR review comments.

* Remove unused variables and redundant computation

- teams.ex: drop the unused unique-id count (pure computation, no effect)
- ai_comments_helpers.ex: return the encrypted string directly
- generate_ai_comments.ex: drop the unused api-key parameter and its caller arg

Addresses PR review comments.

* Report failed autograder jobs as failures to Oban

handle_failure/4 returned :ok, which made Oban mark the job as completed
even though the Lambda invocation failed. Return {:error, message} so the
job is recorded as discarded (max_attempts: 1) and stays visible in Oban
telemetry. The failed result is still enqueued beforehand, so the answer
is updated as before.

Addresses PR review comments.

* Verify course ownership for contest score/XP endpoints

calculate_contest_score/2 and dispatch_contest_xp/2 looked up the voting
question by assessment id only, ignoring the course id in the path. A staff
member of one course could therefore trigger score calculation or XP
dispatch on another course's assessment. Guard both with the existing
is_same_course/2 check (returning 403 on mismatch), matching delete/2, and
extract the shared lookup into a helper.

Addresses ... (continued)

81 of 103 new or added lines in 17 files covered. (78.64%)

5 existing lines in 4 files now uncovered.

3996 of 4569 relevant lines covered (87.46%)

6891.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lib/cadet/code_exchange.ex
1
defmodule Cadet.TokenExchange do
2
  @moduledoc """
3
  The TokenExchange entity stores short-lived codes to be exchanged for long-lived auth tokens.
4
  """
5
  use Cadet, :model
6

7
  import Ecto.Query
8

9
  alias Cadet.Repo
10
  alias Cadet.Accounts.User
11

12
  @primary_key {:code, :string, []}
13
  schema "token_exchange" do
×
14
    field(:generated_at, :utc_datetime_usec)
15
    field(:expires_at, :utc_datetime_usec)
16

17
    belongs_to(:user, User)
18

19
    timestamps()
20
  end
21

22
  @required_fields ~w(code generated_at expires_at user_id)a
23

24
  def get_by_code(code) do
25
    case Repo.get_by(__MODULE__, code: code) do
×
26
      nil ->
×
27
        {:error, "Not found"}
28

29
      struct ->
NEW
30
        if DateTime.compare(struct.expires_at, DateTime.utc_now()) == :lt do
×
31
          {:error, "Expired"}
32
        else
33
          struct = Repo.preload(struct, :user)
×
34
          Repo.delete(struct)
×
35
          {:ok, struct}
36
        end
37
    end
38
  end
39

40
  def delete_expired do
NEW
41
    now = DateTime.utc_now()
×
42

43
    Repo.delete_all(from(c in __MODULE__, where: c.expires_at < ^now))
×
44
  end
45

46
  def changeset(struct, attrs) do
47
    struct
48
    |> cast(attrs, @required_fields)
49
    |> validate_required(@required_fields)
×
50
  end
51

52
  def insert(attrs) do
53
    changeset =
×
54
      %__MODULE__{}
55
      |> changeset(attrs)
56

57
    changeset
58
    |> Repo.insert()
×
59
  end
60
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc