Skip to content

Commit

Permalink
Merge pull request #16354 from code-dot-org/sectionFix
Browse files Browse the repository at this point in the history
redirect to course page on login if section has course and no script
  • Loading branch information
Bjvanminnen committed Jul 12, 2017
2 parents e7de7a1 + 341e158 commit b46ceee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 4 additions & 2 deletions dashboard/app/controllers/sections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def log_in
bypass_sign_in user
user.update_tracked_fields!(request)
session[:show_pairing_dialog] = true if params[:show_pairing_dialog]
redirect_to_section_script
redirect_to_section_script_or_course
else
flash[:alert] = I18n.t('signinsection.invalid_login')
redirect_to section_path(id: @section.code)
Expand All @@ -32,9 +32,11 @@ def log_in

private

def redirect_to_section_script
def redirect_to_section_script_or_course
if @section.script
redirect_to @section.script
elsif @section.course
redirect_to @section.course
else
redirect_to '/'
end
Expand Down
14 changes: 13 additions & 1 deletion dashboard/test/controllers/sections_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ class SectionsControllerTest < ActionController::TestCase

setup do
# place in setup instead of setup_all otherwise course ends up being serialized
# to a file in levelbuilder_mode is true
# to a file if levelbuilder_mode is true
@course = create(:course)
@section_with_course = create(:section, user: @teacher, login_type: 'word', course_id: @course.id)
@section_with_course_user_1 = create(:follower, section: @section_with_course).student_user
end

test "do not show login screen for invalid section code" do
Expand Down Expand Up @@ -107,6 +109,16 @@ class SectionsControllerTest < ActionController::TestCase
assert_redirected_to '/s/flappy'
end

test "login to section with a course redirects to course" do
post :log_in, params: {
id: @section_with_course.code,
user_id: @section_with_course_user_1.id,
secret_words: @section_with_course_user_1.secret_words
}

assert_redirected_to "/courses/#{@section_with_course.course.name}"
end

test "login with show_pairing_dialog shows pairing dialog" do
post :log_in, params: {
id: @flappy_section.code,
Expand Down

0 comments on commit b46ceee

Please sign in to comment.