Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirect to course page on login if section has course and no script #16354

Merged
merged 1 commit into from
Jul 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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