Skip to content

Commit

Permalink
Fix Sorcery conflict for redirect_back_or_to
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSerth committed Jan 19, 2024
1 parent c280a58 commit 7a13303
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
6 changes: 3 additions & 3 deletions app/controllers/exercises_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ def implement # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedC
session.delete(:pair_programming)
@current_contributor = current_user
else
return redirect_back(
fallback_location: implement_exercise_path(current_contributor.exercise),
return redirect_back_or_to(
implement_exercise_path(current_contributor.exercise),
alert: t('exercises.implement.existing_programming_group', exercise: current_contributor.exercise.title)
)
end
Expand All @@ -323,7 +323,7 @@ def implement # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedC
session[:pg_id] = pg.id
@current_contributor = pg
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?
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)
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/live_streams_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def download_submission_file
# 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!)
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
desired_file = params[:filename].to_s
runner = Runner.for(current_contributor, @submission.exercise.execution_environment)
Expand Down Expand Up @@ -65,7 +65,7 @@ def send_runner_file(runner, desired_file, redirect_fallback = root_path, privil
end
end
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
2 changes: 1 addition & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ 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'))
sorcery_redirect_back_or_to(:root, notice: t('.success'))
else
flash.now[:danger] = t('.failure')
render(:new)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/study_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def study_group_params
def set_as_current
session[: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

def set_group
Expand Down
11 changes: 11 additions & 0 deletions config/initializers/monkey_patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@ def previous_or_next_page(page, text, classname, aria_label = nil)
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

0 comments on commit 7a13303

Please sign in to comment.