From 06fa68cf0793cc91095cace3b3d9095cbb4955c9 Mon Sep 17 00:00:00 2001 From: WillNigel23 Date: Thu, 25 Jul 2024 00:30:18 +0800 Subject: [PATCH] 3161 - Owner login with no collection should go to 'Start a project' --- app/controllers/application_controller.rb | 12 ++++++++---- spec/features/devise_spec.rb | 10 +++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 35a869491e..5a6a155f35 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -50,7 +50,7 @@ def switch_locale(&action) end # append region to locale - related_locales = http_accept_language.user_preferred_languages.select do |loc| + related_locales = http_accept_language.user_preferred_languages.select do |loc| loc.to_s.include?(locale.to_s) && # is related to the chosen locale (is the locale, or is a regional version of it) I18n.available_locales.map{|e| e.to_s}.include?(loc.to_s) # is an available locale end @@ -84,7 +84,7 @@ def guest_user def guest_transcription return head(:forbidden) unless GUEST_TRANSCRIPTION_ENABLED - + if check_recaptcha(model: @page, :attribute => :errors) User.find(session[:guest_user_id].nil? ? session[:guest_user_id] = create_guest_user.id : session[:guest_user_id]) redirect_to :controller => 'transcribe', :action => 'display_page', :page_id => @page.id @@ -198,7 +198,7 @@ def set_friendly_collection(id) elsif !DocumentSet.find_by(slug: id).nil? @collection = DocumentSet.find_by(slug: id) elsif !Collection.find_by(slug: id).nil? - @collection = Collection.find_by(slug: id) + @collection = Collection.find_by(slug: id) end # check to make sure URLs haven't gotten scrambled @@ -324,7 +324,11 @@ def after_sign_in_path_for(resource) elsif !session[:user_return_to].blank? && session[:user_return_to] != '/' && !session[:user_return_to].include?('/landing') session[:user_return_to] elsif current_user.owner - dashboard_owner_path + if current_user.collections.any? + dashboard_owner_path + else + dashboard_startproject_path + end else dashboard_watchlist_path end diff --git a/spec/features/devise_spec.rb b/spec/features/devise_spec.rb index c6ed50906c..ba307cebfd 100644 --- a/spec/features/devise_spec.rb +++ b/spec/features/devise_spec.rb @@ -153,7 +153,15 @@ click_button('Sign In') expect(page.current_path).to eq old_path end - it "redirects owner back to user dashboard/watchlist if original path was nil" do + it "redirects owner back to user dashboard/watchlist if original path was nil and user has no collection" do + visit new_user_session_path + page.fill_in 'Login', with: owner.login + page.fill_in 'Password', with: owner.password + click_button('Sign In') + expect(page.current_path).to eq dashboard_startproject_path + end + it "redirects owner back to user dashboard/watchlist if original path was nil and user has collection" do + _collection = create(:collection, owner_user_id: owner.id) visit new_user_session_path page.fill_in 'Login', with: owner.login page.fill_in 'Password', with: owner.password