From 079d64795b30e72f07e36646f511d0678c68b29e Mon Sep 17 00:00:00 2001 From: Ahmad Farhat Date: Wed, 22 Jan 2020 16:32:26 -0500 Subject: [PATCH] Redirect authenticated users to main room when accessing ldap signin (#856) Co-authored-by: Jesus Federico --- app/controllers/concerns/authenticator.rb | 3 ++- app/controllers/sessions_controller.rb | 2 +- spec/controllers/sessions_controller_spec.rb | 8 ++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/controllers/concerns/authenticator.rb b/app/controllers/concerns/authenticator.rb index 2fd6ded0..f4dc3799 100644 --- a/app/controllers/concerns/authenticator.rb +++ b/app/controllers/concerns/authenticator.rb @@ -42,7 +42,8 @@ module Authenticator redirect_to admins_path elsif user.activated? # Dont redirect to any of these urls - dont_redirect_to = [root_url, signin_url, signup_url, unauthorized_url, internal_error_url, not_found_url] + dont_redirect_to = [root_url, signin_url, ldap_signin_url, signup_url, unauthorized_url, + internal_error_url, not_found_url] url = if cookies[:return_to] && !dont_redirect_to.include?(cookies[:return_to]) cookies[:return_to] else diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 3a45c165..6540344e 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -24,7 +24,7 @@ class SessionsController < ApplicationController skip_before_action :verify_authenticity_token, only: [:omniauth, :fail] before_action :check_user_signup_allowed, only: [:new] - before_action :ensure_unauthenticated_except_twitter, only: [:new, :signin] + before_action :ensure_unauthenticated_except_twitter, only: [:new, :signin, :ldap_signin] # GET /signin def signin diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index f1ef34eb..c0db4d12 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -61,6 +61,14 @@ describe SessionsController, type: :controller do expect(response).to render_template(:ldap_signin) end + + it "redirects user to main room if already signed in" do + user = create(:user) + @request.session[:user_id] = user.id + + post :signin + expect(response).to redirect_to(room_path(user.main_room)) + end end describe "GET #destroy" do