redirect_back to page you were on when accepting enrollment

redirect_back is a new method in rails 5:
https://apidock.com/rails/ActionController/Redirecting/redirect_back

and it is for doing exactly what we want here, redirect back to the
page the person was on, otherwise still fall back to the fallback
location we were using before

test plan:
* accept a course enrollment invitation from an assignment page
* it should redirect you back to the same page you were looking at
  and not the course home page

Change-Id: I9be2050b452ee67da3aac32a6e7670f5719e5c35
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/217234
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Tested-by: Jenkins
QA-Review: Steven Burnett <sburnett@instructure.com>
Product-Review: Steven Burnett <sburnett@instructure.com>
Reviewed-by: Steven Burnett <sburnett@instructure.com>
This commit is contained in:
Ryan Shaw 2019-11-14 09:13:20 -07:00 committed by Steven Burnett
parent 61831c8d9c
commit 8483304dcf
1 changed files with 3 additions and 1 deletions

View File

@ -1553,7 +1553,9 @@ class CoursesController < ApplicationController
session[:accepted_enrollment_uuid] = enrollment.uuid
if params[:action] != 'show'
redirect_to course_url(@context.id)
# Redirects back to HTTP_REFERER if it exists (so if you accept from an assignent page it will put
# you back on the same page you were looking at). Otherwise, it redirects back to the course homepage
redirect_back(fallback_location: course_url(@context.id))
else
@context_enrollment = enrollment
enrollment = nil