Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Add a separate setting for max API size

Oliver Günther43891b23bb02
diff --git a/app/views/admin/settings/api_settings/show.html.erb b/app/views/admin/settings/api_settings/show.html.erb
index 08f495edd47..bbe4fa76303 100644
--- a/app/views/admin/settings/api_settings/show.html.erb
+++ b/app/views/admin/settings/api_settings/show.html.erb
@@ -29,6 +29,14 @@ See COPYRIGHT and LICENSE files for more details.
<%= toolbar title: t(:label_api_access_key_type) %>
<%= styled_form_tag(admin_settings_update_api_path, method: :patch) do %>
+ <section class="form--section">
+ <div class="form--field">
+ <%= setting_number_field :apiv3_max_page_size, min: 50, container_class: '-slim' %>
+ <div class="form--field-instructions">
+ <p><%= t(:setting_apiv3_max_page_instructions_html) %></p>
+ </div>
+ </div>
+ </section>
<section class="form--section">
<fieldset class="form--fieldset">
<legend class="form--fieldset-legend"><%= I18n.t("setting_apiv3_docs") %></legend>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index f1c2e3abbcb..e57989e08e8 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -2443,6 +2443,14 @@ en:
If CORS is enabled, these are the origins that are allowed to access OpenProject API.
<br/>
Please check the <a href="%{origin_link}" target="_blank">Documentation on the Origin header</a> on how to specify the expected values.
+ setting_apiv3_max_page_size: "Maximum API page size"
+ setting_apiv3_max_page_instructions_html: >
+ Set the maximum page size the API will respond with.
+ It will not be possible to perform API requests that return more values on a single page.
+ <br/>
+ <strong>Warning:</strong> Please only change this value if you are sure why you need it.
+ Setting to a high value will result in significant performance impacts, while a value lower than the per page options
+ will cause errors in paginated views.
setting_apiv3_docs: "Documentation"
setting_apiv3_docs_enabled: "Enable docs page"
setting_apiv3_docs_enabled_instructions_html: >
diff --git a/config/settings.yml b/config/settings.yml
index 6766d737398..f47884549a0 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -366,9 +366,8 @@ apiv3_cors_origins:
apiv3_docs_enabled:
default: true
format: boolean
+apiv3_max_page_size:
+ default: 1000
notification_retention_period_days:
default: 30
format: int
-attachment_whitelist:
- serialized: true
- default: []
diff --git a/lib/api/utilities/page_size_helper.rb b/lib/api/utilities/page_size_helper.rb
index 00bacf195c0..6a1cd64a02b 100644
--- a/lib/api/utilities/page_size_helper.rb
+++ b/lib/api/utilities/page_size_helper.rb
@@ -31,12 +31,6 @@
module API
module Utilities
module PageSizeHelper
- # Set a default max size to ensure backwards compatibility
- # with the previous private setting `maximum_page_size`.
- # The actual value is taken from
- # max(Setting.per_page_options)
- DEFAULT_API_MAX_SIZE = 500
-
##
# Determine set page_size from string
def resolve_page_size(string)
@@ -61,14 +55,9 @@ module API
end
##
- # Get the maximum allowed page size from
- # the largest option of per_page size,
- # or the magic fallback value 500.
+ # Get the maximum allowed page size from settings
def maximum_page_size
- [
- DEFAULT_API_MAX_SIZE,
- Setting.per_page_options_array.max
- ].max
+ Setting.apiv3_max_page_size.to_i
end
private
diff --git a/spec/lib/api/utilities/page_size_helper.rb b/spec/lib/api/utilities/page_size_helper_spec.rb
similarity index 83%
rename from spec/lib/api/utilities/page_size_helper.rb
rename to spec/lib/api/utilities/page_size_helper_spec.rb
index 3f02e0db577..d2bf9b08e55 100644
--- a/spec/lib/api/utilities/page_size_helper.rb
+++ b/spec/lib/api/utilities/page_size_helper_spec.rb
@@ -38,16 +38,16 @@ describe ::API::Utilities::PageSizeHelper do
describe '#maximum_page_size' do
context 'when small values in per_page_options',
- with_settings: { per_page_options: '20,100' } do
- it 'uses the magical number 500' do
- expect(subject.maximum_page_size).to eq(500)
+ with_settings: { per_page_options: '20,100', apiv3_max_page_size: 57 } do
+ it 'uses the value from settings' do
+ expect(subject.maximum_page_size).to eq(57)
end
end
context 'when larger values in per_page_options',
- with_settings: { per_page_options: '20,100,1000' } do
+ with_settings: { per_page_options: '20,100,1000', apiv3_max_page_size: 57 } do
it 'uses that value' do
- expect(subject.maximum_page_size).to eq(1000)
+ expect(subject.maximum_page_size).to eq(57)
end
end
end