Apply automatic rubocop fixes

This commit is contained in:
Sebastian Serth
2021-05-17 19:40:38 +02:00
parent a6c6b07a91
commit 5243808d54
26 changed files with 72 additions and 72 deletions

View File

@ -15,7 +15,7 @@ class ApplicationController < ActionController::Base
def current_user def current_user
::NewRelic::Agent.add_custom_attributes(external_user_id: session[:external_user_id], ::NewRelic::Agent.add_custom_attributes(external_user_id: session[:external_user_id],
session_user_id: session[:user_id]) session_user_id: session[:user_id])
@current_user ||= ExternalUser.find_by(id: session[:external_user_id]) || login_from_session || login_from_other_sources || nil @current_user ||= ExternalUser.find_by(id: session[:external_user_id]) || login_from_session || login_from_other_sources || nil
end end

View File

@ -49,7 +49,7 @@ path: path, status: :created)
def file_params def file_params
if params[:code_ocean_file].present? if params[:code_ocean_file].present?
params[:code_ocean_file].permit(file_attributes).merge(context_type: 'Submission', params[:code_ocean_file].permit(file_attributes).merge(context_type: 'Submission',
role: 'user_defined_file') role: 'user_defined_file')
end end
end end
private :file_params private :file_params

View File

@ -8,7 +8,7 @@ class CodeharborLinksController < ApplicationController
def new def new
base_url = CodeOcean::Config.new(:code_ocean).read[:codeharbor][:url] || '' base_url = CodeOcean::Config.new(:code_ocean).read[:codeharbor][:url] || ''
@codeharbor_link = CodeharborLink.new(push_url: "#{base_url}/import_exercise", @codeharbor_link = CodeharborLink.new(push_url: "#{base_url}/import_exercise",
check_uuid_url: "#{base_url}/import_uuid_check") check_uuid_url: "#{base_url}/import_uuid_check")
authorize! authorize!
end end

View File

@ -86,7 +86,7 @@ class CommentsController < ApplicationController
# params.require(:comment).permit(:user_id, :file_id, :row, :column, :text) # params.require(:comment).permit(:user_id, :file_id, :row, :column, :text)
# fuer production mode, damit böse menschen keine falsche user_id uebergeben: # fuer production mode, damit böse menschen keine falsche user_id uebergeben:
params.require(:comment).permit(:file_id, :row, :column, :text, :request_id).merge(user_id: current_user.id, params.require(:comment).permit(:file_id, :row, :column, :text, :request_id).merge(user_id: current_user.id,
user_type: current_user.class.name) user_type: current_user.class.name)
end end
def send_mail_to_author(comment, request_for_comment) def send_mail_to_author(comment, request_for_comment)
@ -99,10 +99,10 @@ user_type: current_user.class.name)
request_for_comment.commenters.each do |commenter| request_for_comment.commenters.each do |commenter|
already_sent_mail = false already_sent_mail = false
subscriptions = Subscription.where( subscriptions = Subscription.where(
request_for_comment_id: request_for_comment.id, request_for_comment_id: request_for_comment.id,
user_id: commenter.id, user_type: commenter.class.name, user_id: commenter.id, user_type: commenter.class.name,
deleted: false deleted: false
) )
subscriptions.each do |subscription| subscriptions.each do |subscription|
if (((subscription.subscription_type == 'author') && (current_user == request_for_comment.user)) || (subscription.subscription_type == 'all')) && !((subscription.user == current_user) || already_sent_mail) if (((subscription.subscription_type == 'author') && (current_user == request_for_comment.user)) || (subscription.subscription_type == 'all')) && !((subscription.user == current_user) || already_sent_mail)
UserMailer.got_new_comment_for_subscription(comment, subscription, current_user).deliver_now UserMailer.got_new_comment_for_subscription(comment, subscription, current_user).deliver_now

View File

@ -30,7 +30,7 @@ module Lti
session.delete(:lti_parameters_id) session.delete(:lti_parameters_id)
end end
LtiParameter.where(external_users_id: user_id, LtiParameter.where(external_users_id: user_id,
exercises_id: exercise_id).destroy_all exercises_id: exercise_id).destroy_all
end end
private :clear_lti_session_data private :clear_lti_session_data
@ -143,8 +143,8 @@ module Lti
if submission.user.consumer if submission.user.consumer
lti_parameter = LtiParameter.where(consumers_id: submission.user.consumer.id, lti_parameter = LtiParameter.where(consumers_id: submission.user.consumer.id,
external_users_id: submission.user_id, external_users_id: submission.user_id,
exercises_id: submission.exercise_id).last exercises_id: submission.exercise_id).last
provider = build_tool_provider(consumer: submission.user.consumer, parameters: lti_parameter.lti_parameters) provider = build_tool_provider(consumer: submission.user.consumer, parameters: lti_parameter.lti_parameters)
end end
@ -154,10 +154,10 @@ module Lti
elsif provider.outcome_service? elsif provider.outcome_service?
Sentry.set_extras({ Sentry.set_extras({
provider: provider.inspect, provider: provider.inspect,
score: submission.normalized_score, score: submission.normalized_score,
lti_parameter: lti_parameter.inspect, lti_parameter: lti_parameter.inspect,
session: session.to_hash, session: session.to_hash,
exercise_id: submission.exercise_id, exercise_id: submission.exercise_id,
}) })
normalized_lit_score = submission.normalized_score normalized_lit_score = submission.normalized_score
if submission.before_deadline? if submission.before_deadline?
@ -230,8 +230,8 @@ module Lti
def store_lti_session_data(options = {}) def store_lti_session_data(options = {})
lti_parameters = LtiParameter.find_or_create_by(consumers_id: options[:consumer].id, lti_parameters = LtiParameter.find_or_create_by(consumers_id: options[:consumer].id,
external_users_id: @current_user.id, external_users_id: @current_user.id,
exercises_id: @exercise.id) exercises_id: @exercise.id)
lti_parameters.lti_parameters = options[:parameters].slice(*SESSION_PARAMETERS).permit!.to_h lti_parameters.lti_parameters = options[:parameters].slice(*SESSION_PARAMETERS).permit!.to_h
lti_parameters.save! lti_parameters.save!

View File

@ -84,7 +84,7 @@ module SubmissionScoring
if submission.normalized_score.to_d == 1.0.to_d if submission.normalized_score.to_d == 1.0.to_d
Thread.new do Thread.new do
RequestForComment.where(exercise_id: submission.exercise_id, user_id: submission.user_id, RequestForComment.where(exercise_id: submission.exercise_id, user_id: submission.user_id,
user_type: submission.user_type).each do |rfc| user_type: submission.user_type).each do |rfc|
rfc.full_score_reached = true rfc.full_score_reached = true
rfc.save rfc.save
end end

View File

@ -103,8 +103,8 @@ class ExecutionEnvironmentsController < ApplicationController
def execution_environment_params def execution_environment_params
if params[:execution_environment].present? if params[:execution_environment].present?
params[:execution_environment].permit(:docker_image, :exposed_ports, :editor_mode, :file_extension, :file_type_id, :help, :indent_size, :memory_limit, :name, :network_enabled, :permitted_execution_time, :pool_size, :run_command, :test_command, :testing_framework).merge( params[:execution_environment].permit(:docker_image, :exposed_ports, :editor_mode, :file_extension, :file_type_id, :help, :indent_size, :memory_limit, :name, :network_enabled, :permitted_execution_time, :pool_size, :run_command, :test_command, :testing_framework).merge(
user_id: current_user.id, user_type: current_user.class.name user_id: current_user.id, user_type: current_user.class.name
) )
end end
end end
private :execution_environment_params private :execution_environment_params

View File

@ -111,7 +111,7 @@ raise: false
def export_external_check def export_external_check
codeharbor_check = ExerciseService::CheckExternal.call(uuid: @exercise.uuid, codeharbor_check = ExerciseService::CheckExternal.call(uuid: @exercise.uuid,
codeharbor_link: current_user.codeharbor_link) codeharbor_link: current_user.codeharbor_link)
render json: { render json: {
message: codeharbor_check[:message], message: codeharbor_check[:message],
actions: render_to_string( actions: render_to_string(
@ -139,7 +139,7 @@ codeharbor_link: current_user.codeharbor_link)
status: 'success', status: 'success',
message: t('exercises.export_codeharbor.successfully_exported', id: @exercise.id, title: @exercise.title), message: t('exercises.export_codeharbor.successfully_exported', id: @exercise.id, title: @exercise.title),
actions: render_to_string(partial: 'export_actions', actions: render_to_string(partial: 'export_actions',
locals: {exercise: @exercise, exported: true, error: error}), locals: {exercise: @exercise, exported: true, error: error}),
} }
@exercise.save @exercise.save
else else
@ -147,7 +147,7 @@ locals: {exercise: @exercise, exported: true, error: error}),
status: 'fail', status: 'fail',
message: t('exercises.export_codeharbor.export_failed', id: @exercise.id, title: @exercise.title, error: error), message: t('exercises.export_codeharbor.export_failed', id: @exercise.id, title: @exercise.title, error: error),
actions: render_to_string(partial: 'export_actions', actions: render_to_string(partial: 'export_actions',
locals: {exercise: @exercise, exported: true, error: error}), locals: {exercise: @exercise, exported: true, error: error}),
} }
end end
end end
@ -203,8 +203,8 @@ locals: {exercise: @exercise, exported: true, error: error}),
def exercise_params def exercise_params
if params[:exercise].present? if params[:exercise].present?
params[:exercise].permit(:description, :execution_environment_id, :file_id, :instructions, :submission_deadline, :late_submission_deadline, :public, :unpublished, :hide_file_tree, :allow_file_creation, :allow_auto_completion, :title, :expected_difficulty, :tips, files_attributes: file_attributes, tag_ids: []).merge( params[:exercise].permit(:description, :execution_environment_id, :file_id, :instructions, :submission_deadline, :late_submission_deadline, :public, :unpublished, :hide_file_tree, :allow_file_creation, :allow_auto_completion, :title, :expected_difficulty, :tips, files_attributes: file_attributes, tag_ids: []).merge(
user_id: current_user.id, user_type: current_user.class.name user_id: current_user.id, user_type: current_user.class.name
) )
end end
end end
private :exercise_params private :exercise_params
@ -248,8 +248,8 @@ user_id: current_user.id, user_type: current_user.class.name
exercise_tips.each do |exercise_tip| exercise_tips.each do |exercise_tip|
exercise_tip.symbolize_keys! exercise_tip.symbolize_keys!
current_exercise_tip = ExerciseTip.find_or_initialize_by(id: exercise_tip[:id], current_exercise_tip = ExerciseTip.find_or_initialize_by(id: exercise_tip[:id],
exercise: @exercise, exercise: @exercise,
tip_id: exercise_tip[:tip_id]) tip_id: exercise_tip[:tip_id])
current_exercise_tip.parent_exercise_tip_id = parent_exercise_tip_id current_exercise_tip.parent_exercise_tip_id = parent_exercise_tip_id
current_exercise_tip.rank = rank current_exercise_tip.rank = rank
rank += 1 rank += 1
@ -275,7 +275,7 @@ user_id: current_user.id, user_type: current_user.class.name
count_interventions_today = UserExerciseIntervention.where(user: current_user).where('created_at >= ?', count_interventions_today = UserExerciseIntervention.where(user: current_user).where('created_at >= ?',
Time.zone.now.beginning_of_day).count Time.zone.now.beginning_of_day).count
user_got_intervention_in_exercise = UserExerciseIntervention.where(user: current_user, user_got_intervention_in_exercise = UserExerciseIntervention.where(user: current_user,
exercise: @exercise).size >= max_intervention_count_per_exercise exercise: @exercise).size >= max_intervention_count_per_exercise
(user_got_enough_interventions = count_interventions_today >= max_intervention_count_per_day) || user_got_intervention_in_exercise (user_got_enough_interventions = count_interventions_today >= max_intervention_count_per_day) || user_got_intervention_in_exercise
if @embed_options[:disable_interventions] if @embed_options[:disable_interventions]
@ -302,7 +302,7 @@ exercise: @exercise).size >= max_intervention_count_per_exercise
def set_course_token def set_course_token
lti_parameters = LtiParameter.where(external_users_id: current_user.id, lti_parameters = LtiParameter.where(external_users_id: current_user.id,
exercises_id: @exercise.id).last exercises_id: @exercise.id).last
if lti_parameters if lti_parameters
lti_json = lti_parameters.lti_parameters['launch_presentation_return_url'] lti_json = lti_parameters.lti_parameters['launch_presentation_return_url']
@ -397,11 +397,11 @@ working_time_accumulated: working_time_accumulated})
) )
lti_parameter = LtiParameter.where(external_users_id: @submission.user_id, lti_parameter = LtiParameter.where(external_users_id: @submission.user_id,
exercises_id: @submission.exercise_id).last exercises_id: @submission.exercise_id).last
path = lti_return_path(submission_id: @submission.id, path = lti_return_path(submission_id: @submission.id,
url: consumer_return_url(build_tool_provider(consumer: @submission.user.consumer, url: consumer_return_url(build_tool_provider(consumer: @submission.user.consumer,
parameters: lti_parameter.lti_parameters))) parameters: lti_parameter.lti_parameters)))
clear_lti_session_data(@submission.exercise_id, @submission.user_id) clear_lti_session_data(@submission.exercise_id, @submission.user_id)
respond_to do |format| respond_to do |format|
format.html { redirect_to(path) } format.html { redirect_to(path) }
@ -525,7 +525,7 @@ working_time_accumulated: working_time_accumulated})
def transmit_lti_score def transmit_lti_score
::NewRelic::Agent.add_custom_attributes({submission: @submission.id, ::NewRelic::Agent.add_custom_attributes({submission: @submission.id,
normalized_score: @submission.normalized_score}) normalized_score: @submission.normalized_score})
response = send_score(@submission) response = send_score(@submission)
if response[:status] == 'success' if response[:status] == 'success'

View File

@ -80,7 +80,7 @@ class ExternalUsersController < ApplicationController
tags = ProxyExercise.new.get_user_knowledge_and_max_knowledge(@user, @user.participations.uniq.compact) tags = ProxyExercise.new.get_user_knowledge_and_max_knowledge(@user, @user.participations.uniq.compact)
tags[:user_topic_knowledge].each_pair do |tag, value| tags[:user_topic_knowledge].each_pair do |tag, value|
statistics.append({key: tag.name.to_s, value: (100.0 / tags[:max_topic_knowledge][tag] * value).round, statistics.append({key: tag.name.to_s, value: (100.0 / tags[:max_topic_knowledge][tag] * value).round,
id: tag.id}) id: tag.id})
end end
statistics.sort_by! {|item| -item[:value] } statistics.sort_by! {|item| -item[:value] }

View File

@ -26,8 +26,8 @@ class FileTypesController < ApplicationController
def file_type_params def file_type_params
if params[:file_type].present? if params[:file_type].present?
params[:file_type].permit(:binary, :editor_mode, :executable, :file_extension, :name, :indent_size, :renderable).merge( params[:file_type].permit(:binary, :editor_mode, :executable, :file_extension, :name, :indent_size, :renderable).merge(
user_id: current_user.id, user_type: current_user.class.name user_id: current_user.id, user_type: current_user.class.name
) )
end end
end end
private :file_type_params private :file_type_params

View File

@ -12,7 +12,7 @@ class ProxyExercisesController < ApplicationController
def clone def clone
proxy_exercise = @proxy_exercise.duplicate(public: false, token: nil, exercises: @proxy_exercise.exercises, proxy_exercise = @proxy_exercise.duplicate(public: false, token: nil, exercises: @proxy_exercise.exercises,
user: current_user) user: current_user)
proxy_exercise.send(:generate_token) proxy_exercise.send(:generate_token)
if proxy_exercise.save if proxy_exercise.save
redirect_to(proxy_exercise, notice: t('shared.object_cloned', model: ProxyExercise.model_name.human)) redirect_to(proxy_exercise, notice: t('shared.object_cloned', model: ProxyExercise.model_name.human))
@ -44,7 +44,7 @@ user: current_user)
def proxy_exercise_params def proxy_exercise_params
if params[:proxy_exercise].present? if params[:proxy_exercise].present?
params[:proxy_exercise].permit(:description, :title, :public, exercise_ids: []).merge(user_id: current_user.id, params[:proxy_exercise].permit(:description, :title, :public, exercise_ids: []).merge(user_id: current_user.id,
user_type: current_user.class.name) user_type: current_user.class.name)
end end
end end
private :proxy_exercise_params private :proxy_exercise_params

View File

@ -145,8 +145,8 @@ class RequestForCommentsController < ApplicationController
def request_for_comment_params def request_for_comment_params
# The study_group_id might not be present in the session (e.g. for internal users), resulting in session[:study_group_id] = nil which is intended. # The study_group_id might not be present in the session (e.g. for internal users), resulting in session[:study_group_id] = nil which is intended.
params.require(:request_for_comment).permit(:exercise_id, :file_id, :question, :requested_at, :solved, :submission_id).merge( params.require(:request_for_comment).permit(:exercise_id, :file_id, :question, :requested_at, :solved, :submission_id).merge(
user_id: current_user.id, user_type: current_user.class.name user_id: current_user.id, user_type: current_user.class.name
) )
end end
# The index page requires the grouping of the study groups # The index page requires the grouping of the study groups

View File

@ -47,7 +47,7 @@ module_name: File.basename(filename, File.extname(filename)).underscore}
params[:annotations_arr]&.each do |annotation| params[:annotations_arr]&.each do |annotation|
# comment = Comment.new(annotation[1].permit(:user_id, :file_id, :user_type, :row, :column, :text, :created_at, :updated_at)) # comment = Comment.new(annotation[1].permit(:user_id, :file_id, :user_type, :row, :column, :text, :created_at, :updated_at))
comment = Comment.new(user_id: annotation[1][:user_id], file_id: annotation[1][:file_id], comment = Comment.new(user_id: annotation[1][:user_id], file_id: annotation[1][:file_id],
user_type: current_user.class.name, row: annotation[1][:row], column: annotation[1][:column], text: annotation[1][:text]) user_type: current_user.class.name, row: annotation[1][:row], column: annotation[1][:column], text: annotation[1][:text])
source_file = CodeOcean::File.find(annotation[1][:file_id]) source_file = CodeOcean::File.find(annotation[1][:file_id])
# retrieve target file # retrieve target file

View File

@ -57,7 +57,7 @@ class SubscriptionsController < ApplicationController
current_user_class_name = current_user.try(:class).try(:name) current_user_class_name = current_user.try(:class).try(:name)
if params[:subscription].present? if params[:subscription].present?
params[:subscription].permit(:request_for_comment_id, :subscription_type).merge(user_id: current_user_id, params[:subscription].permit(:request_for_comment_id, :subscription_type).merge(user_id: current_user_id,
user_type: current_user_class_name, deleted: false) user_type: current_user_class_name, deleted: false)
end end
end end
private :subscription_params private :subscription_params

View File

@ -132,9 +132,9 @@ class UserExerciseFeedbacksController < ApplicationController
params[:user_exercise_feedback] params[:user_exercise_feedback]
.permit(:feedback_text, :difficulty, :exercise_id, :user_estimated_worktime) .permit(:feedback_text, :difficulty, :exercise_id, :user_estimated_worktime)
.merge(user_id: user_id, .merge(user_id: user_id,
user_type: user_type, user_type: user_type,
submission: latest_submission, submission: latest_submission,
normalized_score: latest_submission.normalized_score) normalized_score: latest_submission.normalized_score)
end end
def validate_inputs(uef_params) def validate_inputs(uef_params)

View File

@ -10,7 +10,7 @@ module ActionCableHelper
type: :rfc, type: :rfc,
id: id, id: id,
html: ApplicationController.render(partial: 'request_for_comments/list_entry', html: ApplicationController.render(partial: 'request_for_comments/list_entry',
locals: {request_for_comment: self}) locals: {request_for_comment: self})
) )
end end
ensure ensure

View File

@ -7,7 +7,7 @@ module LtiHelper
return false if external_user_id == '' return false if external_user_id == ''
lti_parameters = LtiParameter.where(external_users_id: external_user_id, lti_parameters = LtiParameter.where(external_users_id: external_user_id,
exercises_id: exercise_id).lis_outcome_service_url?.last exercises_id: exercise_id).lis_outcome_service_url?.last
!lti_parameters.nil? && lti_parameters.present? !lti_parameters.nil? && lti_parameters.present?
end end
end end

View File

@ -25,9 +25,9 @@ class UserMailer < ApplicationMailer
@comment_text = comment.text @comment_text = comment.text
@rfc_link = request_for_comment_url(request_for_comment) @rfc_link = request_for_comment_url(request_for_comment)
mail( mail(
subject: t('mailers.user_mailer.got_new_comment.subject', subject: t('mailers.user_mailer.got_new_comment.subject',
commenting_user_displayname: @commenting_user_displayname), to: request_for_comment.user.email commenting_user_displayname: @commenting_user_displayname), to: request_for_comment.user.email
) )
end end
def got_new_comment_for_subscription(comment, subscription, from_user) def got_new_comment_for_subscription(comment, subscription, from_user)
@ -37,9 +37,9 @@ subject: t('mailers.user_mailer.got_new_comment.subject',
@rfc_link = request_for_comment_url(subscription.request_for_comment) @rfc_link = request_for_comment_url(subscription.request_for_comment)
@unsubscribe_link = unsubscribe_subscription_url(subscription) @unsubscribe_link = unsubscribe_subscription_url(subscription)
mail( mail(
subject: t('mailers.user_mailer.got_new_comment_for_subscription.subject', subject: t('mailers.user_mailer.got_new_comment_for_subscription.subject',
author_displayname: @author_displayname), to: subscription.user.email author_displayname: @author_displayname), to: subscription.user.email
) )
end end
def send_thank_you_note(request_for_comments, receiver) def send_thank_you_note(request_for_comments, receiver)

View File

@ -7,7 +7,7 @@ module CodeOcean
class FileNameValidator < ActiveModel::Validator class FileNameValidator < ActiveModel::Validator
def validate(record) def validate(record)
existing_files = File.where(name: record.name, path: record.path, file_type_id: record.file_type_id, existing_files = File.where(name: record.name, path: record.path, file_type_id: record.file_type_id,
context_id: record.context_id, context_type: record.context_type).to_a context_id: record.context_id, context_type: record.context_type).to_a
if !existing_files.empty? && (!record.context.is_a?(Exercise) || record.context.new_record?) if !existing_files.empty? && (!record.context.is_a?(Exercise) || record.context.new_record?)
record.errors[:base] << 'Duplicate' record.errors[:base] << 'Duplicate'
end end

View File

@ -500,14 +500,14 @@ class Exercise < ApplicationRecord
feedback_message_nodes = task_node.xpath('p:tests/p:test/p:test-configuration/c:feedback-message/text()') feedback_message_nodes = task_node.xpath('p:tests/p:test/p:test-configuration/c:feedback-message/text()')
files.build({ files.build({
name: file_name_split.first, name: file_name_split.first,
content: file.xpath('text()').first.content, content: file.xpath('text()').first.content,
read_only: false, read_only: false,
hidden: file_class == 'internal', hidden: file_class == 'internal',
role: role, role: role,
feedback_message: role == 'teacher_defined_test' ? feedback_message_nodes.first.content : nil, feedback_message: role == 'teacher_defined_test' ? feedback_message_nodes.first.content : nil,
file_type: FileType.find_by( file_type: FileType.find_by(
file_extension: ".#{file_name_split.second}" file_extension: ".#{file_name_split.second}"
), ),
}) })
end end
self.execution_environment_id = 1 self.execution_environment_id = 1

View File

@ -14,8 +14,8 @@ class ExerciseTip < ApplicationRecord
def tip_chain? def tip_chain?
# Ensure each referenced parent exercise tip is set for this exercise # Ensure each referenced parent exercise tip is set for this exercise
unless ExerciseTip.exists?( unless ExerciseTip.exists?(
exercise: exercise, id: parent_exercise_tip exercise: exercise, id: parent_exercise_tip
) )
errors.add :parent_exercise_tip, errors.add :parent_exercise_tip,
I18n.t('activerecord.errors.messages.together', I18n.t('activerecord.errors.messages.together',
attribute: I18n.t('activerecord.attributes.exercise_tip.tip')) attribute: I18n.t('activerecord.attributes.exercise_tip.tip'))

View File

@ -58,7 +58,7 @@ class ProxyExercise < ApplicationRecord
exercises.where('expected_difficulty > 1').sample # difficulty should be > 1 to prevent dummy exercise from being chosen. exercises.where('expected_difficulty > 1').sample # difficulty should be > 1 to prevent dummy exercise from being chosen.
end end
user.user_proxy_exercise_exercises << UserProxyExerciseExercise.create(user: user, user.user_proxy_exercise_exercises << UserProxyExerciseExercise.create(user: user,
exercise: matching_exercise, proxy_exercise: self, reason: @reason.to_json) exercise: matching_exercise, proxy_exercise: self, reason: @reason.to_json)
matching_exercise matching_exercise
end end
end end

View File

@ -11,6 +11,6 @@ class StructuredErrorAttribute < ApplicationRecord
value = result.captures[0] value = result.captures[0]
end end
create(structured_error: structured_error, error_template_attribute: attribute, value: value, create(structured_error: structured_error, error_template_attribute: attribute, value: value,
match: !result.nil?) match: !result.nil?)
end end
end end

View File

@ -17,7 +17,7 @@ class DockerContainerPool
container container
rescue StandardError => e rescue StandardError => e
Sentry.set_extras({container: container.inspect, execution_environment: execution_environment.inspect, Sentry.set_extras({container: container.inspect, execution_environment: execution_environment.inspect,
config: config.inspect}) config: config.inspect})
Sentry.capture_exception(e) Sentry.capture_exception(e)
nil nil
end end
@ -26,7 +26,7 @@ config: config.inspect})
Faraday.get("#{config[:location]}/docker_container_pool/return_container/#{container.id}") Faraday.get("#{config[:location]}/docker_container_pool/return_container/#{container.id}")
rescue StandardError => e rescue StandardError => e
Sentry.set_extras({container: container.inspect, execution_environment: execution_environment.inspect, Sentry.set_extras({container: container.inspect, execution_environment: execution_environment.inspect,
config: config.inspect}) config: config.inspect})
Sentry.capture_exception(e) Sentry.capture_exception(e)
nil nil
end end
@ -39,7 +39,7 @@ config: config.inspect})
Docker::Container.get(container_id) if container_id.present? Docker::Container.get(container_id) if container_id.present?
rescue StandardError => e rescue StandardError => e
Sentry.set_extras({container_id: container_id.inspect, execution_environment: execution_environment.inspect, Sentry.set_extras({container_id: container_id.inspect, execution_environment: execution_environment.inspect,
config: config.inspect}) config: config.inspect})
Sentry.capture_exception(e) Sentry.capture_exception(e)
nil nil
end end

View File

@ -133,7 +133,7 @@ namespace :detect_exercise_anomalies do
segment.each do |user| segment.each do |user|
reason = "{\"segment\": \"#{key}\", \"feature\": \"#{user[:reason]}\", value: \"#{user[:value]}\"}" reason = "{\"segment\": \"#{key}\", \"feature\": \"#{user[:reason]}\", value: \"#{user[:value]}\"}"
AnomalyNotification.create(user_id: user[:user_id], user_type: user[:user_type], AnomalyNotification.create(user_id: user[:user_id], user_type: user[:user_type],
exercise: exercise, exercise_collection: collection, reason: reason) exercise: exercise, exercise_collection: collection, reason: reason)
end end
end end
@ -142,7 +142,7 @@ namespace :detect_exercise_anomalies do
user = u[:user_type] == InternalUser.name ? InternalUser.find(u[:user_id]) : ExternalUser.find(u[:user_id]) user = u[:user_type] == InternalUser.name ? InternalUser.find(u[:user_id]) : ExternalUser.find(u[:user_id])
host = CodeOcean::Application.config.action_mailer.default_url_options[:host] host = CodeOcean::Application.config.action_mailer.default_url_options[:host]
feedback_link = Rails.application.routes.url_helpers.url_for(action: :new, feedback_link = Rails.application.routes.url_helpers.url_for(action: :new,
controller: :user_exercise_feedbacks, exercise_id: exercise.id, host: host) controller: :user_exercise_feedbacks, exercise_id: exercise.id, host: host)
UserMailer.exercise_anomaly_needs_feedback(user, exercise, feedback_link).deliver UserMailer.exercise_anomaly_needs_feedback(user, exercise, feedback_link).deliver
end end
log("Asked #{users_to_notify.size} users for feedback.", 2) log("Asked #{users_to_notify.size} users for feedback.", 2)

View File

@ -353,7 +353,7 @@ describe DockerClient, docker: true do
end end
describe '#send_command' do describe '#send_command' do
let(:block) { proc { nil } } let(:block) { proc {} }
let(:container) { described_class.create_container(execution_environment) } let(:container) { described_class.create_container(execution_environment) }
let(:send_command) { docker_client.send(:send_command, command, container, &block) } let(:send_command) { docker_client.send(:send_command, command, container, &block) }