Fix Sorcery conflict for redirect_back_or_to

See https://github.com/Sorcery/sorcery/issues/296
This commit is contained in:
Sebastian Serth
2023-12-22 00:39:39 +01:00
committed by Sebastian Serth
parent c280a58214
commit 7a1330323c
5 changed files with 18 additions and 7 deletions

View File

@ -313,8 +313,8 @@ class ExercisesController < ApplicationController
session.delete(:pair_programming) session.delete(:pair_programming)
@current_contributor = current_user @current_contributor = current_user
else else
return redirect_back( return redirect_back_or_to(
fallback_location: implement_exercise_path(current_contributor.exercise), implement_exercise_path(current_contributor.exercise),
alert: t('exercises.implement.existing_programming_group', exercise: current_contributor.exercise.title) alert: t('exercises.implement.existing_programming_group', exercise: current_contributor.exercise.title)
) )
end end
@ -323,7 +323,7 @@ class ExercisesController < ApplicationController
session[:pg_id] = pg.id session[:pg_id] = pg.id
@current_contributor = pg @current_contributor = pg
elsif session[:pg_id].blank? && session[:pair_programming] == 'mandatory' elsif session[:pg_id].blank? && session[:pair_programming] == 'mandatory'
return redirect_back(fallback_location: new_exercise_programming_group_path(@exercise)) return redirect_back_or_to(new_exercise_programming_group_path(@exercise))
elsif session[:pg_id].blank? && session[:pair_programming] == 'optional' && current_user.submissions.where(study_group_id: current_user.current_study_group_id, exercise: @exercise).none? elsif session[:pg_id].blank? && session[:pair_programming] == 'optional' && current_user.submissions.where(study_group_id: current_user.current_study_group_id, exercise: @exercise).none?
Event.find_or_create_by(category: 'pp_work_alone', user: current_user, exercise: @exercise, data: nil, file_id: nil) Event.find_or_create_by(category: 'pp_work_alone', user: current_user, exercise: @exercise, data: nil, file_id: nil)
current_user.pair_programming_waiting_users&.find_by(exercise: @exercise)&.update(status: :worked_alone) current_user.pair_programming_waiting_users&.find_by(exercise: @exercise)&.update(status: :worked_alone)

View File

@ -21,7 +21,7 @@ class LiveStreamsController < ApplicationController
# Using the submission ID parameter would allow looking up the corresponding exercise ID # Using the submission ID parameter would allow looking up the corresponding exercise ID
# Therefore, we just redirect to the root_path, but actually expect to redirect back (that should work!) # Therefore, we just redirect to the root_path, but actually expect to redirect back (that should work!)
skip_authorization skip_authorization
redirect_back(fallback_location: root_path, allow_other_host: true, alert: t('exercises.download_file_tree.gone')) redirect_back_or_to(root_path, allow_other_host: true, alert: t('exercises.download_file_tree.gone'))
else else
desired_file = params[:filename].to_s desired_file = params[:filename].to_s
runner = Runner.for(current_contributor, @submission.exercise.execution_environment) runner = Runner.for(current_contributor, @submission.exercise.execution_environment)
@ -65,7 +65,7 @@ class LiveStreamsController < ApplicationController
end end
end end
rescue Runner::Error rescue Runner::Error
redirect_back(fallback_location: redirect_fallback, alert: t('exercises.download_file_tree.gone')) redirect_back_or_to(redirect_fallback, alert: t('exercises.download_file_tree.gone'))
end end
end end
end end

View File

@ -40,7 +40,7 @@ class SessionsController < ApplicationController
if login(params[:email], params[:password], params[:remember_me]) 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. # 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 session[:study_group_id] = current_user.study_groups.find_by(external_id: nil)&.id
redirect_back_or_to(:root, notice: t('.success')) sorcery_redirect_back_or_to(:root, notice: t('.success'))
else else
flash.now[:danger] = t('.failure') flash.now[:danger] = t('.failure')
render(:new) render(:new)

View File

@ -39,7 +39,7 @@ class StudyGroupsController < ApplicationController
def set_as_current def set_as_current
session[:study_group_id] = @study_group.id session[:study_group_id] = @study_group.id
current_user.store_current_study_group_id(@study_group.id) current_user.store_current_study_group_id(@study_group.id)
redirect_back(fallback_location: root_path, notice: t('study_groups.set_as_current.success')) redirect_back_or_to(root_path, notice: t('study_groups.set_as_current.success'))
end end
def set_group def set_group

View File

@ -17,3 +17,14 @@ module WillPaginate
end end
end end
end end
# Sorcery is currently overwriting the redirect_back_or_to method, which has been introduced in Rails 7.0+
# See https://github.com/Sorcery/sorcery/issues/296
module Sorcery
module Controller
module InstanceMethods
define_method :sorcery_redirect_back_or_to, instance_method(:redirect_back_or_to)
remove_method :redirect_back_or_to
end
end
end