From 4958f5b9a9ad8d1f09d768f0734eb664363d3d2e Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Mon, 26 Apr 2021 16:40:34 +0200 Subject: [PATCH] Add StudyGroup to RemoteEvaluationMapping --- app/controllers/remote_evaluation_controller.rb | 1 + app/controllers/submissions_controller.rb | 6 +++++- app/models/remote_evaluation_mapping.rb | 1 + app/models/study_group.rb | 1 + app/models/user.rb | 1 + ...6113125_add_study_group_to_remote_evaluation_mapping.rb | 7 +++++++ db/schema.rb | 5 ++++- 7 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20210426113125_add_study_group_to_remote_evaluation_mapping.rb diff --git a/app/controllers/remote_evaluation_controller.rb b/app/controllers/remote_evaluation_controller.rb index 722a530a..7bb46653 100644 --- a/app/controllers/remote_evaluation_controller.rb +++ b/app/controllers/remote_evaluation_controller.rb @@ -74,6 +74,7 @@ class RemoteEvaluationController < ApplicationController submission_params = remote_evaluation_params.except(:validation_token) submission_params[:exercise_id] = remote_evaluation_mapping.exercise_id submission_params[:user_id] = remote_evaluation_mapping.user_id + submission_params[:study_group_id] = remote_evaluation_mapping.study_group_id submission_params[:cause] = cause submission_params[:user_type] = remote_evaluation_mapping.user_type submission_params[:files_attributes] = reject_illegal_file_attributes(remote_evaluation_mapping.exercise, files_attributes) diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index c045432b..5b62c322 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -450,7 +450,11 @@ class SubmissionsController < ApplicationController user = @submission.user exercise_id = @submission.exercise_id - remote_evaluation_mapping = RemoteEvaluationMapping.create(user: user, exercise_id: exercise_id) + remote_evaluation_mapping = RemoteEvaluationMapping.create( + user: user, + exercise_id: exercise_id, + study_group_id: session[:study_group_id] + ) # create .co file path = "tmp/" + user.id.to_s + ".co" diff --git a/app/models/remote_evaluation_mapping.rb b/app/models/remote_evaluation_mapping.rb index a0fba790..091e881f 100644 --- a/app/models/remote_evaluation_mapping.rb +++ b/app/models/remote_evaluation_mapping.rb @@ -3,6 +3,7 @@ class RemoteEvaluationMapping < ApplicationRecord before_create :generate_token, unless: :validation_token? belongs_to :exercise belongs_to :user, polymorphic: true + belongs_to :study_group, optional: true def generate_token self.validation_token = SecureRandom.urlsafe_base64 diff --git a/app/models/study_group.rb b/app/models/study_group.rb index 6ec12779..133ca275 100644 --- a/app/models/study_group.rb +++ b/app/models/study_group.rb @@ -5,6 +5,7 @@ class StudyGroup < ApplicationRecord has_many :external_users, through: :study_group_memberships, source_type: 'ExternalUser', source: :user has_many :internal_users, through: :study_group_memberships, source_type: 'InternalUser', source: :user has_many :submissions, dependent: :nullify + has_many :remote_evaluation_mappings, dependent: :nullify belongs_to :consumer def users diff --git a/app/models/user.rb b/app/models/user.rb index 031dd464..d8796ff5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -13,6 +13,7 @@ class User < ApplicationRecord has_many :user_proxy_exercise_exercises, as: :user has_many :user_exercise_interventions, as: :user has_many :interventions, through: :user_exercise_interventions + has_many :remote_evaluation_mappings, as: :user has_one :codeharbor_link, dependent: :destroy accepts_nested_attributes_for :user_proxy_exercise_exercises diff --git a/db/migrate/20210426113125_add_study_group_to_remote_evaluation_mapping.rb b/db/migrate/20210426113125_add_study_group_to_remote_evaluation_mapping.rb new file mode 100644 index 00000000..13f44f6c --- /dev/null +++ b/db/migrate/20210426113125_add_study_group_to_remote_evaluation_mapping.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddStudyGroupToRemoteEvaluationMapping < ActiveRecord::Migration[5.2] + def change + add_reference :remote_evaluation_mappings, :study_group, index: true, null: true, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 9e06ed8e..1dba3159 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.define(version: 2020_12_10_113500) do +ActiveRecord::Schema.define(version: 2021_04_26_113125) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" @@ -317,6 +317,8 @@ ActiveRecord::Schema.define(version: 2020_12_10_113500) do t.datetime "created_at" t.datetime "updated_at" t.string "user_type" + t.bigint "study_group_id" + t.index ["study_group_id"], name: "index_remote_evaluation_mappings_on_study_group_id" end create_table "request_for_comments", id: :serial, force: :cascade do |t| @@ -480,6 +482,7 @@ ActiveRecord::Schema.define(version: 2020_12_10_113500) do add_foreign_key "exercise_tips", "exercises" add_foreign_key "exercise_tips", "tips" add_foreign_key "request_for_comments", "submissions", name: "request_for_comments_submissions_id_fk" + add_foreign_key "remote_evaluation_mappings", "study_groups" add_foreign_key "submissions", "study_groups" add_foreign_key "tips", "file_types" add_foreign_key "user_exercise_feedbacks", "submissions"