From 20ab67e603ef795bb0fc77f420df79a22d6b6204 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 8 Sep 2024 16:42:26 +0300 Subject: [PATCH] Send along with pagination frames Previous/next page visits are promoted to full page visits with Turbo rewriting most of tags. If new tags aren't sent together with the updated frame, old ones will be simply deleted. That includes deleting a page title and csrf token tags, which is going to break some functionality, particularly logouts. --- app/controllers/diary_comments_controller.rb | 2 +- app/controllers/diary_entries_controller.rb | 2 +- app/controllers/issues_controller.rb | 2 +- app/controllers/traces_controller.rb | 2 +- app/controllers/users_controller.rb | 2 +- app/views/layouts/turbo_frame_visit.html.erb | 2 ++ test/system/user_logout_test.rb | 23 ++++++++++++++++++++ 7 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 app/views/layouts/turbo_frame_visit.html.erb diff --git a/app/controllers/diary_comments_controller.rb b/app/controllers/diary_comments_controller.rb index f6597cf4c0..5262c0bfbb 100644 --- a/app/controllers/diary_comments_controller.rb +++ b/app/controllers/diary_comments_controller.rb @@ -25,7 +25,7 @@ def index @comments, @newer_comments_id, @older_comments_id = get_page_items(comments, :includes => [:user]) - render :partial => "page" if turbo_frame_request_id == "pagination" + render "_page", :layout => "turbo_frame_visit" if turbo_frame_request_id == "pagination" end def create diff --git a/app/controllers/diary_entries_controller.rb b/app/controllers/diary_entries_controller.rb index ff6dfc826c..eccef35c29 100644 --- a/app/controllers/diary_entries_controller.rb +++ b/app/controllers/diary_entries_controller.rb @@ -61,7 +61,7 @@ def index @entries, @newer_entries_id, @older_entries_id = get_page_items(entries, :includes => [:user, :language]) - render :partial => "page" if turbo_frame_request_id == "pagination" + render "_page", :layout => "turbo_frame_visit" if turbo_frame_request_id == "pagination" end def show diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index fe900d627e..74d097dde5 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -44,7 +44,7 @@ def index end @issues, @newer_issues_id, @older_issues_id = get_page_items(@issues, :limit => @params[:limit]) - render :partial => "page" if turbo_frame_request_id == "pagination" + render "_page", :layout => "turbo_frame_visit" if turbo_frame_request_id == "pagination" end def show diff --git a/app/controllers/traces_controller.rb b/app/controllers/traces_controller.rb index d723bac5b7..ee4b0b803f 100644 --- a/app/controllers/traces_controller.rb +++ b/app/controllers/traces_controller.rb @@ -66,7 +66,7 @@ def index # final helper vars for view @target_user = target_user - render :partial => "page" if turbo_frame_request_id == "pagination" + render "_page", :layout => "turbo_frame_visit" if turbo_frame_request_id == "pagination" end def show diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4ebeb1ec3a..a44ed28a1e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -41,7 +41,7 @@ def index @users_count = users.count @users, @newer_users_id, @older_users_id = get_page_items(users, :limit => 50) - render :partial => "page" if turbo_frame_request_id == "pagination" + render "_page", :layout => "turbo_frame_visit" if turbo_frame_request_id == "pagination" end end diff --git a/app/views/layouts/turbo_frame_visit.html.erb b/app/views/layouts/turbo_frame_visit.html.erb new file mode 100644 index 0000000000..778187c413 --- /dev/null +++ b/app/views/layouts/turbo_frame_visit.html.erb @@ -0,0 +1,2 @@ +<%= render :partial => "layouts/head" %> +<%= yield %> diff --git a/test/system/user_logout_test.rb b/test/system/user_logout_test.rb index 2f5331711e..0c74550e99 100644 --- a/test/system/user_logout_test.rb +++ b/test/system/user_logout_test.rb @@ -45,4 +45,27 @@ class UserLogoutTest < ApplicationSystemTestCase assert_content "Log In" assert_content "Public GPS Traces" end + + test "Sign out after navigating with Turbo pagination" do + saved_allow_forgery_protection = ActionController::Base.allow_forgery_protection + ActionController::Base.allow_forgery_protection = true + + create(:language, :code => "en") + create(:diary_entry, :title => "First Diary Entry") + create_list(:diary_entry, 20) # rubocop:disable FactoryBot/ExcessiveCreateList + user = create(:user) + sign_in_as user + + visit diary_entries_path + assert_no_link "Log In" + + click_on "Older Entries" + assert_link "First Diary Entry" + + click_on user.display_name + click_on "Log Out" + assert_link "Log In" + ensure + ActionController::Base.allow_forgery_protection = saved_allow_forgery_protection + end end