diff --git a/app/models/test_attempt.rb b/app/models/test_attempt.rb new file mode 100644 index 000000000..9391144b1 --- /dev/null +++ b/app/models/test_attempt.rb @@ -0,0 +1,36 @@ +class TestAttempt < ApplicationRecord + include ApplicationHelper + include LogHelper + include GradeHelper + + belongs_to :task + + def self.permissions + student_role_permissions = [ + :create, + :view_own, + :delete_own + ] + + tutor_role_permissions = [ + :create, + :view_own, + :delete_own + ] + + convenor_role_permissions = [ + :create, + :view_own, + :delete_own + ] + + nil_role_permissions = [] + + { + student: student_role_permissions, + tutor: tutor_role_permissions, + convenor: convenor_role_permissions, + nil: nil_role_permissions + } + end +end diff --git a/db/migrate/20231205011842_create_test_attempts.rb b/db/migrate/20231205011842_create_test_attempts.rb new file mode 100644 index 000000000..3828d1154 --- /dev/null +++ b/db/migrate/20231205011842_create_test_attempts.rb @@ -0,0 +1,16 @@ +class CreateTestAttempts < ActiveRecord::Migration[7.0] + def change + create_table :test_attempts do |t| + t.references :task, foreign_key: true + t.string :name + t.integer :attempt_number, default: 1, null: false + t.boolean :pass_status + t.text :exam_data + t.boolean :completed, default: false + t.datetime :attempted_at + t.string :cmi_entry, default: "ab-initio" + t.string :exam_result + t.timestamps + end + end +end diff --git a/db/migrate/20231205011958_add_fields_to_task_def.rb b/db/migrate/20231205011958_add_fields_to_task_def.rb new file mode 100644 index 000000000..35d9bb7cc --- /dev/null +++ b/db/migrate/20231205011958_add_fields_to_task_def.rb @@ -0,0 +1,19 @@ +class AddFieldsToTaskDef < ActiveRecord::Migration[7.0] + def change + change_table :task_definitions do |t| + t.boolean :has_test, default: false + t.boolean :restrict_attempts, default: false + t.integer :delay_restart_minutes + t.boolean :retake_on_resubmit, default: false + end + end + + def down + change_table :task_definitions do |t| + t.remove :has_test + t.remove :restrict_attempts + t.remove :delay_restart_minutes + t.remove :retake_on_resubmit + end + end +end diff --git a/db/schema.rb b/db/schema.rb index e0f7698c6..c9520e0c4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_12_01_000245) do +ActiveRecord::Schema[7.0].define(version: 2023_12_05_011958) 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 @@ -251,6 +251,10 @@ t.bigint "overseer_image_id" t.string "tii_group_id" t.string "moss_language" + t.boolean "has_test", default: false + t.boolean "restrict_attempts", default: false + t.integer "delay_restart_minutes" + t.boolean "retake_on_resubmit", default: false t.index ["group_set_id"], name: "index_task_definitions_on_group_set_id" t.index ["overseer_image_id"], name: "index_task_definitions_on_overseer_image_id" t.index ["tutorial_stream_id"], name: "index_task_definitions_on_tutorial_stream_id" @@ -347,6 +351,21 @@ t.index ["period", "year"], name: "index_teaching_periods_on_period_and_year", unique: true end + create_table "test_attempts", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| + t.bigint "task_id" + t.string "name" + t.integer "attempt_number", default: 1, null: false + t.boolean "pass_status" + t.text "exam_data" + t.boolean "completed", default: false + t.datetime "attempted_at" + t.string "cmi_entry", default: "ab-initio" + t.string "exam_result" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["task_id"], name: "index_test_attempts_on_task_id" + end + create_table "tii_actions", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| t.string "entity_type" t.bigint "entity_id" @@ -535,4 +554,5 @@ t.index ["user_id"], name: "index_webcals_on_user_id", unique: true end + add_foreign_key "test_attempts", "tasks" end