Skip to content
Open
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
6 changes: 6 additions & 0 deletions app/api/entities/task_definition_entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def staff?(my_role)
expose :tutorial_stream_abbr do |task_definition, options|
task_definition.tutorial_stream.abbreviation unless task_definition.tutorial_stream.nil?
end
expose :tutorial_self_enrolment_stream_abbr, expose_nil: true do |task_definition, options|
task_definition.tutorial_self_enrolment_stream.abbreviation unless task_definition.tutorial_self_enrolment_stream.nil?
end
expose :plagiarism_warn_pct, if: ->(unit, options) { staff?(options[:my_role]) }
expose :restrict_status_updates, if: ->(unit, options) { staff?(options[:my_role]) }
expose :group_set_id, expose_nil: false
Expand All @@ -45,6 +48,9 @@ def staff?(my_role)
expose :scorm_bypass_test
expose :scorm_time_delay_enabled
expose :scorm_attempt_limit
expose :tutorial_self_enrolment_enabled
expose :tutorial_self_enrolment_stream_id
expose :scorm_attempt_limit

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line I noticed to be redundant as it is already written on line 50

expose :is_graded
expose :max_quality_pts
expose :overseer_image_id, if: ->(unit, options) { staff?(options[:my_role]) }, expose_nil: false
Expand Down
22 changes: 22 additions & 0 deletions app/api/task_definitions_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class TaskDefinitionsApi < Grape::API
optional :scorm_bypass_test, type: Boolean, desc: 'Whether a student is allowed to upload files before passing SCORM test'
optional :scorm_time_delay_enabled, type: Boolean, desc: 'Whether there is an incremental time delay between SCORM test attempts'
optional :scorm_attempt_limit, type: Integer, desc: 'The number of times a SCORM test can be attempted'
optional :tutorial_self_enrolment_enabled, type: Boolean, desc: 'Whether the tutorial self enrolment feature is enabled for this task'
optional :tutorial_self_enrolment_stream_abbr, type: String, desc: 'The abbreviation of tutorial stream to fetch from for self enrolment'
end
end
post '/units/:unit_id/task_definitions/' do
Expand Down Expand Up @@ -65,6 +67,7 @@ class TaskDefinitionsApi < Grape::API
:scorm_bypass_test,
:scorm_time_delay_enabled,
:scorm_attempt_limit,
:tutorial_self_enrolment_enabled,
:is_graded,
:max_quality_pts,
:assessment_enabled,
Expand All @@ -86,6 +89,14 @@ class TaskDefinitionsApi < Grape::API
task_def.tutorial_stream = tutorial_stream
end

# Set the self enrolment tutorial stream
tutorial_self_enrolment_stream_abbr = params[:task_def][:tutorial_self_enrolment_stream_abbr]
unless tutorial_self_enrolment_stream_abbr.nil?
tutorial_self_enrolment_stream = task_def.unit.tutorial_streams.find_by!(abbreviation: tutorial_self_enrolment_stream_abbr)
task_def.tutorial_self_enrolment_stream = tutorial_self_enrolment_stream
task_def.save!
end

#
# Link in group set if specified
#
Expand Down Expand Up @@ -126,6 +137,8 @@ class TaskDefinitionsApi < Grape::API
optional :assessment_enabled, type: Boolean, desc: 'Enable or disable assessment'
optional :overseer_image_id, type: Integer, desc: 'The id of the Docker image name for overseer'
optional :moss_language, type: String, desc: 'The language to use for code similarity checks'
optional :tutorial_self_enrolment_enabled, type: Boolean, desc: 'Whether the tutorial self enrolment feature is enabled for this task'
optional :tutorial_self_enrolment_stream_abbr, type: String, desc: 'The abbreviation of tutorial stream to fetch from for self enrolment'
end
end
put '/units/:unit_id/task_definitions/:id' do
Expand Down Expand Up @@ -154,6 +167,7 @@ class TaskDefinitionsApi < Grape::API
:scorm_bypass_test,
:scorm_time_delay_enabled,
:scorm_attempt_limit,
:tutorial_self_enrolment_enabled,
:is_graded,
:max_quality_pts,
:assessment_enabled,
Expand Down Expand Up @@ -189,6 +203,14 @@ class TaskDefinitionsApi < Grape::API
task_def.save!
end

# Set the self enrolment tutorial stream
tutorial_self_enrolment_stream_abbr = params[:task_def][:tutorial_self_enrolment_stream_abbr]
unless tutorial_self_enrolment_stream_abbr.nil?
tutorial_self_enrolment_stream = task_def.unit.tutorial_streams.find_by!(abbreviation: tutorial_self_enrolment_stream_abbr)
task_def.tutorial_self_enrolment_stream = tutorial_self_enrolment_stream
task_def.save!
end

#
# Link in group set if specified
#
Expand Down
5 changes: 5 additions & 0 deletions app/models/task_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class TaskDefinition < ApplicationRecord
belongs_to :unit, optional: false # Foreign key
belongs_to :group_set, optional: true
belongs_to :tutorial_stream, optional: true
belongs_to :tutorial_self_enrolment_stream, class_name: "TutorialStream", optional: true
belongs_to :overseer_image, optional: true

has_many :tasks, dependent: :destroy # Destroying a task definition will also nuke any instances
Expand Down Expand Up @@ -449,6 +450,10 @@ def scorm_attempt_limit?
scorm_attempt_limit
end

def tutorial_self_enrolment_enabled?
tutorial_self_enrolment_enabled
end

def is_graded?
is_graded
end
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20250506044920_tutorial_self_enrolment_feature.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class TutorialSelfEnrolmentFeature < ActiveRecord::Migration[7.1]
def change
add_column :task_definitions, :tutorial_self_enrolment_enabled, :boolean, default: false
add_reference :task_definitions, :tutorial_self_enrolment_stream, foreign_key: { to_table: :tutorial_streams }
end
end
6 changes: 5 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_12_17_091744) do
ActiveRecord::Schema[7.1].define(version: 2025_05_06_044920) do
create_table "activity_types", charset: "utf8", collation: "utf8_unicode_ci", force: :cascade do |t|
t.string "name", null: false
t.string "abbreviation", null: false
Expand Down Expand Up @@ -272,10 +272,13 @@
t.boolean "scorm_bypass_test", default: false
t.boolean "scorm_time_delay_enabled", default: false
t.integer "scorm_attempt_limit", default: 0
t.boolean "tutorial_self_enrolment_enabled", default: false
t.bigint "tutorial_self_enrolment_stream_id"
t.index ["abbreviation", "unit_id"], name: "index_task_definitions_on_abbreviation_and_unit_id", unique: true
t.index ["group_set_id"], name: "index_task_definitions_on_group_set_id"
t.index ["name", "unit_id"], name: "index_task_definitions_on_name_and_unit_id", unique: true
t.index ["overseer_image_id"], name: "index_task_definitions_on_overseer_image_id"
t.index ["tutorial_self_enrolment_stream_id"], name: "index_task_definitions_on_tutorial_self_enrolment_stream_id"
t.index ["tutorial_stream_id"], name: "index_task_definitions_on_tutorial_stream_id"
t.index ["unit_id"], name: "index_task_definitions_on_unit_id"
end
Expand Down Expand Up @@ -591,6 +594,7 @@
t.index ["user_id"], name: "index_webcals_on_user_id", unique: true
end

add_foreign_key "task_definitions", "tutorial_streams", column: "tutorial_self_enrolment_stream_id"
add_foreign_key "user_oauth_states", "users"
add_foreign_key "user_oauth_tokens", "users"
end