Apply automatic rubocop fixes
This commit is contained in:
@ -15,7 +15,7 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
def current_user
|
||||
::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
|
||||
end
|
||||
|
||||
|
@ -49,7 +49,7 @@ path: path, status: :created)
|
||||
def file_params
|
||||
if params[:code_ocean_file].present?
|
||||
params[:code_ocean_file].permit(file_attributes).merge(context_type: 'Submission',
|
||||
role: 'user_defined_file')
|
||||
role: 'user_defined_file')
|
||||
end
|
||||
end
|
||||
private :file_params
|
||||
|
@ -8,7 +8,7 @@ class CodeharborLinksController < ApplicationController
|
||||
def new
|
||||
base_url = CodeOcean::Config.new(:code_ocean).read[:codeharbor][:url] || ''
|
||||
@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!
|
||||
end
|
||||
|
||||
|
@ -86,7 +86,7 @@ class CommentsController < ApplicationController
|
||||
# params.require(:comment).permit(:user_id, :file_id, :row, :column, :text)
|
||||
# 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,
|
||||
user_type: current_user.class.name)
|
||||
user_type: current_user.class.name)
|
||||
end
|
||||
|
||||
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|
|
||||
already_sent_mail = false
|
||||
subscriptions = Subscription.where(
|
||||
request_for_comment_id: request_for_comment.id,
|
||||
user_id: commenter.id, user_type: commenter.class.name,
|
||||
deleted: false
|
||||
)
|
||||
request_for_comment_id: request_for_comment.id,
|
||||
user_id: commenter.id, user_type: commenter.class.name,
|
||||
deleted: false
|
||||
)
|
||||
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)
|
||||
UserMailer.got_new_comment_for_subscription(comment, subscription, current_user).deliver_now
|
||||
|
@ -30,7 +30,7 @@ module Lti
|
||||
session.delete(:lti_parameters_id)
|
||||
end
|
||||
LtiParameter.where(external_users_id: user_id,
|
||||
exercises_id: exercise_id).destroy_all
|
||||
exercises_id: exercise_id).destroy_all
|
||||
end
|
||||
|
||||
private :clear_lti_session_data
|
||||
@ -143,8 +143,8 @@ module Lti
|
||||
|
||||
if submission.user.consumer
|
||||
lti_parameter = LtiParameter.where(consumers_id: submission.user.consumer.id,
|
||||
external_users_id: submission.user_id,
|
||||
exercises_id: submission.exercise_id).last
|
||||
external_users_id: submission.user_id,
|
||||
exercises_id: submission.exercise_id).last
|
||||
|
||||
provider = build_tool_provider(consumer: submission.user.consumer, parameters: lti_parameter.lti_parameters)
|
||||
end
|
||||
@ -154,10 +154,10 @@ module Lti
|
||||
elsif provider.outcome_service?
|
||||
Sentry.set_extras({
|
||||
provider: provider.inspect,
|
||||
score: submission.normalized_score,
|
||||
lti_parameter: lti_parameter.inspect,
|
||||
session: session.to_hash,
|
||||
exercise_id: submission.exercise_id,
|
||||
score: submission.normalized_score,
|
||||
lti_parameter: lti_parameter.inspect,
|
||||
session: session.to_hash,
|
||||
exercise_id: submission.exercise_id,
|
||||
})
|
||||
normalized_lit_score = submission.normalized_score
|
||||
if submission.before_deadline?
|
||||
@ -230,8 +230,8 @@ module Lti
|
||||
|
||||
def store_lti_session_data(options = {})
|
||||
lti_parameters = LtiParameter.find_or_create_by(consumers_id: options[:consumer].id,
|
||||
external_users_id: @current_user.id,
|
||||
exercises_id: @exercise.id)
|
||||
external_users_id: @current_user.id,
|
||||
exercises_id: @exercise.id)
|
||||
|
||||
lti_parameters.lti_parameters = options[:parameters].slice(*SESSION_PARAMETERS).permit!.to_h
|
||||
lti_parameters.save!
|
||||
|
@ -84,7 +84,7 @@ module SubmissionScoring
|
||||
if submission.normalized_score.to_d == 1.0.to_d
|
||||
Thread.new do
|
||||
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.save
|
||||
end
|
||||
|
@ -103,8 +103,8 @@ class ExecutionEnvironmentsController < ApplicationController
|
||||
def execution_environment_params
|
||||
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(
|
||||
user_id: current_user.id, user_type: current_user.class.name
|
||||
)
|
||||
user_id: current_user.id, user_type: current_user.class.name
|
||||
)
|
||||
end
|
||||
end
|
||||
private :execution_environment_params
|
||||
|
@ -111,7 +111,7 @@ raise: false
|
||||
|
||||
def export_external_check
|
||||
codeharbor_check = ExerciseService::CheckExternal.call(uuid: @exercise.uuid,
|
||||
codeharbor_link: current_user.codeharbor_link)
|
||||
codeharbor_link: current_user.codeharbor_link)
|
||||
render json: {
|
||||
message: codeharbor_check[:message],
|
||||
actions: render_to_string(
|
||||
@ -139,7 +139,7 @@ codeharbor_link: current_user.codeharbor_link)
|
||||
status: 'success',
|
||||
message: t('exercises.export_codeharbor.successfully_exported', id: @exercise.id, title: @exercise.title),
|
||||
actions: render_to_string(partial: 'export_actions',
|
||||
locals: {exercise: @exercise, exported: true, error: error}),
|
||||
locals: {exercise: @exercise, exported: true, error: error}),
|
||||
}
|
||||
@exercise.save
|
||||
else
|
||||
@ -147,7 +147,7 @@ locals: {exercise: @exercise, exported: true, error: error}),
|
||||
status: 'fail',
|
||||
message: t('exercises.export_codeharbor.export_failed', id: @exercise.id, title: @exercise.title, error: error),
|
||||
actions: render_to_string(partial: 'export_actions',
|
||||
locals: {exercise: @exercise, exported: true, error: error}),
|
||||
locals: {exercise: @exercise, exported: true, error: error}),
|
||||
}
|
||||
end
|
||||
end
|
||||
@ -203,8 +203,8 @@ locals: {exercise: @exercise, exported: true, error: error}),
|
||||
def exercise_params
|
||||
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(
|
||||
user_id: current_user.id, user_type: current_user.class.name
|
||||
)
|
||||
user_id: current_user.id, user_type: current_user.class.name
|
||||
)
|
||||
end
|
||||
end
|
||||
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_tip.symbolize_keys!
|
||||
current_exercise_tip = ExerciseTip.find_or_initialize_by(id: exercise_tip[:id],
|
||||
exercise: @exercise,
|
||||
tip_id: exercise_tip[:tip_id])
|
||||
exercise: @exercise,
|
||||
tip_id: exercise_tip[:tip_id])
|
||||
current_exercise_tip.parent_exercise_tip_id = parent_exercise_tip_id
|
||||
current_exercise_tip.rank = rank
|
||||
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 >= ?',
|
||||
Time.zone.now.beginning_of_day).count
|
||||
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
|
||||
|
||||
if @embed_options[:disable_interventions]
|
||||
@ -302,7 +302,7 @@ exercise: @exercise).size >= max_intervention_count_per_exercise
|
||||
|
||||
def set_course_token
|
||||
lti_parameters = LtiParameter.where(external_users_id: current_user.id,
|
||||
exercises_id: @exercise.id).last
|
||||
exercises_id: @exercise.id).last
|
||||
if lti_parameters
|
||||
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,
|
||||
exercises_id: @submission.exercise_id).last
|
||||
exercises_id: @submission.exercise_id).last
|
||||
|
||||
path = lti_return_path(submission_id: @submission.id,
|
||||
url: consumer_return_url(build_tool_provider(consumer: @submission.user.consumer,
|
||||
parameters: lti_parameter.lti_parameters)))
|
||||
url: consumer_return_url(build_tool_provider(consumer: @submission.user.consumer,
|
||||
parameters: lti_parameter.lti_parameters)))
|
||||
clear_lti_session_data(@submission.exercise_id, @submission.user_id)
|
||||
respond_to do |format|
|
||||
format.html { redirect_to(path) }
|
||||
@ -525,7 +525,7 @@ working_time_accumulated: working_time_accumulated})
|
||||
|
||||
def transmit_lti_score
|
||||
::NewRelic::Agent.add_custom_attributes({submission: @submission.id,
|
||||
normalized_score: @submission.normalized_score})
|
||||
normalized_score: @submission.normalized_score})
|
||||
response = send_score(@submission)
|
||||
|
||||
if response[:status] == 'success'
|
||||
|
@ -80,7 +80,7 @@ class ExternalUsersController < ApplicationController
|
||||
tags = ProxyExercise.new.get_user_knowledge_and_max_knowledge(@user, @user.participations.uniq.compact)
|
||||
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,
|
||||
id: tag.id})
|
||||
id: tag.id})
|
||||
end
|
||||
statistics.sort_by! {|item| -item[:value] }
|
||||
|
||||
|
@ -26,8 +26,8 @@ class FileTypesController < ApplicationController
|
||||
def file_type_params
|
||||
if params[:file_type].present?
|
||||
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
|
||||
private :file_type_params
|
||||
|
@ -12,7 +12,7 @@ class ProxyExercisesController < ApplicationController
|
||||
|
||||
def clone
|
||||
proxy_exercise = @proxy_exercise.duplicate(public: false, token: nil, exercises: @proxy_exercise.exercises,
|
||||
user: current_user)
|
||||
user: current_user)
|
||||
proxy_exercise.send(:generate_token)
|
||||
if proxy_exercise.save
|
||||
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
|
||||
if params[:proxy_exercise].present?
|
||||
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
|
||||
private :proxy_exercise_params
|
||||
|
@ -145,8 +145,8 @@ class RequestForCommentsController < ApplicationController
|
||||
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.
|
||||
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
|
||||
|
||||
# The index page requires the grouping of the study groups
|
||||
|
@ -47,7 +47,7 @@ module_name: File.basename(filename, File.extname(filename)).underscore}
|
||||
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(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])
|
||||
|
||||
# retrieve target file
|
||||
|
@ -57,7 +57,7 @@ class SubscriptionsController < ApplicationController
|
||||
current_user_class_name = current_user.try(:class).try(:name)
|
||||
if params[:subscription].present?
|
||||
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
|
||||
private :subscription_params
|
||||
|
@ -132,9 +132,9 @@ class UserExerciseFeedbacksController < ApplicationController
|
||||
params[:user_exercise_feedback]
|
||||
.permit(:feedback_text, :difficulty, :exercise_id, :user_estimated_worktime)
|
||||
.merge(user_id: user_id,
|
||||
user_type: user_type,
|
||||
submission: latest_submission,
|
||||
normalized_score: latest_submission.normalized_score)
|
||||
user_type: user_type,
|
||||
submission: latest_submission,
|
||||
normalized_score: latest_submission.normalized_score)
|
||||
end
|
||||
|
||||
def validate_inputs(uef_params)
|
||||
|
@ -10,7 +10,7 @@ module ActionCableHelper
|
||||
type: :rfc,
|
||||
id: id,
|
||||
html: ApplicationController.render(partial: 'request_for_comments/list_entry',
|
||||
locals: {request_for_comment: self})
|
||||
locals: {request_for_comment: self})
|
||||
)
|
||||
end
|
||||
ensure
|
||||
|
@ -7,7 +7,7 @@ module LtiHelper
|
||||
return false if 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?
|
||||
end
|
||||
end
|
||||
|
@ -25,9 +25,9 @@ class UserMailer < ApplicationMailer
|
||||
@comment_text = comment.text
|
||||
@rfc_link = request_for_comment_url(request_for_comment)
|
||||
mail(
|
||||
subject: t('mailers.user_mailer.got_new_comment.subject',
|
||||
commenting_user_displayname: @commenting_user_displayname), to: request_for_comment.user.email
|
||||
)
|
||||
subject: t('mailers.user_mailer.got_new_comment.subject',
|
||||
commenting_user_displayname: @commenting_user_displayname), to: request_for_comment.user.email
|
||||
)
|
||||
end
|
||||
|
||||
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)
|
||||
@unsubscribe_link = unsubscribe_subscription_url(subscription)
|
||||
mail(
|
||||
subject: t('mailers.user_mailer.got_new_comment_for_subscription.subject',
|
||||
author_displayname: @author_displayname), to: subscription.user.email
|
||||
)
|
||||
subject: t('mailers.user_mailer.got_new_comment_for_subscription.subject',
|
||||
author_displayname: @author_displayname), to: subscription.user.email
|
||||
)
|
||||
end
|
||||
|
||||
def send_thank_you_note(request_for_comments, receiver)
|
||||
|
@ -7,7 +7,7 @@ module CodeOcean
|
||||
class FileNameValidator < ActiveModel::Validator
|
||||
def validate(record)
|
||||
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?)
|
||||
record.errors[:base] << 'Duplicate'
|
||||
end
|
||||
|
@ -500,14 +500,14 @@ class Exercise < ApplicationRecord
|
||||
feedback_message_nodes = task_node.xpath('p:tests/p:test/p:test-configuration/c:feedback-message/text()')
|
||||
files.build({
|
||||
name: file_name_split.first,
|
||||
content: file.xpath('text()').first.content,
|
||||
read_only: false,
|
||||
hidden: file_class == 'internal',
|
||||
role: role,
|
||||
feedback_message: role == 'teacher_defined_test' ? feedback_message_nodes.first.content : nil,
|
||||
file_type: FileType.find_by(
|
||||
file_extension: ".#{file_name_split.second}"
|
||||
),
|
||||
content: file.xpath('text()').first.content,
|
||||
read_only: false,
|
||||
hidden: file_class == 'internal',
|
||||
role: role,
|
||||
feedback_message: role == 'teacher_defined_test' ? feedback_message_nodes.first.content : nil,
|
||||
file_type: FileType.find_by(
|
||||
file_extension: ".#{file_name_split.second}"
|
||||
),
|
||||
})
|
||||
end
|
||||
self.execution_environment_id = 1
|
||||
|
@ -14,8 +14,8 @@ class ExerciseTip < ApplicationRecord
|
||||
def tip_chain?
|
||||
# Ensure each referenced parent exercise tip is set for this exercise
|
||||
unless ExerciseTip.exists?(
|
||||
exercise: exercise, id: parent_exercise_tip
|
||||
)
|
||||
exercise: exercise, id: parent_exercise_tip
|
||||
)
|
||||
errors.add :parent_exercise_tip,
|
||||
I18n.t('activerecord.errors.messages.together',
|
||||
attribute: I18n.t('activerecord.attributes.exercise_tip.tip'))
|
||||
|
@ -58,7 +58,7 @@ class ProxyExercise < ApplicationRecord
|
||||
exercises.where('expected_difficulty > 1').sample # difficulty should be > 1 to prevent dummy exercise from being chosen.
|
||||
end
|
||||
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
|
||||
end
|
||||
end
|
||||
|
@ -11,6 +11,6 @@ class StructuredErrorAttribute < ApplicationRecord
|
||||
value = result.captures[0]
|
||||
end
|
||||
create(structured_error: structured_error, error_template_attribute: attribute, value: value,
|
||||
match: !result.nil?)
|
||||
match: !result.nil?)
|
||||
end
|
||||
end
|
||||
|
@ -17,7 +17,7 @@ class DockerContainerPool
|
||||
container
|
||||
rescue StandardError => e
|
||||
Sentry.set_extras({container: container.inspect, execution_environment: execution_environment.inspect,
|
||||
config: config.inspect})
|
||||
config: config.inspect})
|
||||
Sentry.capture_exception(e)
|
||||
nil
|
||||
end
|
||||
@ -26,7 +26,7 @@ config: config.inspect})
|
||||
Faraday.get("#{config[:location]}/docker_container_pool/return_container/#{container.id}")
|
||||
rescue StandardError => e
|
||||
Sentry.set_extras({container: container.inspect, execution_environment: execution_environment.inspect,
|
||||
config: config.inspect})
|
||||
config: config.inspect})
|
||||
Sentry.capture_exception(e)
|
||||
nil
|
||||
end
|
||||
@ -39,7 +39,7 @@ config: config.inspect})
|
||||
Docker::Container.get(container_id) if container_id.present?
|
||||
rescue StandardError => e
|
||||
Sentry.set_extras({container_id: container_id.inspect, execution_environment: execution_environment.inspect,
|
||||
config: config.inspect})
|
||||
config: config.inspect})
|
||||
Sentry.capture_exception(e)
|
||||
nil
|
||||
end
|
||||
|
@ -133,7 +133,7 @@ namespace :detect_exercise_anomalies do
|
||||
segment.each do |user|
|
||||
reason = "{\"segment\": \"#{key}\", \"feature\": \"#{user[:reason]}\", value: \"#{user[:value]}\"}"
|
||||
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
|
||||
|
||||
@ -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])
|
||||
host = CodeOcean::Application.config.action_mailer.default_url_options[:host]
|
||||
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
|
||||
end
|
||||
log("Asked #{users_to_notify.size} users for feedback.", 2)
|
||||
|
@ -353,7 +353,7 @@ describe DockerClient, docker: true do
|
||||
end
|
||||
|
||||
describe '#send_command' do
|
||||
let(:block) { proc { nil } }
|
||||
let(:block) { proc {} }
|
||||
let(:container) { described_class.create_container(execution_environment) }
|
||||
let(:send_command) { docker_client.send(:send_command, command, container, &block) }
|
||||
|
||||
|
Reference in New Issue
Block a user