diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5d2c9074e..619c52ea5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -686,8 +686,9 @@ def api_offset_and_limit(options=params) limit = options[:limit].to_i if limit < 1 limit = 25 - elsif limit > 100 - limit = 100 + end + if 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/_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/config/locales/en.yml b/config/locales/en.yml index 5fee1e225..9d8128a6b 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 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 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 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