Fix Rubocop offenses
This commit is contained in:
@ -10,31 +10,29 @@ class ConsumersController < ApplicationController
|
||||
end
|
||||
private :authorize!
|
||||
|
||||
def create
|
||||
@consumer = Consumer.new(consumer_params)
|
||||
def index
|
||||
@consumers = Consumer.paginate(page: params[:page], per_page: per_page_param)
|
||||
authorize!
|
||||
create_and_respond(object: @consumer)
|
||||
end
|
||||
|
||||
def destroy
|
||||
destroy_and_respond(object: @consumer)
|
||||
end
|
||||
def show; end
|
||||
|
||||
def edit; end
|
||||
def new
|
||||
@consumer = Consumer.new(oauth_key: SecureRandom.hex, oauth_secret: SecureRandom.hex)
|
||||
authorize!
|
||||
end
|
||||
|
||||
def consumer_params
|
||||
params[:consumer].permit(:name, :oauth_key, :oauth_secret) if params[:consumer].present?
|
||||
end
|
||||
private :consumer_params
|
||||
|
||||
def index
|
||||
@consumers = Consumer.paginate(page: params[:page], per_page: per_page_param)
|
||||
authorize!
|
||||
end
|
||||
def edit; end
|
||||
|
||||
def new
|
||||
@consumer = Consumer.new(oauth_key: SecureRandom.hex, oauth_secret: SecureRandom.hex)
|
||||
def create
|
||||
@consumer = Consumer.new(consumer_params)
|
||||
authorize!
|
||||
create_and_respond(object: @consumer)
|
||||
end
|
||||
|
||||
def set_consumer
|
||||
@ -43,9 +41,11 @@ class ConsumersController < ApplicationController
|
||||
end
|
||||
private :set_consumer
|
||||
|
||||
def show; end
|
||||
|
||||
def update
|
||||
update_and_respond(object: @consumer, params: consumer_params)
|
||||
end
|
||||
|
||||
def destroy
|
||||
destroy_and_respond(object: @consumer)
|
||||
end
|
||||
end
|
||||
|
@ -12,19 +12,20 @@ class ExecutionEnvironmentsController < ApplicationController
|
||||
end
|
||||
private :authorize!
|
||||
|
||||
def create
|
||||
@execution_environment = ExecutionEnvironment.new(execution_environment_params)
|
||||
def index
|
||||
@execution_environments = ExecutionEnvironment.all.includes(:user).order(:name).paginate(page: params[:page], per_page: per_page_param)
|
||||
authorize!
|
||||
create_and_respond(object: @execution_environment)
|
||||
end
|
||||
|
||||
def destroy
|
||||
destroy_and_respond(object: @execution_environment)
|
||||
def show
|
||||
if @execution_environment.testing_framework?
|
||||
@testing_framework_adapter = TestingFrameworkAdapter.descendants.find {|klass| klass.name == @execution_environment.testing_framework }
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
# Add the current execution_environment if not already present in the list
|
||||
@docker_images |= [@execution_environment.docker_image]
|
||||
def new
|
||||
@execution_environment = ExecutionEnvironment.new
|
||||
authorize!
|
||||
end
|
||||
|
||||
def execute_command
|
||||
@ -122,21 +123,22 @@ class ExecutionEnvironmentsController < ApplicationController
|
||||
end
|
||||
private :execution_environment_params
|
||||
|
||||
def index
|
||||
@execution_environments = ExecutionEnvironment.all.includes(:user).order(:name).paginate(page: params[:page], per_page: per_page_param)
|
||||
authorize!
|
||||
def edit
|
||||
# Add the current execution_environment if not already present in the list
|
||||
@docker_images |= [@execution_environment.docker_image]
|
||||
end
|
||||
|
||||
def new
|
||||
@execution_environment = ExecutionEnvironment.new
|
||||
def create
|
||||
@execution_environment = ExecutionEnvironment.new(execution_environment_params)
|
||||
authorize!
|
||||
create_and_respond(object: @execution_environment)
|
||||
end
|
||||
|
||||
def set_docker_images
|
||||
@docker_images ||= ExecutionEnvironment.pluck(:docker_image)
|
||||
@docker_images += Runner.strategy_class.available_images
|
||||
rescue Runner::Error => e
|
||||
flash[:warning] = html_escape e.message
|
||||
flash.now[:warning] = html_escape e.message
|
||||
ensure
|
||||
@docker_images = @docker_images.sort.uniq
|
||||
end
|
||||
@ -158,16 +160,14 @@ class ExecutionEnvironmentsController < ApplicationController
|
||||
|
||||
def shell; end
|
||||
|
||||
def show
|
||||
if @execution_environment.testing_framework?
|
||||
@testing_framework_adapter = TestingFrameworkAdapter.descendants.find {|klass| klass.name == @execution_environment.testing_framework }
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
update_and_respond(object: @execution_environment, params: execution_environment_params)
|
||||
end
|
||||
|
||||
def destroy
|
||||
destroy_and_respond(object: @execution_environment)
|
||||
end
|
||||
|
||||
def sync_to_runner_management
|
||||
return unless Runner.management_active?
|
||||
|
||||
|
@ -17,6 +17,8 @@ class ExerciseCollectionsController < ApplicationController
|
||||
authorize!
|
||||
end
|
||||
|
||||
def edit; end
|
||||
|
||||
def create
|
||||
@exercise_collection = ExerciseCollection.new
|
||||
authorize!
|
||||
@ -24,18 +26,16 @@ class ExerciseCollectionsController < ApplicationController
|
||||
update_and_respond(object: @exercise_collection, params: exercise_collection_params)
|
||||
end
|
||||
|
||||
def destroy
|
||||
authorize!
|
||||
destroy_and_respond(object: @exercise_collection)
|
||||
end
|
||||
|
||||
def edit; end
|
||||
|
||||
def update
|
||||
authorize!
|
||||
update_and_respond(object: @exercise_collection, params: exercise_collection_params)
|
||||
end
|
||||
|
||||
def destroy
|
||||
authorize!
|
||||
destroy_and_respond(object: @exercise_collection)
|
||||
end
|
||||
|
||||
def statistics; end
|
||||
|
||||
private
|
||||
|
@ -73,22 +73,22 @@ class ExercisesController < ApplicationController
|
||||
|
||||
private :collect_paths
|
||||
|
||||
def create
|
||||
@exercise = Exercise.new(exercise_params&.except(:tips))
|
||||
def index
|
||||
@search = policy_scope(Exercise).ransack(params[:q])
|
||||
@exercises = @search.result.includes(:execution_environment, :user).order(:title).paginate(page: params[:page], per_page: per_page_param)
|
||||
authorize!
|
||||
end
|
||||
|
||||
def show
|
||||
# Show exercise details for teachers and admins
|
||||
end
|
||||
|
||||
def new
|
||||
@exercise = Exercise.new
|
||||
authorize!
|
||||
handle_exercise_tips
|
||||
collect_set_and_unset_exercise_tags
|
||||
return if performed?
|
||||
|
||||
create_and_respond(object: @exercise, params: exercise_params_with_tags)
|
||||
end
|
||||
|
||||
def destroy
|
||||
destroy_and_respond(object: @exercise)
|
||||
end
|
||||
|
||||
def edit; end
|
||||
|
||||
def feedback
|
||||
authorize!
|
||||
@feedbacks = @exercise.user_exercise_feedbacks.paginate(page: params[:page], per_page: per_page_param)
|
||||
@ -424,16 +424,16 @@ class ExercisesController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
@search = policy_scope(Exercise).ransack(params[:q])
|
||||
@exercises = @search.result.includes(:execution_environment, :user).order(:title).paginate(page: params[:page], per_page: per_page_param)
|
||||
authorize!
|
||||
end
|
||||
def edit; end
|
||||
|
||||
def new
|
||||
@exercise = Exercise.new
|
||||
def create
|
||||
@exercise = Exercise.new(exercise_params&.except(:tips))
|
||||
authorize!
|
||||
handle_exercise_tips
|
||||
collect_set_and_unset_exercise_tags
|
||||
return if performed?
|
||||
|
||||
create_and_respond(object: @exercise, params: exercise_params_with_tags)
|
||||
end
|
||||
|
||||
def not_authorized_for_exercise(_exception)
|
||||
@ -489,8 +489,11 @@ class ExercisesController < ApplicationController
|
||||
|
||||
private :collect_set_and_unset_exercise_tags
|
||||
|
||||
def show
|
||||
# Show exercise details for teachers and admins
|
||||
def update
|
||||
handle_exercise_tips
|
||||
return if performed?
|
||||
|
||||
update_and_respond(object: @exercise, params: exercise_params_with_tags)
|
||||
end
|
||||
|
||||
def reload
|
||||
@ -579,7 +582,7 @@ class ExercisesController < ApplicationController
|
||||
if response[:status] == 'success'
|
||||
if response[:score_sent] != @submission.normalized_score
|
||||
# Score has been reduced due to the passed deadline
|
||||
flash[:warning] = I18n.t('exercises.submit.too_late')
|
||||
flash.now[:warning] = I18n.t('exercises.submit.too_late')
|
||||
flash.keep(:warning)
|
||||
end
|
||||
redirect_after_submit
|
||||
@ -593,11 +596,8 @@ class ExercisesController < ApplicationController
|
||||
|
||||
private :transmit_lti_score
|
||||
|
||||
def update
|
||||
handle_exercise_tips
|
||||
return if performed?
|
||||
|
||||
update_and_respond(object: @exercise, params: exercise_params_with_tags)
|
||||
def destroy
|
||||
destroy_and_respond(object: @exercise)
|
||||
end
|
||||
|
||||
def study_group_dashboard
|
||||
|
@ -11,17 +11,17 @@ class FileTypesController < ApplicationController
|
||||
end
|
||||
private :authorize!
|
||||
|
||||
def create
|
||||
@file_type = FileType.new(file_type_params)
|
||||
def index
|
||||
@file_types = FileType.all.includes(:user).order(:name).paginate(page: params[:page], per_page: per_page_param)
|
||||
authorize!
|
||||
create_and_respond(object: @file_type)
|
||||
end
|
||||
|
||||
def destroy
|
||||
destroy_and_respond(object: @file_type)
|
||||
end
|
||||
def show; end
|
||||
|
||||
def edit; end
|
||||
def new
|
||||
@file_type = FileType.new
|
||||
authorize!
|
||||
end
|
||||
|
||||
def file_type_params
|
||||
if params[:file_type].present?
|
||||
@ -32,14 +32,12 @@ class FileTypesController < ApplicationController
|
||||
end
|
||||
private :file_type_params
|
||||
|
||||
def index
|
||||
@file_types = FileType.all.includes(:user).order(:name).paginate(page: params[:page], per_page: per_page_param)
|
||||
authorize!
|
||||
end
|
||||
def edit; end
|
||||
|
||||
def new
|
||||
@file_type = FileType.new
|
||||
def create
|
||||
@file_type = FileType.new(file_type_params)
|
||||
authorize!
|
||||
create_and_respond(object: @file_type)
|
||||
end
|
||||
|
||||
def set_editor_modes
|
||||
@ -56,9 +54,11 @@ class FileTypesController < ApplicationController
|
||||
end
|
||||
private :set_file_type
|
||||
|
||||
def show; end
|
||||
|
||||
def update
|
||||
update_and_respond(object: @file_type, params: file_type_params)
|
||||
end
|
||||
|
||||
def destroy
|
||||
destroy_and_respond(object: @file_type)
|
||||
end
|
||||
end
|
||||
|
@ -31,17 +31,10 @@ class InternalUsersController < ApplicationController
|
||||
end
|
||||
private :change_password
|
||||
|
||||
def create
|
||||
@user = InternalUser.new(internal_user_params)
|
||||
@user.platform_admin = platform_admin_param if current_user.admin?
|
||||
def index
|
||||
@search = InternalUser.ransack(params[:q], {auth_object: current_user})
|
||||
@users = @search.result.in_study_group_of(current_user).includes(:consumer).order(:name).paginate(page: params[:page], per_page: per_page_param)
|
||||
authorize!
|
||||
@user.send(:setup_activation)
|
||||
create_and_respond(object: @user) do
|
||||
@user.send(:send_activation_needed_email!)
|
||||
# The return value is used as a flash message. If this block does not
|
||||
# have any specific return value, a default success message is shown.
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def deliver_reset_password_instructions
|
||||
@ -53,11 +46,13 @@ class InternalUsersController < ApplicationController
|
||||
end
|
||||
private :deliver_reset_password_instructions
|
||||
|
||||
def destroy
|
||||
destroy_and_respond(object: @user)
|
||||
end
|
||||
def show; end
|
||||
|
||||
def edit; end
|
||||
def new
|
||||
@user = InternalUser.new
|
||||
authorize!
|
||||
collect_set_and_unset_study_group_memberships
|
||||
end
|
||||
|
||||
def forgot_password
|
||||
if request.get?
|
||||
@ -67,11 +62,7 @@ class InternalUsersController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
@search = InternalUser.ransack(params[:q], {auth_object: current_user})
|
||||
@users = @search.result.in_study_group_of(current_user).includes(:consumer).order(:name).paginate(page: params[:page], per_page: per_page_param)
|
||||
authorize!
|
||||
end
|
||||
def edit; end
|
||||
|
||||
def internal_user_params
|
||||
permitted_params = params.require(:internal_user).permit(:consumer_id, :email, :name, study_group_ids: []).presence || {}
|
||||
@ -95,10 +86,17 @@ class InternalUsersController < ApplicationController
|
||||
end
|
||||
private :platform_admin_param
|
||||
|
||||
def new
|
||||
@user = InternalUser.new
|
||||
def create
|
||||
@user = InternalUser.new(internal_user_params)
|
||||
@user.platform_admin = platform_admin_param if current_user.admin?
|
||||
authorize!
|
||||
collect_set_and_unset_study_group_memberships
|
||||
@user.send(:setup_activation)
|
||||
create_and_respond(object: @user) do
|
||||
@user.send(:send_activation_needed_email!)
|
||||
# The return value is used as a flash message. If this block does not
|
||||
# have any specific return value, a default success message is shown.
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def render_forgot_password_form
|
||||
@ -159,8 +157,6 @@ class InternalUsersController < ApplicationController
|
||||
|
||||
private :collect_set_and_unset_study_group_memberships
|
||||
|
||||
def show; end
|
||||
|
||||
def update
|
||||
# Let's skip the password validation if the user is edited through
|
||||
# the form by another user. Otherwise, the update might fail if an
|
||||
@ -169,4 +165,8 @@ class InternalUsersController < ApplicationController
|
||||
@user.platform_admin = platform_admin_param if current_user.admin?
|
||||
update_and_respond(object: @user, params: internal_user_params)
|
||||
end
|
||||
|
||||
def destroy
|
||||
destroy_and_respond(object: @user)
|
||||
end
|
||||
end
|
||||
|
@ -22,20 +22,19 @@ class ProxyExercisesController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
myparams = proxy_exercise_params
|
||||
myparams[:exercises] = Exercise.find(myparams[:exercise_ids].compact_blank)
|
||||
@proxy_exercise = ProxyExercise.new(myparams)
|
||||
def index
|
||||
@search = policy_scope(ProxyExercise).ransack(params[:q])
|
||||
@proxy_exercises = @search.result.order(:title).paginate(page: params[:page], per_page: per_page_param)
|
||||
authorize!
|
||||
|
||||
create_and_respond(object: @proxy_exercise)
|
||||
end
|
||||
|
||||
def destroy
|
||||
destroy_and_respond(object: @proxy_exercise)
|
||||
def show
|
||||
@search = @proxy_exercise.exercises.ransack
|
||||
@exercises = @proxy_exercise.exercises.ransack.result.order(:title)
|
||||
end
|
||||
|
||||
def edit
|
||||
def new
|
||||
@proxy_exercise = ProxyExercise.new
|
||||
@search = policy_scope(Exercise).ransack(params[:q])
|
||||
@exercises = @search.result.order(:title)
|
||||
authorize!
|
||||
@ -49,33 +48,34 @@ class ProxyExercisesController < ApplicationController
|
||||
end
|
||||
private :proxy_exercise_params
|
||||
|
||||
def index
|
||||
@search = policy_scope(ProxyExercise).ransack(params[:q])
|
||||
@proxy_exercises = @search.result.order(:title).paginate(page: params[:page], per_page: per_page_param)
|
||||
authorize!
|
||||
end
|
||||
|
||||
def new
|
||||
@proxy_exercise = ProxyExercise.new
|
||||
def edit
|
||||
@search = policy_scope(Exercise).ransack(params[:q])
|
||||
@exercises = @search.result.order(:title)
|
||||
authorize!
|
||||
end
|
||||
|
||||
def create
|
||||
myparams = proxy_exercise_params
|
||||
myparams[:exercises] = Exercise.find(myparams[:exercise_ids].compact_blank)
|
||||
@proxy_exercise = ProxyExercise.new(myparams)
|
||||
authorize!
|
||||
|
||||
create_and_respond(object: @proxy_exercise)
|
||||
end
|
||||
|
||||
def set_exercise_and_authorize
|
||||
@proxy_exercise = ProxyExercise.find(params[:id])
|
||||
authorize!
|
||||
end
|
||||
private :set_exercise_and_authorize
|
||||
|
||||
def show
|
||||
@search = @proxy_exercise.exercises.ransack
|
||||
@exercises = @proxy_exercise.exercises.ransack.result.order(:title)
|
||||
end
|
||||
|
||||
def update
|
||||
myparams = proxy_exercise_params
|
||||
myparams[:exercises] = Exercise.find(myparams[:exercise_ids].compact_blank)
|
||||
update_and_respond(object: @proxy_exercise, params: myparams)
|
||||
end
|
||||
|
||||
def destroy
|
||||
destroy_and_respond(object: @proxy_exercise)
|
||||
end
|
||||
end
|
||||
|
@ -11,15 +11,8 @@ class SessionsController < ApplicationController
|
||||
skip_after_action :verify_authorized
|
||||
skip_before_action :verify_authenticity_token, only: :create_through_lti
|
||||
|
||||
def create
|
||||
if login(params[:email], params[:password], params[:remember_me])
|
||||
# We set the user's default study group to the "internal" group (no external id) for the given consumer.
|
||||
session[:study_group_id] = current_user.study_groups.find_by(external_id: nil)&.id
|
||||
redirect_back_or_to(:root, notice: t('.success'))
|
||||
else
|
||||
flash.now[:danger] = t('.failure')
|
||||
render(:new)
|
||||
end
|
||||
def new
|
||||
redirect_to(:root, alert: t('shared.already_signed_in')) if current_user
|
||||
end
|
||||
|
||||
def create_through_lti
|
||||
@ -34,13 +27,15 @@ class SessionsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if current_user&.external_user?
|
||||
clear_lti_session_data
|
||||
def create
|
||||
if login(params[:email], params[:password], params[:remember_me])
|
||||
# We set the user's default study group to the "internal" group (no external id) for the given consumer.
|
||||
session[:study_group_id] = current_user.study_groups.find_by(external_id: nil)&.id
|
||||
redirect_back_or_to(:root, notice: t('.success'))
|
||||
else
|
||||
logout
|
||||
flash.now[:danger] = t('.failure')
|
||||
render(:new)
|
||||
end
|
||||
redirect_to(:root, notice: t('.success'))
|
||||
end
|
||||
|
||||
def destroy_through_lti
|
||||
@ -52,7 +47,12 @@ class SessionsController < ApplicationController
|
||||
clear_lti_session_data(@submission.exercise_id, @submission.user_id)
|
||||
end
|
||||
|
||||
def new
|
||||
redirect_to(:root, alert: t('shared.already_signed_in')) if current_user
|
||||
def destroy
|
||||
if current_user&.external_user?
|
||||
clear_lti_session_data
|
||||
else
|
||||
logout
|
||||
end
|
||||
redirect_to(:root, notice: t('.success'))
|
||||
end
|
||||
end
|
||||
|
@ -19,10 +19,10 @@ class SubmissionsController < ApplicationController
|
||||
# We want to serve .js files without raising a `ActionController::InvalidCrossOriginRequest` exception
|
||||
skip_before_action :verify_authenticity_token, only: %i[render_file download_file]
|
||||
|
||||
def create
|
||||
@submission = Submission.new(submission_params)
|
||||
def index
|
||||
@search = Submission.ransack(params[:q])
|
||||
@submissions = @search.result.includes(:exercise, :user).paginate(page: params[:page], per_page: per_page_param)
|
||||
authorize!
|
||||
create_and_respond(object: @submission)
|
||||
end
|
||||
|
||||
def download
|
||||
@ -71,11 +71,7 @@ class SubmissionsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
@search = Submission.ransack(params[:q])
|
||||
@submissions = @search.result.includes(:exercise, :user).paginate(page: params[:page], per_page: per_page_param)
|
||||
authorize!
|
||||
end
|
||||
def show; end
|
||||
|
||||
def render_file
|
||||
# Set @current_user with a new *learner* for Pundit checks
|
||||
@ -250,7 +246,11 @@ class SubmissionsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def show; end
|
||||
def create
|
||||
@submission = Submission.new(submission_params)
|
||||
authorize!
|
||||
create_and_respond(object: @submission)
|
||||
end
|
||||
|
||||
def statistics; end
|
||||
|
||||
|
@ -10,31 +10,29 @@ class TagsController < ApplicationController
|
||||
end
|
||||
private :authorize!
|
||||
|
||||
def create
|
||||
@tag = Tag.new(tag_params)
|
||||
def index
|
||||
@tags = Tag.all.paginate(page: params[:page], per_page: per_page_param)
|
||||
authorize!
|
||||
create_and_respond(object: @tag)
|
||||
end
|
||||
|
||||
def destroy
|
||||
destroy_and_respond(object: @tag)
|
||||
end
|
||||
def show; end
|
||||
|
||||
def edit; end
|
||||
def new
|
||||
@tag = Tag.new
|
||||
authorize!
|
||||
end
|
||||
|
||||
def tag_params
|
||||
params[:tag].permit(:name) if params[:tag].present?
|
||||
end
|
||||
private :tag_params
|
||||
|
||||
def index
|
||||
@tags = Tag.all.paginate(page: params[:page], per_page: per_page_param)
|
||||
authorize!
|
||||
end
|
||||
def edit; end
|
||||
|
||||
def new
|
||||
@tag = Tag.new
|
||||
def create
|
||||
@tag = Tag.new(tag_params)
|
||||
authorize!
|
||||
create_and_respond(object: @tag)
|
||||
end
|
||||
|
||||
def set_tag
|
||||
@ -43,12 +41,14 @@ class TagsController < ApplicationController
|
||||
end
|
||||
private :set_tag
|
||||
|
||||
def show; end
|
||||
|
||||
def update
|
||||
update_and_respond(object: @tag, params: tag_params)
|
||||
end
|
||||
|
||||
def destroy
|
||||
destroy_and_respond(object: @tag)
|
||||
end
|
||||
|
||||
def to_s
|
||||
name
|
||||
end
|
||||
|
@ -11,17 +11,17 @@ class TipsController < ApplicationController
|
||||
end
|
||||
private :authorize!
|
||||
|
||||
def create
|
||||
@tip = Tip.new(tip_params)
|
||||
def index
|
||||
@tips = Tip.all.paginate(page: params[:page], per_page: per_page_param)
|
||||
authorize!
|
||||
create_and_respond(object: @tip)
|
||||
end
|
||||
|
||||
def destroy
|
||||
destroy_and_respond(object: @tip)
|
||||
end
|
||||
def show; end
|
||||
|
||||
def edit; end
|
||||
def new
|
||||
@tip = Tip.new
|
||||
authorize!
|
||||
end
|
||||
|
||||
def tip_params
|
||||
return if params[:tip].blank?
|
||||
@ -33,14 +33,12 @@ class TipsController < ApplicationController
|
||||
end
|
||||
private :tip_params
|
||||
|
||||
def index
|
||||
@tips = Tip.all.paginate(page: params[:page], per_page: per_page_param)
|
||||
authorize!
|
||||
end
|
||||
def edit; end
|
||||
|
||||
def new
|
||||
@tip = Tip.new
|
||||
def create
|
||||
@tip = Tip.new(tip_params)
|
||||
authorize!
|
||||
create_and_respond(object: @tip)
|
||||
end
|
||||
|
||||
def set_tip
|
||||
@ -49,12 +47,14 @@ class TipsController < ApplicationController
|
||||
end
|
||||
private :set_tip
|
||||
|
||||
def show; end
|
||||
|
||||
def update
|
||||
update_and_respond(object: @tip, params: tip_params)
|
||||
end
|
||||
|
||||
def destroy
|
||||
destroy_and_respond(object: @tip)
|
||||
end
|
||||
|
||||
def set_file_types
|
||||
@file_types = FileType.all.order(:name)
|
||||
end
|
||||
|
@ -22,6 +22,21 @@ class UserExerciseFeedbacksController < ApplicationController
|
||||
[4, t('user_exercise_feedback.estimated_time_more_30')]]
|
||||
end
|
||||
|
||||
def new
|
||||
exercise_id = if params[:user_exercise_feedback].nil?
|
||||
params[:exercise_id]
|
||||
else
|
||||
params[:user_exercise_feedback][:exercise_id]
|
||||
end
|
||||
@exercise = Exercise.find(exercise_id)
|
||||
@uef = UserExerciseFeedback.find_or_initialize_by(user: current_user, exercise: @exercise)
|
||||
authorize!
|
||||
end
|
||||
|
||||
def edit
|
||||
authorize!
|
||||
end
|
||||
|
||||
def create
|
||||
Sentry.set_extras(params: uef_params)
|
||||
|
||||
@ -46,32 +61,12 @@ class UserExerciseFeedbacksController < ApplicationController
|
||||
end
|
||||
create_and_respond(object: @uef, path: proc { path })
|
||||
else
|
||||
flash[:danger] = t('shared.message_failure')
|
||||
flash.now[:danger] = t('shared.message_failure')
|
||||
redirect_back fallback_location: user_exercise_feedback_path(@uef)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
authorize!
|
||||
destroy_and_respond(object: @uef)
|
||||
end
|
||||
|
||||
def edit
|
||||
authorize!
|
||||
end
|
||||
|
||||
def new
|
||||
exercise_id = if params[:user_exercise_feedback].nil?
|
||||
params[:exercise_id]
|
||||
else
|
||||
params[:user_exercise_feedback][:exercise_id]
|
||||
end
|
||||
@exercise = Exercise.find(exercise_id)
|
||||
@uef = UserExerciseFeedback.find_or_initialize_by(user: current_user, exercise: @exercise)
|
||||
authorize!
|
||||
end
|
||||
|
||||
def update
|
||||
submission = begin
|
||||
current_user.submissions.where(exercise_id: @exercise.id).order('created_at DESC').final.first
|
||||
@ -89,11 +84,16 @@ class UserExerciseFeedbacksController < ApplicationController
|
||||
end
|
||||
update_and_respond(object: @uef, params: uef_params, path: path)
|
||||
else
|
||||
flash[:danger] = t('shared.message_failure')
|
||||
flash.now[:danger] = t('shared.message_failure')
|
||||
redirect_back fallback_location: user_exercise_feedback_path(@uef)
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
authorize!
|
||||
destroy_and_respond(object: @uef)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def authorize!
|
||||
|
@ -7,17 +7,17 @@ namespace :export_exercises do
|
||||
successful_exports = []
|
||||
failed_exports = []
|
||||
Exercise.where(public: true).each do |exercise|
|
||||
puts "Exporting exercise \##{exercise.id}"
|
||||
puts "Exporting exercise ##{exercise.id}"
|
||||
error = ExerciseService::PushExternal.call(
|
||||
zip: ProformaService::ExportTask.call(exercise: exercise),
|
||||
codeharbor_link: codeharbor_link
|
||||
)
|
||||
if error.nil?
|
||||
successful_exports << exercise.id
|
||||
puts "Successfully exported exercise\# #{exercise.id}"
|
||||
puts "Successfully exported exercise# #{exercise.id}"
|
||||
else
|
||||
failed_exports << exercise.id
|
||||
puts "An error occured during export of exercise\# #{exercise.id}: #{error}"
|
||||
puts "An error occured during export of exercise# #{exercise.id}: #{error}"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe PingController, type: :controller do
|
||||
RSpec.describe PingController do
|
||||
describe 'index' do
|
||||
it 'returns the wanted page and answer with HTTP Status 200' do
|
||||
get :index
|
||||
|
@ -29,6 +29,6 @@ describe 'Request_for_Comments' do
|
||||
|
||||
it 'contains a filter for study group in the view' do
|
||||
visit(request_for_comments_path)
|
||||
expect(page.find_by_id('q_submission_study_group_id_in')).not_to be_nil # rubocop:disable Rails/DynamicFindBy
|
||||
expect(page.find_by_id('q_submission_study_group_id_in')).not_to be_nil
|
||||
end
|
||||
end
|
||||
|
@ -5,7 +5,7 @@ require 'pathname'
|
||||
|
||||
describe Runner::Strategy::DockerContainerPool do
|
||||
let(:runner_id) { attributes_for(:runner)[:runner_id] }
|
||||
let(:execution_environment) { create :ruby }
|
||||
let(:execution_environment) { create(:ruby) }
|
||||
let(:container_pool) { described_class.new(runner_id, execution_environment) }
|
||||
let(:docker_container_pool_url) { 'https://localhost:1234' }
|
||||
let(:config) { {url: docker_container_pool_url, unused_runner_expiration_time: 180} }
|
||||
|
@ -4,7 +4,7 @@ require 'rails_helper'
|
||||
|
||||
describe Runner::Strategy::Poseidon do
|
||||
let(:runner_id) { attributes_for(:runner)[:runner_id] }
|
||||
let(:execution_environment) { create :ruby }
|
||||
let(:execution_environment) { create(:ruby) }
|
||||
let(:poseidon) { described_class.new(runner_id, execution_environment) }
|
||||
let(:error_message) { 'test error message' }
|
||||
let(:response_body) { nil }
|
||||
|
@ -8,7 +8,7 @@ describe Runner do
|
||||
let(:strategy) { instance_double(strategy_class) }
|
||||
|
||||
describe 'attribute validation' do
|
||||
let(:runner) { create :runner }
|
||||
let(:runner) { create(:runner) }
|
||||
|
||||
it 'validates the presence of the runner id' do
|
||||
described_class.skip_callback(:validation, :before, :request_id)
|
||||
@ -164,8 +164,8 @@ describe Runner do
|
||||
end
|
||||
|
||||
describe 'creation' do
|
||||
let(:user) { create :external_user }
|
||||
let(:execution_environment) { create :ruby }
|
||||
let(:user) { create(:external_user) }
|
||||
let(:execution_environment) { create(:ruby) }
|
||||
let(:create_action) { -> { described_class.create(user: user, execution_environment: execution_environment) } }
|
||||
|
||||
it 'requests a runner id from the runner management' do
|
||||
@ -194,7 +194,7 @@ describe Runner do
|
||||
end
|
||||
|
||||
describe '#request_new_id' do
|
||||
let(:runner) { create :runner }
|
||||
let(:runner) { create(:runner) }
|
||||
|
||||
context 'when the environment is available in the runner management' do
|
||||
it 'requests the runner management' do
|
||||
@ -242,8 +242,8 @@ describe Runner do
|
||||
end
|
||||
|
||||
describe '::for' do
|
||||
let(:user) { create :external_user }
|
||||
let(:exercise) { create :fibonacci }
|
||||
let(:user) { create(:external_user) }
|
||||
let(:exercise) { create(:fibonacci) }
|
||||
|
||||
context 'when the runner could not be saved' do
|
||||
before { allow(strategy_class).to receive(:request_from_management).and_return(nil) }
|
||||
|
@ -126,7 +126,7 @@ describe Submission do
|
||||
end
|
||||
|
||||
describe '#calculate_score' do
|
||||
let(:runner) { create :runner }
|
||||
let(:runner) { create(:runner) }
|
||||
|
||||
before do
|
||||
allow(Runner).to receive(:for).and_return(runner)
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe PingController, type: :routing do
|
||||
describe PingController do
|
||||
context 'with routes to #show' do
|
||||
it { expect(get: '/ping').to route_to('ping#index', format: :json) }
|
||||
end
|
Reference in New Issue
Block a user