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
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.rbnew file mode 100644index 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+enddiff --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.rbindex 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::Filterclass FileLinkOriginIdFilter < ::Queries::WorkPackages::Filter::WorkPackageFilterinclude StoragesFilterMixin+ include Concerns::ValidateStoragesModuleAvailabledef filter_model::Storages::FileLinkdiff --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.rbindex 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::Filterclass LinkableToStorageIdFilter < ::Queries::WorkPackages::Filter::WorkPackageFilterinclude StoragesFilterMixin+ include Concerns::ValidateStoragesModuleAvailabledef filter_model::Storages::Storagediff --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.rbindex 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::Filterclass LinkableToStorageUrlFilter < ::Queries::WorkPackages::Filter::WorkPackageFilterinclude StoragesFilterMixin+ include Concerns::ValidateStoragesModuleAvailabledef filter_model::Storages::Storagediff --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.rbindex 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::Filterclass StorageIdFilter < ::Queries::WorkPackages::Filter::WorkPackageFilterinclude StoragesFilterMixin+ include Concerns::ValidateStoragesModuleAvailabledef filter_model::Storages::FileLinkdiff --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.rbindex 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::Filterclass StorageUrlFilter < ::Queries::WorkPackages::Filter::WorkPackageFilterinclude StoragesFilterMixin+ include Concerns::ValidateStoragesModuleAvailabledef filter_model::Storages::Storagediff --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.rbnew file mode 100644index 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+enddiff --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 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/MultipleMemoizedHelpersdescribe '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 storagelet(:elements) { [] }endend++ include_examples 'filter unavailable when storages module is inactive'endcontext 'with filter for storage url' do@@ -165,6 +168,8 @@ describe 'API v3 work packages resource with filters for the linkable to storagelet(:elements) { [] }endend++ include_examples 'filter unavailable when storages module is inactive'endendenddiff --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 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/MultipleMemoizedHelpersdescribe '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) { [] }endend++ include_examples 'filter unavailable when storages module is inactive'endcontext '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) { [] }endend++ include_examples 'filter unavailable when storages module is inactive'endcontext '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) { [] }endend++ include_examples 'filter unavailable when storages module is inactive'endcontext 'with combined filter of file id and storage id' do