From 2bb90eab13a6f743992b6b1a0e0b8d0ee20c53be Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Tue, 4 Nov 2025 16:59:40 +0100 Subject: [PATCH] Use the sole collection as the root for a better onboarding experience for new accounts --- app/controllers/concerns/authentication.rb | 2 +- app/controllers/join_codes_controller.rb | 2 +- app/controllers/landings_controller.rb | 9 +++++++++ app/controllers/users/joins_controller.rb | 2 +- .../sessions/menus/show.html+menu_section.erb | 2 +- app/views/sessions/menus/show.html.erb | 2 +- config/routes.rb | 2 ++ .../signups/completions_controller.rb | 2 +- .../signups/completions_controller_test.rb | 2 +- .../controllers/join_codes_controller_test.rb | 2 +- test/controllers/landings_controller_test.rb | 20 +++++++++++++++++++ .../users/joins_controller_test.rb | 2 +- 12 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 app/controllers/landings_controller.rb create mode 100644 test/controllers/landings_controller_test.rb diff --git a/app/controllers/concerns/authentication.rb b/app/controllers/concerns/authentication.rb index daedbb582..5afbcccf8 100644 --- a/app/controllers/concerns/authentication.rb +++ b/app/controllers/concerns/authentication.rb @@ -73,7 +73,7 @@ module Authentication end def after_authentication_url - session.delete(:return_to_after_authenticating) || root_url + session.delete(:return_to_after_authenticating) || landing_url end def redirect_authenticated_user diff --git a/app/controllers/join_codes_controller.rb b/app/controllers/join_codes_controller.rb index 4bd5293ea..0ddbcdd7b 100644 --- a/app/controllers/join_codes_controller.rb +++ b/app/controllers/join_codes_controller.rb @@ -15,7 +15,7 @@ class JoinCodesController < ApplicationController identity.send_magic_link end - session[:return_to_after_authenticating] = root_url(script_name: "/#{tenant}") + session[:return_to_after_authenticating] = landing_url(script_name: "/#{tenant}") redirect_to session_magic_link_path end diff --git a/app/controllers/landings_controller.rb b/app/controllers/landings_controller.rb new file mode 100644 index 000000000..5e8fce46d --- /dev/null +++ b/app/controllers/landings_controller.rb @@ -0,0 +1,9 @@ +class LandingsController < ApplicationController + def show + if Current.user.collections.many? + redirect_to events_path + else + redirect_to collection_path(Current.user.collections.first) + end + end +end diff --git a/app/controllers/users/joins_controller.rb b/app/controllers/users/joins_controller.rb index 493887452..d811a6203 100644 --- a/app/controllers/users/joins_controller.rb +++ b/app/controllers/users/joins_controller.rb @@ -11,7 +11,7 @@ class Users::JoinsController < ApplicationController User.create!(user_params.merge(membership: Current.membership)) end - redirect_to root_path + redirect_to landing_path end private diff --git a/app/views/sessions/menus/show.html+menu_section.erb b/app/views/sessions/menus/show.html+menu_section.erb index 6aab21fe8..6a0a41346 100644 --- a/app/views/sessions/menus/show.html+menu_section.erb +++ b/app/views/sessions/menus/show.html+menu_section.erb @@ -2,7 +2,7 @@ <% cache [ Current.identity, @memberships ] do %> <%= collapsible_nav_section "Accounts" do %> <% @memberships.each do |membership| %> - <%= filter_place_menu_item root_url(script_name: "/#{membership.tenant}"), "#{membership.account_name}", "marker", new_window: true %> + <%= filter_place_menu_item landing_url(script_name: "/#{membership.tenant}"), "#{membership.account_name}", "marker", new_window: true %> <% end %> <% end %> <% end %> diff --git a/app/views/sessions/menus/show.html.erb b/app/views/sessions/menus/show.html.erb index 1c9af55ed..096ea7d5b 100644 --- a/app/views/sessions/menus/show.html.erb +++ b/app/views/sessions/menus/show.html.erb @@ -13,7 +13,7 @@ <% @memberships.each do |membership| %> diff --git a/config/routes.rb b/config/routes.rb index 89699f4dd..ef99bad1b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -15,6 +15,8 @@ Rails.application.routes.draw do end end + resource :landing + resources :collections do scope module: :collections do resource :subscriptions diff --git a/gems/fizzy-saas/app/controllers/signups/completions_controller.rb b/gems/fizzy-saas/app/controllers/signups/completions_controller.rb index e86731f22..58dd528d2 100644 --- a/gems/fizzy-saas/app/controllers/signups/completions_controller.rb +++ b/gems/fizzy-saas/app/controllers/signups/completions_controller.rb @@ -13,7 +13,7 @@ class Signups::CompletionsController < ApplicationController @signup = Signup.new(signup_params) if @signup.complete - redirect_to root_url(script_name: "/#{@signup.tenant}") + redirect_to landing_url(script_name: "/#{@signup.tenant}") else render :new, status: :unprocessable_entity end diff --git a/gems/fizzy-saas/test/controllers/signups/completions_controller_test.rb b/gems/fizzy-saas/test/controllers/signups/completions_controller_test.rb index e9f8a472f..35861722d 100644 --- a/gems/fizzy-saas/test/controllers/signups/completions_controller_test.rb +++ b/gems/fizzy-saas/test/controllers/signups/completions_controller_test.rb @@ -33,7 +33,7 @@ class Signups::CompletionsControllerTest < ActionDispatch::IntegrationTest }, headers: http_basic_auth_headers end - assert_redirected_to root_url(script_name: "/#{@signup.tenant}"), "Successful completion should redirect to root in new tenant" + assert_redirected_to landing_path(script_name: "/#{@signup.tenant}"), "Successful completion should redirect to root in new tenant" untenanted do post saas.signup_completion_path, params: { diff --git a/test/controllers/join_codes_controller_test.rb b/test/controllers/join_codes_controller_test.rb index de8c5daa5..2387e30ce 100644 --- a/test/controllers/join_codes_controller_test.rb +++ b/test/controllers/join_codes_controller_test.rb @@ -42,7 +42,7 @@ class JoinCodesControllerTest < ActionDispatch::IntegrationTest end assert_redirected_to session_magic_link_path - assert_equal root_url(script_name: "/#{@tenant}"), session[:return_to_after_authenticating] + assert_equal landing_url(script_name: "/#{@tenant}"), session[:return_to_after_authenticating] end end diff --git a/test/controllers/landings_controller_test.rb b/test/controllers/landings_controller_test.rb new file mode 100644 index 000000000..eb24a3058 --- /dev/null +++ b/test/controllers/landings_controller_test.rb @@ -0,0 +1,20 @@ +require "test_helper" + +class LandingsControllerTest < ActionDispatch::IntegrationTest + setup do + sign_in_as :kevin + end + + test "redirects to the timeline when many collections" do + get landing_path + assert_redirected_to events_path + end + + test "redirects to collections when only one collection" do + sole_collection, *collections_to_delete = users(:kevin).collections.to_a + collections_to_delete.each(&:destroy) + + get landing_path + assert_redirected_to collection_path(sole_collection) + end +end diff --git a/test/controllers/users/joins_controller_test.rb b/test/controllers/users/joins_controller_test.rb index 3d06b7b08..4fe3ec218 100644 --- a/test/controllers/users/joins_controller_test.rb +++ b/test/controllers/users/joins_controller_test.rb @@ -26,7 +26,7 @@ class Users::JoinsControllerTest < ActionDispatch::IntegrationTest assert_difference -> { User.count }, +1 do post users_joins_path, params: { user: { name: "Newart Userbaum" } } - assert_redirected_to root_path + assert_redirected_to landing_path end end end