Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions app/views/settings/_api.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<p><%= setting_check_box :rest_api_enabled %></p>

<p><%= setting_check_box :jsonp_enabled %></p>

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

</div>

<%= submit_tag l(:button_save) %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ host_name:
protocol:
default: http
security_notifications: 1
api_limit:
format: int
default: 100
feeds_limit:
format: int
default: 15
Expand Down
8 changes: 8 additions & 0 deletions test/integration/api_test/api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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