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

Allow configuration request to pass through with login_required

Oliver Günther5e60abc0bd23
diff --git a/lib/api/root_api.rb b/lib/api/root_api.rb
index 7f50f30f354..08ca2adf660 100644
--- a/lib/api/root_api.rb
+++ b/lib/api/root_api.rb
@@ -71,11 +71,15 @@ module API
def authenticate
User.current = warden.authenticate! scope: authentication_scope
- if Setting.login_required? and not logged_in?
+ if Setting.login_required? && !logged_in? && !allowed_unauthenticated_route?
raise ::API::Errors::Unauthenticated
end
end
+ def allowed_unauthenticated_route?
+ false
+ end
+
def set_localization
SetLocalizationService.new(User.current, env['HTTP_ACCEPT_LANGUAGE']).call
end
diff --git a/lib/api/v3/configuration/configuration_api.rb b/lib/api/v3/configuration/configuration_api.rb
index 74585f18b11..4418423921e 100644
--- a/lib/api/v3/configuration/configuration_api.rb
+++ b/lib/api/v3/configuration/configuration_api.rb
@@ -33,6 +33,12 @@ module API
module Configuration
class ConfigurationAPI < ::API::OpenProjectAPI
resources :configuration do
+ helpers do
+ def allowed_unauthenticated_route?
+ true
+ end
+ end
+
get do
ConfigurationRepresenter.new(Setting, current_user:, embed_links: true)
end
diff --git a/spec/requests/api/v3/configuration_resource_spec.rb b/spec/requests/api/v3/configuration_resource_spec.rb
index 0904cda5518..f95c2022b46 100644
--- a/spec/requests/api/v3/configuration_resource_spec.rb
+++ b/spec/requests/api/v3/configuration_resource_spec.rb
@@ -91,6 +91,17 @@ describe 'API v3 Configuration resource' do
end
context 'for a non logged in user' do
+ current_user { User.anonymous }
+
+ it 'returns 200 OK' do
+ expect(subject.status).to eq(200)
+ end
+ end
+
+ context 'for a non logged in user with login_required',
+ with_settings: { login_required?: true } do
+ current_user { User.anonymous }
+
it 'returns 200 OK' do
expect(subject.status).to eq(200)
end