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

make storages filters unavailable if storages module is unavailable

Christophe Bliard8231f3fabd99
diff --git a/modules/storages/app/models/queries/storages/work_packages/filter/concerns/validate_storages_module_available.rb b/modules/storages/app/models/queries/storages/work_packages/filter/concerns/validate_storages_module_available.rb
new file mode 100644
index 00000000000..eb2250f1b1e
--- /dev/null
+++ b/modules/storages/app/models/queries/storages/work_packages/filter/concerns/validate_storages_module_available.rb
@@ -0,0 +1,41 @@
+#-- 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.
+#++
+
+module Queries::Storages::WorkPackages::Filter::Concerns::ValidateStoragesModuleAvailable
+ extend ActiveSupport::Concern
+
+ included do
+ validate :storages_module_available
+
+ def storages_module_available
+ return if OpenProject::FeatureDecisions.storages_module_active?
+
+ errors.add :base, I18n.t('activerecord.errors.messages.filter_does_not_exist')
+ end
+ end
+end
diff --git a/modules/storages/app/models/queries/storages/work_packages/filter/file_link_origin_id_filter.rb b/modules/storages/app/models/queries/storages/work_packages/filter/file_link_origin_id_filter.rb
index d1a3c182135..1f708388c3a 100644
--- a/modules/storages/app/models/queries/storages/work_packages/filter/file_link_origin_id_filter.rb
+++ b/modules/storages/app/models/queries/storages/work_packages/filter/file_link_origin_id_filter.rb
@@ -29,6 +29,7 @@
module Queries::Storages::WorkPackages::Filter
class FileLinkOriginIdFilter < ::Queries::WorkPackages::Filter::WorkPackageFilter
include StoragesFilterMixin
+ include Concerns::ValidateStoragesModuleAvailable
def filter_model
::Storages::FileLink
diff --git a/modules/storages/app/models/queries/storages/work_packages/filter/linkable_to_storage_id_filter.rb b/modules/storages/app/models/queries/storages/work_packages/filter/linkable_to_storage_id_filter.rb
index 897c937924e..3165ba8f826 100644
--- a/modules/storages/app/models/queries/storages/work_packages/filter/linkable_to_storage_id_filter.rb
+++ b/modules/storages/app/models/queries/storages/work_packages/filter/linkable_to_storage_id_filter.rb
@@ -29,6 +29,7 @@
module Queries::Storages::WorkPackages::Filter
class LinkableToStorageIdFilter < ::Queries::WorkPackages::Filter::WorkPackageFilter
include StoragesFilterMixin
+ include Concerns::ValidateStoragesModuleAvailable
def filter_model
::Storages::Storage
diff --git a/modules/storages/app/models/queries/storages/work_packages/filter/linkable_to_storage_url_filter.rb b/modules/storages/app/models/queries/storages/work_packages/filter/linkable_to_storage_url_filter.rb
index bcf78a4b091..98e14287c50 100644
--- a/modules/storages/app/models/queries/storages/work_packages/filter/linkable_to_storage_url_filter.rb
+++ b/modules/storages/app/models/queries/storages/work_packages/filter/linkable_to_storage_url_filter.rb
@@ -29,6 +29,7 @@
module Queries::Storages::WorkPackages::Filter
class LinkableToStorageUrlFilter < ::Queries::WorkPackages::Filter::WorkPackageFilter
include StoragesFilterMixin
+ include Concerns::ValidateStoragesModuleAvailable
def filter_model
::Storages::Storage
diff --git a/modules/storages/app/models/queries/storages/work_packages/filter/storage_id_filter.rb b/modules/storages/app/models/queries/storages/work_packages/filter/storage_id_filter.rb
index f0733a41b77..4bc8b34f13c 100644
--- a/modules/storages/app/models/queries/storages/work_packages/filter/storage_id_filter.rb
+++ b/modules/storages/app/models/queries/storages/work_packages/filter/storage_id_filter.rb
@@ -29,6 +29,7 @@
module Queries::Storages::WorkPackages::Filter
class StorageIdFilter < ::Queries::WorkPackages::Filter::WorkPackageFilter
include StoragesFilterMixin
+ include Concerns::ValidateStoragesModuleAvailable
def filter_model
::Storages::FileLink
diff --git a/modules/storages/app/models/queries/storages/work_packages/filter/storage_url_filter.rb b/modules/storages/app/models/queries/storages/work_packages/filter/storage_url_filter.rb
index 12b2c464192..c0ec908289c 100644
--- a/modules/storages/app/models/queries/storages/work_packages/filter/storage_url_filter.rb
+++ b/modules/storages/app/models/queries/storages/work_packages/filter/storage_url_filter.rb
@@ -29,6 +29,7 @@
module Queries::Storages::WorkPackages::Filter
class StorageUrlFilter < ::Queries::WorkPackages::Filter::WorkPackageFilter
include StoragesFilterMixin
+ include Concerns::ValidateStoragesModuleAvailable
def filter_model
::Storages::Storage
diff --git a/modules/storages/spec/requests/api/v3/work_packages/shared_filter_examples.rb b/modules/storages/spec/requests/api/v3/work_packages/shared_filter_examples.rb
new file mode 100644
index 00000000000..be256998b00
--- /dev/null
+++ b/modules/storages/spec/requests/api/v3/work_packages/shared_filter_examples.rb
@@ -0,0 +1,38 @@
+#-- 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.
+#++
+
+require 'spec_helper'
+
+shared_examples_for 'filter unavailable when storages module is inactive' do
+ context 'when storages module is inactive', :disable_storages do
+ it_behaves_like 'error response',
+ 400,
+ 'InvalidQuery',
+ 'filter does not exist.'
+ end
+end
diff --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.rb
index d46387bfc4a..aeb86ed1e9e 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
@@ -28,6 +28,7 @@
require 'spec_helper'
require_module_spec_helper
+require_relative 'shared_filter_examples'
# rubocop:disable RSpec/MultipleMemoizedHelpers
describe 'API v3 work packages resource with filters for the linkable to storage attribute',
@@ -123,6 +124,8 @@ describe 'API v3 work packages resource with filters for the linkable to storage
let(:elements) { [] }
end
end
+
+ include_examples 'filter unavailable when storages module is inactive'
end
context 'with filter for storage url' do
@@ -165,6 +168,8 @@ describe 'API v3 work packages resource with filters for the linkable to storage
let(:elements) { [] }
end
end
+
+ include_examples 'filter unavailable when storages module is inactive'
end
end
end
diff --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.rb
index f5e6b9b06f2..5aaeeec501b 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
@@ -28,6 +28,7 @@
require 'spec_helper'
require_module_spec_helper
+require_relative 'shared_filter_examples'
# rubocop:disable RSpec/MultipleMemoizedHelpers
describe 'API v3 work packages resource with filters for linked storage file',
@@ -138,6 +139,8 @@ describe 'API v3 work packages resource with filters for linked storage file',
let(:elements) { [] }
end
end
+
+ include_examples 'filter unavailable when storages module is inactive'
end
context 'with single filter for storage id' do
@@ -172,6 +175,8 @@ describe 'API v3 work packages resource with filters for linked storage file',
let(:elements) { [] }
end
end
+
+ include_examples 'filter unavailable when storages module is inactive'
end
context 'with single filter for storage url' do
@@ -214,6 +219,8 @@ describe 'API v3 work packages resource with filters for linked storage file',
let(:elements) { [] }
end
end
+
+ include_examples 'filter unavailable when storages module is inactive'
end
context 'with combined filter of file id and storage id' do