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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
return 404 for storages api routes if storages module is disabled
Christophe Bliard416205f08efd
diff --git a/modules/storages/lib/api/v3/file_links/file_links_api.rb b/modules/storages/lib/api/v3/file_links/file_links_api.rbindex ff19c4d479e..fb8405342fe 100644--- a/modules/storages/lib/api/v3/file_links/file_links_api.rb+++ b/modules/storages/lib/api/v3/file_links/file_links_api.rb@@ -41,6 +41,10 @@ module APIendend+ before do+ raise ::API::Errors::NotFound unless OpenProject::FeatureDecisions.storages_module_active?+ end+# The `:resources` keyword defines the API namespace -> /api/v3/file_links/...resources :file_links do# `route_param` extends the route by a route parameter of the endpoint.diff --git a/modules/storages/lib/api/v3/file_links/work_packages_file_links_api.rb b/modules/storages/lib/api/v3/file_links/work_packages_file_links_api.rbindex a06a9dbf8ac..5a0a2ffca23 100644--- a/modules/storages/lib/api/v3/file_links/work_packages_file_links_api.rb+++ b/modules/storages/lib/api/v3/file_links/work_packages_file_links_api.rb@@ -42,6 +42,10 @@ module APIendend+ before do+ raise ::API::Errors::NotFound unless OpenProject::FeatureDecisions.storages_module_active?+ end+# The `:resources` keyword defines the API namespace -> /api/v3/work_packages/:id/file_links/...resources :file_links do# A helper is used to define the behaviour at GET /api/v3/work_packages/:id/file_linksdiff --git a/modules/storages/lib/api/v3/storages/storages_api.rb b/modules/storages/lib/api/v3/storages/storages_api.rbindex c768f118a0d..ceabe1f47bb 100644--- a/modules/storages/lib/api/v3/storages/storages_api.rb+++ b/modules/storages/lib/api/v3/storages/storages_api.rb@@ -41,6 +41,10 @@ module APIendend+ before do+ raise ::API::Errors::NotFound unless OpenProject::FeatureDecisions.storages_module_active?+ end+# The `:resources` keyword defines the API namespace -> /api/v3/storages/...resources :storages do# `route_param` extends the route by a route parameter of the endpoint.diff --git a/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb b/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rbindex dd100cda925..92edbf6c7bf 100644--- a/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb+++ b/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb@@ -81,6 +81,10 @@ describe 'API v3 file links resource', :enable_storages, type: :request dolet(:elements) { [] }endend++ context 'when storages module is inactive', :disable_storages do+ it_behaves_like 'not found'+ endenddescribe 'POST /api/v3/work_packages/:work_package_id/file_links' do@@ -141,6 +145,10 @@ describe 'API v3 file links resource', :enable_storages, type: :request doendendend++ context 'when storages module is inactive', :disable_storages do+ it_behaves_like 'not found'+ endendcontext 'when some embedded file link elements are NOT valid' do@@ -318,6 +326,10 @@ describe 'API v3 file links resource', :enable_storages, type: :request doit_behaves_like 'not found'end++ context 'when storages module is inactive', :disable_storages do+ it_behaves_like 'not found'+ endenddescribe 'DELETE /api/v3/file_links/:file_link_id' do@@ -351,6 +363,10 @@ describe 'API v3 file links resource', :enable_storages, type: :request doit_behaves_like 'not found'end++ context 'when storages module is inactive', :disable_storages do+ it_behaves_like 'not found'+ endenddescribe 'GET /api/v3/file_links/:file_link_id/open' do@@ -375,6 +391,10 @@ describe 'API v3 file links resource', :enable_storages, type: :request doit_behaves_like 'not found'end++ context 'when storages module is inactive', :disable_storages do+ it_behaves_like 'not found'+ endendend# rubocop:enable RSpec/MultipleMemoizedHelpersdiff --git a/modules/storages/spec/requests/api/v3/storages/storages_spec.rb b/modules/storages/spec/requests/api/v3/storages/storages_spec.rbindex df59cc3123a..8e7fd415679 100644--- a/modules/storages/spec/requests/api/v3/storages/storages_spec.rb+++ b/modules/storages/spec/requests/api/v3/storages/storages_spec.rb@@ -94,5 +94,9 @@ describe 'API v3 storages resource', :enable_storages, type: :request, content_tit_behaves_like 'successful storage response'end++ context 'when storages module is inactive', :disable_storages do+ it_behaves_like 'not found'+ endendenddiff --git a/modules/storages/spec/requests/api/v3/work_packages/work_packages_linkable_filter_spec.rb b/modules/storages/spec/requests/api/v3/work_packages/work_packages_linkable_filter_spec.rbindex 4bb50b637af..c537e0c12c8 100644--- a/modules/storages/spec/requests/api/v3/work_packages/work_packages_linkable_filter_spec.rb+++ b/modules/storages/spec/requests/api/v3/work_packages/work_packages_linkable_filter_spec.rb@@ -149,6 +149,10 @@ describe 'API v3 work packages resource with filters for the linkable to storagelet(:elements) { [] }endend++ context 'when storages module is inactive', :disable_storages do+ it_behaves_like 'not found'+ endendendenddiff --git a/modules/storages/spec/requests/api/v3/work_packages/work_packages_linked_filter_spec.rb b/modules/storages/spec/requests/api/v3/work_packages/work_packages_linked_filter_spec.rbindex 13fa6462e14..b1d4c592bba 100644--- a/modules/storages/spec/requests/api/v3/work_packages/work_packages_linked_filter_spec.rb+++ b/modules/storages/spec/requests/api/v3/work_packages/work_packages_linked_filter_spec.rb@@ -252,6 +252,10 @@ describe 'API v3 work packages resource with filters for linked storage file',let(:elements) { [work_package3] }endend++ context 'when storages module is inactive', :disable_storages do+ it_behaves_like 'not found'+ endendendenddiff --git a/modules/storages/spec/support/enable_storages_module.rb b/modules/storages/spec/support/enable_storages_module.rbindex 7c11aa48f9b..dcc4cc4b3b4 100644--- a/modules/storages/spec/support/enable_storages_module.rb+++ b/modules/storages/spec/support/enable_storages_module.rb@@ -1,9 +1,48 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#+++RSpec.shared_context "with storages module enabled" do+ let(:storages_module_active) { true }+before do- allow(OpenProject::FeatureDecisions).to receive(:storages_module_active?).and_return(true)+ allow(OpenProject::FeatureDecisions).to receive(:storages_module_active?).and_return(storages_module_active)endend+RSpec.shared_context "with storages module disabled" do+ let(:storages_module_active) { false }+end+RSpec.configure do |rspec|- rspec.include_context "with storages module enabled", enable_storages: true+ # examples tagged with `:enable_storages` will automatically have context+ # included and storages module enabled+ rspec.include_context "with storages module enabled", :enable_storages+ # examples tagged with `disable_storages` will automatically have context+ # included and storages module disabled+ rspec.include_context "with storages module disabled", :disable_storagesend