Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
env:
MIX_ENV: prod
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ELIXIR_VERSION: '1.12.3'
OTP_VERSION: '24.0.6'
ELIXIR_VERSION: '1.13.2'
OTP_VERSION: '24.2'
steps:
- uses: rlespinasse/github-slug-action@v3.x
- uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jobs:
env:
MIX_ENV: test
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ELIXIR_VERSION: '1.12.3'
OTP_VERSION: '24.0.6'
ELIXIR_VERSION: '1.13.2'
OTP_VERSION: '24.2'
services:
postgres:
image: postgres:13.1
Expand Down
9 changes: 9 additions & 0 deletions lib/cadet/accounts/course_registration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ defmodule Cadet.Accounts.CourseRegistration do
alias Cadet.Accounts.{Role, User}
alias Cadet.Courses.{Course, Group}

@type t :: %__MODULE__{
role: Role.t(),
game_states: %{},
agreed_to_research: boolean(),
group: Group.t() | nil,
user: User.t() | nil,
course: Course.t() | nil
}

schema "course_registrations" do
field(:role, Role)
field(:game_states, :map)
Expand Down
10 changes: 5 additions & 5 deletions lib/cadet/accounts/notifications.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule Cadet.Accounts.Notifications do
@doc """
Fetches all unread notifications belonging to a course_reg as an array
"""
@spec fetch(%CourseRegistration{}) :: {:ok, {:array, Notification}}
@spec fetch(CourseRegistration.t()) :: {:ok, {:array, Notification}}
def fetch(course_reg = %CourseRegistration{}) do
notifications =
Notification
Expand Down Expand Up @@ -101,7 +101,7 @@ defmodule Cadet.Accounts.Notifications do
@doc """
Changes read status of notification(s) from false to true.
"""
@spec acknowledge({:array, :integer}, %CourseRegistration{}) ::
@spec acknowledge({:array, :integer}, CourseRegistration.t()) ::
{:ok, Ecto.Schema.t()}
| {:error, any}
| {:error, Ecto.Multi.name(), any, %{Ecto.Multi.name() => any}}
Expand All @@ -123,7 +123,7 @@ defmodule Cadet.Accounts.Notifications do
|> Repo.transaction()
end

@spec acknowledge(:integer, %CourseRegistration{}) :: {:ok, Ecto.Schema.t()} | {:error, any()}
@spec acknowledge(:integer, CourseRegistration.t()) :: {:ok, Ecto.Schema.t()} | {:error, any()}
def acknowledge(notification_id, course_reg = %CourseRegistration{}) do
notification = Repo.get_by(Notification, id: notification_id, course_reg_id: course_reg.id)

Expand All @@ -141,7 +141,7 @@ defmodule Cadet.Accounts.Notifications do
@doc """
Function that handles notifications when a submission is unsubmitted.
"""
@spec handle_unsubmit_notifications(integer(), %CourseRegistration{}) ::
@spec handle_unsubmit_notifications(integer(), CourseRegistration.t()) ::
{:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
def handle_unsubmit_notifications(assessment_id, student = %CourseRegistration{})
when is_ecto_id(assessment_id) do
Expand Down Expand Up @@ -220,7 +220,7 @@ defmodule Cadet.Accounts.Notifications do
When a student has finalized a submission, writes a notification to the corresponding
grader (Avenger) in charge of the student.
"""
@spec write_notification_when_student_submits(%Submission{}) ::
@spec write_notification_when_student_submits(Submission.t()) ::
{:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
def write_notification_when_student_submits(submission = %Submission{}) do
avenger_id = get_avenger_id_of(submission.student_id)
Expand Down
2 changes: 1 addition & 1 deletion lib/cadet/accounts/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule Cadet.Accounts.Query do
|> preload(:latest_viewed_course)
end

@spec students_of(%CourseRegistration{}) :: Ecto.Query.t()
@spec students_of(CourseRegistration.t()) :: Ecto.Query.t()
def students_of(course_reg = %CourseRegistration{course_id: course_id}) do
# Note that staff role is not check here as we assume that
# group leader is assign to a staff validated by group changeset
Expand Down
7 changes: 7 additions & 0 deletions lib/cadet/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ defmodule Cadet.Accounts.User do
alias Cadet.Accounts.CourseRegistration
alias Cadet.Courses.Course

@type t :: %__MODULE__{
name: String.t(),
username: String.t(),
provider: String.t(),
latest_viewed_course: Course.t()
}

schema "users" do
field(:name, :string)
field(:username, :string)
Expand Down
2 changes: 2 additions & 0 deletions lib/cadet/assessments/answer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ defmodule Cadet.Assessments.Answer do
alias Cadet.Assessments.AnswerTypes.{MCQAnswer, ProgrammingAnswer, VotingAnswer}
alias Cadet.Assessments.{Question, QuestionType, Submission}

@type t :: %__MODULE__{}

schema "answers" do
# used to compare answers with others
field(:relative_score, :float, default: 0.0)
Expand Down
2 changes: 2 additions & 0 deletions lib/cadet/assessments/assessment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ defmodule Cadet.Assessments.Assessment do
alias Cadet.Assessments.{AssessmentAccess, Question, SubmissionStatus, Upload}
alias Cadet.Courses.{Course, AssessmentConfig}

@type t :: %__MODULE__{}

schema "assessments" do
field(:access, AssessmentAccess, virtual: true, default: :public)
field(:max_xp, :integer, virtual: true)
Expand Down
20 changes: 10 additions & 10 deletions lib/cadet/assessments/assessments.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ defmodule Cadet.Assessments do
Repo.delete_all(submissions)
end

@spec user_max_xp(%CourseRegistration{}) :: integer()
@spec user_max_xp(CourseRegistration.t()) :: integer()
def user_max_xp(%CourseRegistration{id: cr_id}) do
Submission
|> where(status: ^:submitted)
Expand Down Expand Up @@ -127,7 +127,7 @@ defmodule Cadet.Assessments do
story
end

@spec get_user_story_by_type(%CourseRegistration{}, :unattempted | :attempted) ::
@spec get_user_story_by_type(CourseRegistration.t(), :unattempted | :attempted) ::
String.t() | nil
def get_user_story_by_type(%CourseRegistration{id: cr_id}, type)
when is_atom(type) do
Expand Down Expand Up @@ -812,8 +812,8 @@ defmodule Cadet.Assessments do
end
end

@spec update_submission_status_and_xp_bonus(%Submission{}) ::
{:ok, %Submission{}} | {:error, Ecto.Changeset.t()}
@spec update_submission_status_and_xp_bonus(Submission.t()) ::
{:ok, Submission.t()} | {:error, Ecto.Changeset.t()}
defp update_submission_status_and_xp_bonus(submission = %Submission{}) do
assessment = submission.assessment
assessment_conifg = Repo.get_by(AssessmentConfig, id: assessment.config_id)
Expand Down Expand Up @@ -1118,7 +1118,7 @@ defmodule Cadet.Assessments do
The return value is {:ok, submissions} if no errors, else it is {:error,
{:unauthorized, "Forbidden."}}
"""
@spec all_submissions_by_grader_for_index(%CourseRegistration{}) ::
@spec all_submissions_by_grader_for_index(CourseRegistration.t()) ::
{:ok, String.t()}
def all_submissions_by_grader_for_index(
grader = %CourseRegistration{course_id: course_id},
Expand Down Expand Up @@ -1221,7 +1221,7 @@ defmodule Cadet.Assessments do
end

@spec get_answers_in_submission(integer() | String.t()) ::
{:ok, [%Answer{}]} | {:error, {:bad_request | :unauthorized, String.t()}}
{:ok, [Answer.t()]} | {:error, {:bad_request | :unauthorized, String.t()}}
def get_answers_in_submission(id) when is_ecto_id(id) do
answer_query =
Answer
Expand Down Expand Up @@ -1286,7 +1286,7 @@ defmodule Cadet.Assessments do
@spec update_grading_info(
%{submission_id: integer() | String.t(), question_id: integer() | String.t()},
%{},
%CourseRegistration{}
CourseRegistration.t()
) ::
{:ok, nil}
| {:error, {:unauthorized | :bad_request | :internal_server_error, String.t()}}
Expand Down Expand Up @@ -1347,7 +1347,7 @@ defmodule Cadet.Assessments do
{:error, {:unauthorized, "User is not permitted to grade."}}
end

@spec force_regrade_submission(integer() | String.t(), %CourseRegistration{}) ::
@spec force_regrade_submission(integer() | String.t(), CourseRegistration.t()) ::
{:ok, nil} | {:error, {:forbidden | :not_found, String.t()}}
def force_regrade_submission(
submission_id,
Expand All @@ -1374,7 +1374,7 @@ defmodule Cadet.Assessments do
@spec force_regrade_answer(
integer() | String.t(),
integer() | String.t(),
%CourseRegistration{}
CourseRegistration.t()
) ::
{:ok, nil} | {:error, {:forbidden | :not_found, String.t()}}
def force_regrade_answer(
Expand Down Expand Up @@ -1423,7 +1423,7 @@ defmodule Cadet.Assessments do
end

# Checks if an assessment is open and published.
@spec is_open?(%Assessment{}) :: boolean()
@spec is_open?(Assessment.t()) :: boolean()
def is_open?(%Assessment{open_at: open_at, close_at: close_at, is_published: is_published}) do
Timex.between?(Timex.now(), open_at, close_at, inclusive: :start) and is_published
end
Expand Down
2 changes: 2 additions & 0 deletions lib/cadet/assessments/question.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ defmodule Cadet.Assessments.Question do
alias Cadet.Assessments.{Assessment, Library, QuestionType}
alias Cadet.Assessments.QuestionTypes.{MCQQuestion, ProgrammingQuestion, VotingQuestion}

@type t :: %__MODULE__{}

schema "questions" do
field(:display_order, :integer)
field(:question, :map)
Expand Down
2 changes: 2 additions & 0 deletions lib/cadet/assessments/submission.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ defmodule Cadet.Assessments.Submission do
alias Cadet.Accounts.CourseRegistration
alias Cadet.Assessments.{Answer, Assessment, SubmissionStatus}

@type t :: %__MODULE__{}

schema "submissions" do
field(:xp, :integer, virtual: true)
field(:xp_adjustment, :integer, virtual: true)
Expand Down
13 changes: 13 additions & 0 deletions lib/cadet/courses/course.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ defmodule Cadet.Courses.Course do

alias Cadet.Courses.AssessmentConfig

@type t :: %__MODULE__{
course_name: String.t(),
course_short_name: String.t(),
viewable: boolean(),
enable_game: boolean(),
enable_achievements: boolean(),
enable_sourcecast: boolean(),
source_chapter: integer(),
source_variant: String.t(),
module_help_text: String.t(),
assets_prefix: String.t() | nil
}

schema "courses" do
field(:course_name, :string)
field(:course_short_name, :string)
Expand Down
8 changes: 4 additions & 4 deletions lib/cadet/courses/courses.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ defmodule Cadet.Courses do
Returns the course configuration for the specified course.
"""
@spec get_course_config(integer) ::
{:ok, %Course{}} | {:error, {:bad_request, String.t()}}
{:ok, Course.t()} | {:error, {:bad_request, String.t()}}
def get_course_config(course_id) when is_ecto_id(course_id) do
case retrieve_course(course_id) do
nil ->
Expand All @@ -65,7 +65,7 @@ defmodule Cadet.Courses do
Updates the general course configuration for the specified course
"""
@spec update_course_config(integer, %{}) ::
{:ok, %Course{}} | {:error, Ecto.Changeset.t()} | {:error, {:bad_request, String.t()}}
{:ok, Course.t()} | {:error, Ecto.Changeset.t()} | {:error, {:bad_request, String.t()}}
def update_course_config(course_id, params) when is_ecto_id(course_id) do
case retrieve_course(course_id) do
nil ->
Expand Down Expand Up @@ -299,7 +299,7 @@ defmodule Cadet.Courses do
Get a group based on the group name and course id or create one if it doesn't exist
"""
@spec get_or_create_group(String.t(), integer()) ::
{:ok, %Group{}} | {:error, Ecto.Changeset.t()}
{:ok, Group.t()} | {:error, Ecto.Changeset.t()}
def get_or_create_group(name, course_id) when is_binary(name) and is_ecto_id(course_id) do
Group
|> where(name: ^name)
Expand Down Expand Up @@ -406,7 +406,7 @@ defmodule Cadet.Courses do
# |> Repo.preload(:uploader)
# end

@spec assets_prefix(%Course{}) :: binary()
@spec assets_prefix(Course.t()) :: binary()
def assets_prefix(course) do
course.assets_prefix || "#{Assets.assets_prefix()}#{course.id}/"
end
Expand Down
6 changes: 6 additions & 0 deletions lib/cadet/courses/group.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ defmodule Cadet.Courses.Group do
alias Cadet.Accounts.CourseRegistration
alias Cadet.Courses.Course

@type t :: %__MODULE__{
name: String.t(),
leader: CourseRegistration.t() | nil,
course: Course.t() | nil
}

schema "groups" do
field(:name, :string)
belongs_to(:leader, CourseRegistration)
Expand Down
2 changes: 2 additions & 0 deletions lib/cadet/devices/device.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ defmodule Cadet.Devices.Device do

use Cadet, :model

@type t :: %__MODULE__{}

schema "devices" do
field(:secret, :string)
field(:type, :string)
Expand Down
2 changes: 2 additions & 0 deletions lib/cadet/devices/device_registration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ defmodule Cadet.Devices.DeviceRegistration do
alias Cadet.Accounts.User
alias Cadet.Devices.Device

@type t :: %__MODULE__{}

schema "device_registrations" do
field(:title, :string)

Expand Down
26 changes: 13 additions & 13 deletions lib/cadet/devices/devices.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule Cadet.Devices do
alias Cadet.Devices.{Device, DeviceRegistration}
alias ExAws.STS

@spec get_user_registrations(integer | String.t() | %User{}) :: [%DeviceRegistration{}]
@spec get_user_registrations(integer | String.t() | User.t()) :: [DeviceRegistration.t()]
def get_user_registrations(%User{id: user_id}) do
get_user_registrations(user_id)
end
Expand All @@ -23,8 +23,8 @@ defmodule Cadet.Devices do
|> Repo.all()
end

@spec get_user_registration(integer | String.t() | %User{}, integer | String.t()) ::
%DeviceRegistration{} | nil
@spec get_user_registration(integer | String.t() | User.t(), integer | String.t()) ::
DeviceRegistration.t() | nil
def get_user_registration(%User{id: user_id}, id) do
get_user_registration(user_id, id)
end
Expand All @@ -37,20 +37,20 @@ defmodule Cadet.Devices do
|> Repo.get(id)
end

@spec delete_registration(%DeviceRegistration{}) :: {:ok, %DeviceRegistration{}}
@spec delete_registration(DeviceRegistration.t()) :: {:ok, DeviceRegistration.t()}
def delete_registration(registration = %DeviceRegistration{}) do
Repo.delete(registration)
end

@spec rename_registration(%DeviceRegistration{}, String.t()) ::
{:ok, %DeviceRegistration{}} | {:error, Ecto.Changeset.t()}
@spec rename_registration(DeviceRegistration.t(), String.t()) ::
{:ok, DeviceRegistration.t()} | {:error, Ecto.Changeset.t()}
def rename_registration(registration = %DeviceRegistration{}, title) do
registration
|> DeviceRegistration.changeset(%{title: title})
|> Repo.update()
end

@spec get_device(binary | integer) :: %Device{} | nil
@spec get_device(binary | integer) :: Device.t() | nil
def get_device(device_id) when is_integer(device_id) do
Repo.get(Device, device_id)
end
Expand All @@ -61,8 +61,8 @@ defmodule Cadet.Devices do
|> Repo.one()
end

@spec register(binary, binary, binary, integer | %User{}) ::
{:ok, %DeviceRegistration{}} | {:error, Ecto.Changeset.t() | :conflicting_device}
@spec register(binary, binary, binary, integer | User.t()) ::
{:ok, DeviceRegistration.t()} | {:error, Ecto.Changeset.t() | :conflicting_device}
def register(title, type, secret, %User{id: user_id}) do
register(title, type, secret, user_id)
end
Expand All @@ -78,7 +78,7 @@ defmodule Cadet.Devices do
end
end

@spec get_device_key_cert(binary | integer | %Device{}) ::
@spec get_device_key_cert(binary | integer | Device.t()) ::
{:ok, {String.t(), String.t()}}
| {:error,
:no_such_device
Expand Down Expand Up @@ -108,7 +108,7 @@ defmodule Cadet.Devices do
end

@spec maybe_insert_device(binary, binary) ::
{:ok, %Device{}} | {:error, Ecto.Changeset.t() | :conflicting_device}
{:ok, Device.t()} | {:error, Ecto.Changeset.t() | :conflicting_device}
defp maybe_insert_device(type, secret) do
case get_device(secret) do
device = %Device{} ->
Expand Down Expand Up @@ -167,8 +167,8 @@ defmodule Cadet.Devices do
end

@spec get_device_ws_endpoint(
binary | integer | %Device{},
%User{},
binary | integer | Device.t(),
User.t(),
[{:datetime, :calendar.datetime()}]
) ::
{:ok, %{}}
Expand Down
Loading