From 1def3b9b08ff5261635276c7764a82b680c86bc4 Mon Sep 17 00:00:00 2001 From: fkdkent Date: Sat, 24 Oct 2020 14:14:42 +0900 Subject: [PATCH 1/5] Apply Domingo Galdos's patch --- app/controllers/application_controller.rb | 4 ++-- app/views/settings/_general.html.erb | 2 ++ config/locales/en.yml | 1 + config/settings.yml | 3 +++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5d2c9074e..50279f716 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -686,8 +686,8 @@ def api_offset_and_limit(options=params) limit = options[:limit].to_i if limit < 1 limit = 25 - elsif limit > 100 - limit = 100 + elsif limit > Setting.api_limit.to_i + limit = Setting.api_limit.to_i end if offset.nil? && options[:page].present? offset = (options[:page].to_i - 1) * limit diff --git a/app/views/settings/_general.html.erb b/app/views/settings/_general.html.erb index 043067f18..c8a6ccd76 100644 --- a/app/views/settings/_general.html.erb +++ b/app/views/settings/_general.html.erb @@ -35,6 +35,8 @@

<%= setting_select :wiki_compression, [['Gzip', 'gzip']], :blank => :label_none %>

+

<%= setting_text_field :api_limit, :size => 6 %>

+

<%= setting_text_field :feeds_limit, :size => 6 %>

<%= call_hook(:view_settings_general_form) %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 5fee1e225..4a376aa38 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -429,6 +429,7 @@ en: setting_host_name: Host name and path setting_text_formatting: Text formatting setting_wiki_compression: Wiki history compression + setting_api_limit: Maximum number of items returned in a JSON/XML API response setting_feeds_limit: Maximum number of items in Atom feeds setting_default_projects_public: New projects are public by default setting_autofetch_changesets: Fetch commits automatically diff --git a/config/settings.yml b/config/settings.yml index 0c41b7eda..3112eb06c 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -111,6 +111,9 @@ host_name: protocol: default: http security_notifications: 1 +api_limit: + format: int + default: 100 feeds_limit: format: int default: 15 From eb4722774c5d97cd63b44a5017300876bd39520b Mon Sep 17 00:00:00 2001 From: fkdkent Date: Sat, 24 Oct 2020 14:36:30 +0900 Subject: [PATCH 2/5] Move to API tab --- app/views/settings/_api.html.erb | 3 +++ app/views/settings/_general.html.erb | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/settings/_api.html.erb b/app/views/settings/_api.html.erb index 6ee401037..ee862f687 100644 --- a/app/views/settings/_api.html.erb +++ b/app/views/settings/_api.html.erb @@ -4,6 +4,9 @@

<%= setting_check_box :rest_api_enabled %>

<%= setting_check_box :jsonp_enabled %>

+ +

<%= setting_text_field :api_limit, :size => 6 %>

+ <%= submit_tag l(:button_save) %> diff --git a/app/views/settings/_general.html.erb b/app/views/settings/_general.html.erb index c8a6ccd76..043067f18 100644 --- a/app/views/settings/_general.html.erb +++ b/app/views/settings/_general.html.erb @@ -35,8 +35,6 @@

<%= setting_select :wiki_compression, [['Gzip', 'gzip']], :blank => :label_none %>

-

<%= setting_text_field :api_limit, :size => 6 %>

-

<%= setting_text_field :feeds_limit, :size => 6 %>

<%= call_hook(:view_settings_general_form) %> From de3b51ecc2294976d41d7a43ef7e4601d5dcac43 Mon Sep 17 00:00:00 2001 From: fkdkent Date: Sat, 24 Oct 2020 14:36:44 +0900 Subject: [PATCH 3/5] Simplify label --- config/locales/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 4a376aa38..9d8128a6b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -429,7 +429,7 @@ en: setting_host_name: Host name and path setting_text_formatting: Text formatting setting_wiki_compression: Wiki history compression - setting_api_limit: Maximum number of items returned in a JSON/XML API response + setting_api_limit: Maximum number of returned items setting_feeds_limit: Maximum number of items in Atom feeds setting_default_projects_public: New projects are public by default setting_autofetch_changesets: Fetch commits automatically From a817032d7d993fb7072237ce231fafe353816799 Mon Sep 17 00:00:00 2001 From: fkdkent Date: Sat, 24 Oct 2020 14:37:42 +0900 Subject: [PATCH 4/5] Quick fix to allow less than 25 --- app/controllers/application_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 50279f716..619c52ea5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -686,7 +686,8 @@ def api_offset_and_limit(options=params) limit = options[:limit].to_i if limit < 1 limit = 25 - elsif limit > Setting.api_limit.to_i + end + if limit > Setting.api_limit.to_i limit = Setting.api_limit.to_i end if offset.nil? && options[:page].present? From 4a83cdf01596dae590d221381aa45bede5fc9eaf Mon Sep 17 00:00:00 2001 From: fkdkent Date: Sat, 24 Oct 2020 14:59:26 +0900 Subject: [PATCH 5/5] Add test --- test/integration/api_test/api_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/integration/api_test/api_test.rb b/test/integration/api_test/api_test.rb index b16a50471..e103a94d6 100644 --- a/test/integration/api_test/api_test.rb +++ b/test/integration/api_test/api_test.rb @@ -64,4 +64,12 @@ def test_api_with_invalid_format_should_return_406 assert_response :not_acceptable assert_equal "We couldn't handle your request, sorry. If you were trying to access the API, make sure to append .json or .xml to your request URL.\n", response.body end + + def test_setting_api_limit_should_limit_response_item_count + with_settings :api_limit => 5 do + get '/users.xml?limit=5', :headers => credentials('admin') + assert_select 'users[type=array][total_count][limit="5"][offset="0"]' + assert_select 'users user', 5 + end + end end