diff --git a/app/controllers/remote_evaluation_controller.rb b/app/controllers/remote_evaluation_controller.rb index 36d61f73..5f01860c 100644 --- a/app/controllers/remote_evaluation_controller.rb +++ b/app/controllers/remote_evaluation_controller.rb @@ -15,14 +15,12 @@ class RemoteEvaluationController < ApplicationController # todo extra: validiere, ob files wirklich zur Übung gehören (wenn allowNewFiles-flag nicht gesetzt ist) if (remote_evaluation_mapping = RemoteEvaluationMapping.find_by(:validation_token => validation_token)) - puts remote_evaluation_mapping.exercise_id - puts remote_evaluation_mapping.user_id _params = remote_evaluation_params.except(:validation_token) _params[:exercise_id] = remote_evaluation_mapping.exercise_id _params[:user_id] = remote_evaluation_mapping.user_id _params[:cause] = "remoteAssess" - _params[:user_type] = "ExternalUser" + _params[:user_type] = remote_evaluation_mapping.user_type @submission = Submission.create(_params) render json: score_submission(@submission) diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index 8d16eb90..32d1e560 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -398,13 +398,13 @@ class SubmissionsController < ApplicationController private :with_server_sent_events def create_remote_evaluation_mapping - user_id = @submission.user_id + user = @submission.user exercise_id = @submission.exercise_id - remote_evaluation_mapping = RemoteEvaluationMapping.create(:user_id => user_id, :exercise_id => exercise_id) + remote_evaluation_mapping = RemoteEvaluationMapping.create(user: user, exercise_id: exercise_id) # create .co file - path = "tmp/" + user_id.to_s + ".co" + path = "tmp/" + user.id.to_s + ".co" # parse validation token content = "#{remote_evaluation_mapping.validation_token}\n" # parse remote request url diff --git a/app/models/remote_evaluation_mapping.rb b/app/models/remote_evaluation_mapping.rb index 551ab8a6..a0fba790 100644 --- a/app/models/remote_evaluation_mapping.rb +++ b/app/models/remote_evaluation_mapping.rb @@ -2,9 +2,9 @@ class RemoteEvaluationMapping < ApplicationRecord before_create :generate_token, unless: :validation_token? belongs_to :exercise - belongs_to :user, class_name: 'ExternalUser' + belongs_to :user, polymorphic: true def generate_token self.validation_token = SecureRandom.urlsafe_base64 end -end \ No newline at end of file +end diff --git a/db/migrate/20181126163428_add_user_type_to_remote_evaluation_mappings.rb b/db/migrate/20181126163428_add_user_type_to_remote_evaluation_mappings.rb new file mode 100644 index 00000000..0ad50d0f --- /dev/null +++ b/db/migrate/20181126163428_add_user_type_to_remote_evaluation_mappings.rb @@ -0,0 +1,8 @@ +class AddUserTypeToRemoteEvaluationMappings < ActiveRecord::Migration[5.2] + def change + add_column :remote_evaluation_mappings, :user_type, :string + # Update all existing records and set user_type to `ExternalUser` (safe way to prevent any function loss). + # We are not using a default value here on intend to be in line with the other `user_type` columns + RemoteEvaluationMapping.update_all(user_type: 'ExternalUser') + end +end diff --git a/db/schema.rb b/db/schema.rb index f84e45d1..f918e876 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: 2018_09_04_115948) do +ActiveRecord::Schema.define(version: 2018_11_26_163428) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -290,6 +290,7 @@ ActiveRecord::Schema.define(version: 2018_09_04_115948) do t.string "validation_token", null: false t.datetime "created_at" t.datetime "updated_at" + t.string "user_type" end create_table "request_for_comments", force: :cascade do |t|