From 43db847314a485d9b3675bac9dd4b0509a5a168b Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Thu, 10 Sep 2026 10:36:09 +0100 Subject: [PATCH] Add ACL cursor-base pagination --- app/controllers/acls_controller.rb | 5 +++- app/views/acls/_page.html.erb | 23 +++++++++++++++++++ app/views/acls/index.html.erb | 18 ++------------- config/locales/en.yml | 6 +++++ test/controllers/acls_controller_test.rb | 12 ++++++++++ test/system/acls_test.rb | 29 ++++++++++++++++++++++++ 6 files changed, 76 insertions(+), 17 deletions(-) create mode 100644 app/views/acls/_page.html.erb diff --git a/app/controllers/acls_controller.rb b/app/controllers/acls_controller.rb index 2abfee729..f3c4f758b 100644 --- a/app/controllers/acls_controller.rb +++ b/app/controllers/acls_controller.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class AclsController < ApplicationController + include PaginationMethods + layout :site_layout before_action :authorize_web @@ -13,7 +15,8 @@ class AclsController < ApplicationController before_action :set_acl, :only => [:edit, :update, :destroy] def index - @acls = Acl.order(:id) + @params = params.permit(:before, :after) + @acls = get_page_items(Acl.all) end def new diff --git a/app/views/acls/_page.html.erb b/app/views/acls/_page.html.erb new file mode 100644 index 000000000..3e916b5f5 --- /dev/null +++ b/app/views/acls/_page.html.erb @@ -0,0 +1,23 @@ +<%# locals: (acls:, params:) %> + + + <%= render "pagination", :paginator => acls, :params => params %> + + + + + + + + + + + + + + <%= render acls.items %> + +
<%= t(".address") %><%= t(".domain") %><%= t(".mx") %><%= t(".k") %><%= t(".v") %><%= t(".actions") %>
+ + <%= render "pagination", :paginator => acls, :params => params %> +
diff --git a/app/views/acls/index.html.erb b/app/views/acls/index.html.erb index aa32b5215..1806750ad 100644 --- a/app/views/acls/index.html.erb +++ b/app/views/acls/index.html.erb @@ -6,22 +6,8 @@ <%= render "navigation" %> <% end %> -<% if @acls.empty? %> +<% if @acls.items.empty? %>

<%= t(".empty") %>

<% else %> - - - - - - - - - - - - - <%= render @acls %> - -
<%= t(".address") %><%= t(".domain") %><%= t(".mx") %><%= t(".k") %><%= t(".v") %><%= t(".actions") %>
+ <%= render "page", :acls => @acls, :params => @params %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 03331d51d..db3e07f86 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3196,6 +3196,11 @@ en: help: Help pagination: label: Page navigation + acls: + older: Older ACLs + newer: Newer ACLs + oldest: Oldest ACLs + newest: Newest ACLs changeset_comments: older: Older Comments newer: Newer Comments @@ -3934,6 +3939,7 @@ en: index: title: ACLs empty: No ACLs to show. + page: address: Address domain: Domain mx: MX server diff --git a/test/controllers/acls_controller_test.rb b/test/controllers/acls_controller_test.rb index ea27cfc8b..f70df1880 100644 --- a/test/controllers/acls_controller_test.rb +++ b/test/controllers/acls_controller_test.rb @@ -52,6 +52,18 @@ class AclsControllerTest < ActionDispatch::IntegrationTest assert_template :index end + def test_index_invalid_paged + session_for(create(:administrator_user)) + + %w[-1 fred].each do |id| + get acls_path(:before => id) + assert_redirected_to :controller => "errors", :action => "bad_request" + + get acls_path(:after => id) + assert_redirected_to :controller => "errors", :action => "bad_request" + end + end + def test_new get new_acl_path assert_redirected_to login_path(:referer => new_acl_path) diff --git a/test/system/acls_test.rb b/test/system/acls_test.rb index b6c0d3a3d..1b28c7a07 100644 --- a/test/system/acls_test.rb +++ b/test/system/acls_test.rb @@ -26,6 +26,35 @@ class AclsTest < ApplicationSystemTestCase end end + test "index shows newest acls first and pages through older ones" do + 1.upto(25) { |n| create(:acl, :k => "no_account_creation", :v => "entry-#{n}") } + sign_in_as(create(:administrator_user)) + + visit acls_path + within_table "acl_list" do + assert_selector "tbody tr", :count => 20 + assert_selector "tbody tr:first-child", :text => "entry-25" + assert_selector "tbody tr:last-child", :text => "entry-6" + assert_no_text "entry-5" + end + + click_on "Older ACLs", :match => :first + within_table "acl_list" do + assert_selector "tbody tr", :count => 5 + assert_selector "tbody tr:first-child", :text => "entry-5" + assert_selector "tbody tr:last-child", :text => "entry-1" + assert_no_text "entry-6" + end + assert_no_link "Older ACLs" + + click_on "Newer ACLs", :match => :first + within_table "acl_list" do + assert_selector "tbody tr", :count => 20 + assert_selector "tbody tr:first-child", :text => "entry-25" + end + assert_no_link "Newer ACLs" + end + test "create an acl" do sign_in_as(create(:administrator_user)) -- 2.47.3