Fix rubocop offenses - Requires Ruby 3.1+
This commit is contained in:
@ -115,16 +115,16 @@ class ApplicationController < ActionController::Base
|
||||
redirect_back fallback_location: :root, allow_other_host: false, alert: message
|
||||
end
|
||||
end
|
||||
format.json { render json: {error: message}, status: status }
|
||||
format.json { render json: {error: message}, status: }
|
||||
end
|
||||
end
|
||||
private :render_error
|
||||
|
||||
def switch_locale(&action)
|
||||
def switch_locale(&)
|
||||
session[:locale] = sanitize_locale(params[:custom_locale] || params[:locale] || session[:locale])
|
||||
locale = session[:locale] || I18n.default_locale
|
||||
Sentry.set_extras(locale: locale)
|
||||
I18n.with_locale(locale, &action)
|
||||
Sentry.set_extras(locale:)
|
||||
I18n.with_locale(locale, &)
|
||||
end
|
||||
private :switch_locale
|
||||
|
||||
|
@ -60,7 +60,7 @@ module CodeOcean
|
||||
yield if block_given?
|
||||
path = options[:path].try(:call) || @object
|
||||
respond_with_valid_object(format, notice: t('shared.object_created', model: @object.class.model_name.human),
|
||||
path: path, status: :created)
|
||||
path:, status: :created)
|
||||
else
|
||||
filename = "#{@object.path || ''}/#{@object.name || ''}#{@object.file_type.try(:file_extension) || ''}"
|
||||
format.html do
|
||||
|
@ -11,7 +11,7 @@ module CommonBehavior
|
||||
notice = result if result.present?
|
||||
end
|
||||
path = options[:path].try(:call) || @object
|
||||
respond_with_valid_object(format, notice: notice, path: path, status: :created)
|
||||
respond_with_valid_object(format, notice:, path:, status: :created)
|
||||
else
|
||||
respond_with_invalid_object(format, template: :new)
|
||||
end
|
||||
@ -51,7 +51,7 @@ module CommonBehavior
|
||||
notice = result if result.present?
|
||||
end
|
||||
path = options[:path] || @object
|
||||
respond_with_valid_object(format, notice: notice, path: path, status: :ok)
|
||||
respond_with_valid_object(format, notice:, path:, status: :ok)
|
||||
else
|
||||
respond_with_invalid_object(format, template: :edit)
|
||||
end
|
||||
|
@ -16,14 +16,14 @@ module FileConversion
|
||||
path = File.dirname(file['name']).sub(%r{^(?>\./|\.)}, '').presence
|
||||
file_type = all_file_types.detect {|ft| ft.file_extension == extension } || FileType.new(file_extension: extension)
|
||||
CodeOcean::File.new(
|
||||
name: name,
|
||||
path: path,
|
||||
name:,
|
||||
path:,
|
||||
size: file['size'],
|
||||
owner: file['owner'],
|
||||
group: file['group'],
|
||||
permissions: file['permissions'],
|
||||
updated_at: file['modificationTime'],
|
||||
file_type: file_type
|
||||
file_type:
|
||||
)
|
||||
end
|
||||
[augment_files_for_download(files), directories]
|
||||
|
@ -124,7 +124,7 @@ module RedirectBehavior
|
||||
session: session.to_hash,
|
||||
submission: @submission.inspect,
|
||||
params: params.as_json,
|
||||
current_user: current_user,
|
||||
current_user:,
|
||||
lti_exercise_id: session[:lti_exercise_id],
|
||||
lti_parameters_id: session[:lti_parameters_id]
|
||||
)
|
||||
|
@ -115,8 +115,8 @@ class ExecutionEnvironmentsController < ApplicationController
|
||||
end
|
||||
|
||||
render locals: {
|
||||
working_time_statistics: working_time_statistics,
|
||||
user_statistics: user_statistics,
|
||||
working_time_statistics:,
|
||||
user_statistics:,
|
||||
}
|
||||
end
|
||||
|
||||
@ -132,7 +132,7 @@ class ExecutionEnvironmentsController < ApplicationController
|
||||
params[:execution_environment]
|
||||
.permit(:docker_image, :editor_mode, :file_extension, :file_type_id, :help, :indent_size, :memory_limit, :cpu_limit, :name,
|
||||
:network_enabled, :privileged_execution, :permitted_execution_time, :pool_size, :run_command, :test_command, :testing_framework)
|
||||
.merge(user_id: current_user.id, user_type: current_user.class.name, exposed_ports: exposed_ports)
|
||||
.merge(user_id: current_user.id, user_type: current_user.class.name, exposed_ports:)
|
||||
end
|
||||
end
|
||||
private :execution_environment_params
|
||||
|
@ -128,15 +128,15 @@ class ExercisesController < ApplicationController
|
||||
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:}),
|
||||
}
|
||||
@exercise.save
|
||||
else
|
||||
render json: {
|
||||
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:),
|
||||
actions: render_to_string(partial: 'export_actions',
|
||||
locals: {exercise: @exercise, exported: true, error: error}),
|
||||
locals: {exercise: @exercise, exported: true, error:}),
|
||||
}
|
||||
end
|
||||
end
|
||||
@ -146,7 +146,7 @@ class ExercisesController < ApplicationController
|
||||
return render json: {}, status: :unauthorized if user.nil?
|
||||
|
||||
uuid = params[:uuid]
|
||||
exercise = Exercise.find_by(uuid: uuid)
|
||||
exercise = Exercise.find_by(uuid:)
|
||||
|
||||
return render json: {uuid_found: false} if exercise.nil?
|
||||
return render json: {uuid_found: true, update_right: false} unless ExercisePolicy.new(user, exercise).update?
|
||||
@ -163,7 +163,7 @@ class ExercisesController < ApplicationController
|
||||
return render json: {}, status: :unauthorized if user.nil?
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
exercise = ::ProformaService::Import.call(zip: tempfile, user: user)
|
||||
exercise = ::ProformaService::Import.call(zip: tempfile, user:)
|
||||
exercise.save!
|
||||
render json: {}, status: :created
|
||||
end
|
||||
@ -185,7 +185,7 @@ class ExercisesController < ApplicationController
|
||||
private :user_from_api_key
|
||||
|
||||
def user_by_codeharbor_token(api_key)
|
||||
link = CodeharborLink.find_by(api_key: api_key)
|
||||
link = CodeharborLink.find_by(api_key:)
|
||||
link&.user
|
||||
end
|
||||
|
||||
@ -394,8 +394,8 @@ class ExercisesController < ApplicationController
|
||||
def working_times
|
||||
working_time_accumulated = @exercise.accumulated_working_time_for_only(current_user)
|
||||
working_time_75_percentile = @exercise.get_quantiles([0.75]).first
|
||||
render(json: {working_time_75_percentile: working_time_75_percentile,
|
||||
working_time_accumulated: working_time_accumulated})
|
||||
render(json: {working_time_75_percentile:,
|
||||
working_time_accumulated:})
|
||||
end
|
||||
|
||||
def intervention
|
||||
@ -404,7 +404,7 @@ class ExercisesController < ApplicationController
|
||||
render(json: {success: 'false', error: "undefined intervention #{params[:intervention_type]}"})
|
||||
else
|
||||
uei = UserExerciseIntervention.new(
|
||||
user: current_user, exercise: @exercise, intervention: intervention,
|
||||
user: current_user, exercise: @exercise, intervention:,
|
||||
accumulated_worktime_s: @exercise.accumulated_working_time_for_only(current_user)
|
||||
)
|
||||
uei.save
|
||||
@ -483,7 +483,7 @@ class ExercisesController < ApplicationController
|
||||
checked_tags = checked_exercise_tags.collect(&:tag).to_set
|
||||
unchecked_tags = Tag.all.to_set.subtract checked_tags
|
||||
@exercise_tags = checked_exercise_tags + unchecked_tags.collect do |tag|
|
||||
ExerciseTag.new(exercise: @exercise, tag: tag)
|
||||
ExerciseTag.new(exercise: @exercise, tag:)
|
||||
end
|
||||
end
|
||||
|
||||
@ -522,7 +522,7 @@ class ExercisesController < ApplicationController
|
||||
end
|
||||
|
||||
render locals: {
|
||||
user_statistics: user_statistics,
|
||||
user_statistics:,
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -72,7 +72,7 @@ class ExternalUsersController < ApplicationController
|
||||
end
|
||||
|
||||
render locals: {
|
||||
statistics: statistics,
|
||||
statistics:,
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -41,7 +41,7 @@ class FileTypesController < ApplicationController
|
||||
end
|
||||
|
||||
def set_editor_modes
|
||||
@editor_modes = Dir.glob('vendor/assets/javascripts/ace/mode-*.js').sort.map do |filename|
|
||||
@editor_modes = Dir.glob('vendor/assets/javascripts/ace/mode-*.js').map do |filename|
|
||||
name = filename.gsub(%r{\w+/|mode-|.js$}, '')
|
||||
[name, "ace/mode/#{name}"]
|
||||
end
|
||||
|
@ -28,7 +28,7 @@ class FlowrController < ApplicationController
|
||||
# once the programming language model becomes available, the language name can be added to the query to
|
||||
# produce more relevant results
|
||||
query = attributes.map(&:value).join(' ')
|
||||
{submission: submission, error: error, attributes: attributes, query: query}
|
||||
{submission:, error:, attributes:, query:}
|
||||
end
|
||||
|
||||
# Always return JSON
|
||||
|
@ -151,7 +151,7 @@ class InternalUsersController < ApplicationController
|
||||
checked_study_groups = checked_study_group_memberships.collect(&:study_group).sort.to_set
|
||||
unchecked_study_groups = StudyGroup.all.order(name: :asc).to_set.subtract checked_study_groups
|
||||
@study_group_memberships = checked_study_group_memberships + unchecked_study_groups.collect do |study_group|
|
||||
StudyGroupMembership.new(user: @user, study_group: study_group)
|
||||
StudyGroupMembership.new(user: @user, study_group:)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -26,14 +26,14 @@ class LiveStreamsController < ApplicationController
|
||||
runner = Runner.for(current_user, @execution_environment)
|
||||
fallback_location = shell_execution_environment_path(@execution_environment)
|
||||
privileged = params[:sudo] || @execution_environment.privileged_execution?
|
||||
send_runner_file(runner, desired_file, fallback_location, privileged: privileged)
|
||||
send_runner_file(runner, desired_file, fallback_location, privileged:)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def send_runner_file(runner, desired_file, redirect_fallback = root_path, privileged: false)
|
||||
filename = File.basename(desired_file)
|
||||
send_stream(filename: filename, type: 'application/octet-stream', disposition: 'attachment') do |stream|
|
||||
send_stream(filename:, type: 'application/octet-stream', disposition: 'attachment') do |stream|
|
||||
runner.download_file desired_file, privileged_execution: privileged do |chunk, overall_size, _content_type|
|
||||
unless response.committed?
|
||||
# Disable Rack::ETag, which would otherwise cause the response to be cached
|
||||
|
@ -15,7 +15,7 @@ class RemoteEvaluationController < ApplicationController
|
||||
else
|
||||
201
|
||||
end
|
||||
render json: result, status: status
|
||||
render json: result, status:
|
||||
end
|
||||
|
||||
# POST /submit
|
||||
@ -29,7 +29,7 @@ class RemoteEvaluationController < ApplicationController
|
||||
status = result[:status]
|
||||
end
|
||||
|
||||
render json: result, status: status
|
||||
render json: result, status:
|
||||
end
|
||||
|
||||
def try_lti
|
||||
@ -62,7 +62,7 @@ class RemoteEvaluationController < ApplicationController
|
||||
|
||||
def create_and_score_submission(cause)
|
||||
validation_token = remote_evaluation_params[:validation_token]
|
||||
if (remote_evaluation_mapping = RemoteEvaluationMapping.find_by(validation_token: validation_token))
|
||||
if (remote_evaluation_mapping = RemoteEvaluationMapping.find_by(validation_token:))
|
||||
@submission = Submission.create(build_submission_params(cause, remote_evaluation_mapping))
|
||||
@submission.calculate_score
|
||||
else
|
||||
|
@ -146,7 +146,7 @@ class SubmissionsController < ApplicationController
|
||||
end
|
||||
else
|
||||
Rails.logger.info("Unknown command from client: #{event[:cmd]}")
|
||||
Sentry.set_extras(event: event)
|
||||
Sentry.set_extras(event:)
|
||||
Sentry.capture_message("Unknown command from client: #{event[:cmd]}")
|
||||
end
|
||||
rescue JSON::ParserError => e
|
||||
@ -183,19 +183,19 @@ class SubmissionsController < ApplicationController
|
||||
exit_statement =
|
||||
if @testrun[:output].empty? && exit_code.zero?
|
||||
@testrun[:status] = :ok
|
||||
t('exercises.implement.no_output_exit_successful', timestamp: l(Time.zone.now, format: :short), exit_code: exit_code)
|
||||
t('exercises.implement.no_output_exit_successful', timestamp: l(Time.zone.now, format: :short), exit_code:)
|
||||
elsif @testrun[:output].empty?
|
||||
@testrun[:status] = :failed
|
||||
t('exercises.implement.no_output_exit_failure', timestamp: l(Time.zone.now, format: :short), exit_code: exit_code)
|
||||
t('exercises.implement.no_output_exit_failure', timestamp: l(Time.zone.now, format: :short), exit_code:)
|
||||
elsif exit_code.zero?
|
||||
@testrun[:status] = :ok
|
||||
"\n#{t('exercises.implement.exit_successful', timestamp: l(Time.zone.now, format: :short), exit_code: exit_code)}"
|
||||
"\n#{t('exercises.implement.exit_successful', timestamp: l(Time.zone.now, format: :short), exit_code:)}"
|
||||
else
|
||||
@testrun[:status] = :failed
|
||||
"\n#{t('exercises.implement.exit_failure', timestamp: l(Time.zone.now, format: :short), exit_code: exit_code)}"
|
||||
"\n#{t('exercises.implement.exit_failure', timestamp: l(Time.zone.now, format: :short), exit_code:)}"
|
||||
end
|
||||
stream = @testrun[:status] == :ok ? :stdout : :stderr
|
||||
send_and_store client_socket, {cmd: :write, stream: stream, data: "#{exit_statement}\n"}
|
||||
send_and_store client_socket, {cmd: :write, stream:, data: "#{exit_statement}\n"}
|
||||
if exit_code == 137
|
||||
send_and_store client_socket, {cmd: :status, status: :out_of_memory}
|
||||
@testrun[:status] = :out_of_memory
|
||||
@ -307,8 +307,8 @@ class SubmissionsController < ApplicationController
|
||||
exercise_id = @submission.exercise_id
|
||||
|
||||
remote_evaluation_mapping = RemoteEvaluationMapping.create(
|
||||
user: user,
|
||||
exercise_id: exercise_id,
|
||||
user:,
|
||||
exercise_id:,
|
||||
study_group_id: session[:study_group_id]
|
||||
)
|
||||
|
||||
@ -370,7 +370,7 @@ class SubmissionsController < ApplicationController
|
||||
testrun = Testrun.create!(
|
||||
file: @file,
|
||||
passed: @testrun[:passed],
|
||||
cause: cause,
|
||||
cause:,
|
||||
submission: @submission,
|
||||
exit_code: @testrun[:exit_code], # might be nil, e.g., when the run did not finish
|
||||
status: @testrun[:status] || :failed,
|
||||
@ -379,7 +379,7 @@ class SubmissionsController < ApplicationController
|
||||
waiting_for_container_time: @testrun[:waiting_for_container_time]
|
||||
)
|
||||
TestrunMessage.create_for(testrun, @testrun[:messages])
|
||||
TestrunExecutionEnvironment.create(testrun: testrun, execution_environment: @submission.used_execution_environment)
|
||||
TestrunExecutionEnvironment.create(testrun:, execution_environment: @submission.used_execution_environment)
|
||||
end
|
||||
|
||||
def send_hints(tubesock, errors)
|
||||
@ -430,10 +430,10 @@ class SubmissionsController < ApplicationController
|
||||
parsed[:stream] = parsed[:stream].to_sym if parsed.key? :stream
|
||||
parsed
|
||||
else
|
||||
{cmd: :write, stream: stream, data: data}
|
||||
{cmd: :write, stream:, data:}
|
||||
end
|
||||
rescue JSON::ParserError
|
||||
{cmd: :write, stream: stream, data: data}
|
||||
{cmd: :write, stream:, data:}
|
||||
end
|
||||
|
||||
def augment_files_for_download(files)
|
||||
|
@ -58,7 +58,7 @@ class SubscriptionsController < ApplicationController
|
||||
study_group_id = current_user.try(:current_study_group_id)
|
||||
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, study_group_id: study_group_id, deleted: false)
|
||||
user_type: current_user_class_name, study_group_id:, deleted: false)
|
||||
end
|
||||
end
|
||||
private :subscription_params
|
||||
|
@ -82,7 +82,7 @@ class UserExerciseFeedbacksController < ApplicationController
|
||||
else
|
||||
implement_exercise_path(@exercise)
|
||||
end
|
||||
update_and_respond(object: @uef, params: uef_params, path: path)
|
||||
update_and_respond(object: @uef, params: uef_params, path:)
|
||||
else
|
||||
flash.now[:danger] = t('shared.message_failure')
|
||||
redirect_back fallback_location: user_exercise_feedback_path(@uef)
|
||||
@ -126,15 +126,15 @@ class UserExerciseFeedbacksController < ApplicationController
|
||||
user_id = current_user.id
|
||||
user_type = current_user.class.name
|
||||
latest_submission = Submission
|
||||
.where(user_id: user_id, user_type: user_type, exercise_id: exercise_id)
|
||||
.where(user_id:, user_type:, exercise_id:)
|
||||
.order(created_at: :desc).final.first
|
||||
|
||||
authorize(latest_submission, :show?)
|
||||
|
||||
params[:user_exercise_feedback]
|
||||
.permit(:feedback_text, :difficulty, :exercise_id, :user_estimated_worktime)
|
||||
.merge(user_id: user_id,
|
||||
user_type: user_type,
|
||||
.merge(user_id:,
|
||||
user_type:,
|
||||
submission: latest_submission,
|
||||
normalized_score: latest_submission&.normalized_score)
|
||||
end
|
||||
|
Reference in New Issue
Block a user