From 8e242e95aae5650454463f841cfcd152f92f1b6b Mon Sep 17 00:00:00 2001 From: Christophe Bliard Date: Mon, 4 Apr 2022 10:18:23 +0200 Subject: [PATCH] disable storages module by default through feature_storages_module_active setting --- config/constants/settings/definitions.rb | 4 ++ lib/open_project/feature_decisions.rb | 35 ++++++++++++++++++ .../lib/open_project/storages/engine.rb | 4 +- .../file_links/create_contract_spec.rb | 3 +- .../file_links/delete_contract_spec.rb | 3 +- .../project_storages/create_contract_spec.rb | 3 +- .../project_storages/delete_contract_spec.rb | 3 +- .../storages/storages/base_contract_spec.rb | 2 +- .../storages/storages/create_contract_spec.rb | 3 +- .../storages/storages/delete_contract_spec.rb | 3 +- .../storages/storages/update_contract_spec.rb | 3 +- .../spec/features/admin_storages_spec.rb | 2 +- .../create_and_delete_project_storage_spec.rb | 2 +- ...ete_project_storage_and_file_links_spec.rb | 2 +- .../manage_storage_in_project_spec.rb | 8 +++- .../api/v3/file_links/file_links_spec.rb | 3 +- .../requests/api/v3/storages/storages_spec.rb | 3 +- .../work_packages_linkable_filter_spec.rb | 2 + .../work_packages_linked_filter_spec.rb | 2 + .../project_storages/delete_service_spec.rb | 3 +- .../spec/support/enable_storages_module.rb | 9 +++++ spec/support/module_spec_helper.rb | 37 +++++++++++++++++++ 22 files changed, 123 insertions(+), 16 deletions(-) create mode 100644 lib/open_project/feature_decisions.rb create mode 100644 modules/storages/spec/support/enable_storages_module.rb create mode 100644 spec/support/module_spec_helper.rb diff --git a/config/constants/settings/definitions.rb b/config/constants/settings/definitions.rb index a143c16974..709385183d 100644 --- a/config/constants/settings/definitions.rb +++ b/config/constants/settings/definitions.rb @@ -387,6 +387,10 @@ Settings::Definition.define do value: 'enterprise-on-premises---euro---1-year', writable: false + add :feature_storages_module_active, + value: false, + format: :boolean + add :feeds_enabled, value: true diff --git a/lib/open_project/feature_decisions.rb b/lib/open_project/feature_decisions.rb new file mode 100644 index 0000000000..a3b49b1f48 --- /dev/null +++ b/lib/open_project/feature_decisions.rb @@ -0,0 +1,35 @@ +#-- 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 OpenProject + module FeatureDecisions + def self.storages_module_active? + Setting.feature_storages_module_active + end + end +end diff --git a/modules/storages/lib/open_project/storages/engine.rb b/modules/storages/lib/open_project/storages/engine.rb index 9a3c5e7e54..13107d1761 100644 --- a/modules/storages/lib/open_project/storages/engine.rb +++ b/modules/storages/lib/open_project/storages/engine.rb @@ -50,7 +50,9 @@ module OpenProject::Storages name: 'OpenProject Storages' do # Defines permission constraints used in the module (controller, etc.) # Permissions documentation: https://www.openproject.org/docs/development/concepts/permissions/#definition-of-permissions - project_module :storages, dependencies: :work_package_tracking do + project_module :storages, + dependencies: :work_package_tracking, + if: ->(*) { OpenProject::FeatureDecisions.storages_module_active? } do permission :view_file_links, {}, dependencies: %i[view_work_packages] diff --git a/modules/storages/spec/contracts/storages/file_links/create_contract_spec.rb b/modules/storages/spec/contracts/storages/file_links/create_contract_spec.rb index 4374b41e80..c43e1cbb13 100644 --- a/modules/storages/spec/contracts/storages/file_links/create_contract_spec.rb +++ b/modules/storages/spec/contracts/storages/file_links/create_contract_spec.rb @@ -27,10 +27,11 @@ #++ require 'spec_helper' +require_module_spec_helper require 'contracts/shared/model_contract_shared_context' require_relative 'shared_contract_examples' -describe Storages::FileLinks::CreateContract do +describe Storages::FileLinks::CreateContract, :enable_storages do include_context 'ModelContract shared context' it_behaves_like 'file_link contract' do diff --git a/modules/storages/spec/contracts/storages/file_links/delete_contract_spec.rb b/modules/storages/spec/contracts/storages/file_links/delete_contract_spec.rb index 962f03d685..9561f4993d 100644 --- a/modules/storages/spec/contracts/storages/file_links/delete_contract_spec.rb +++ b/modules/storages/spec/contracts/storages/file_links/delete_contract_spec.rb @@ -27,9 +27,10 @@ #++ require 'spec_helper' +require_module_spec_helper require 'contracts/shared/model_contract_shared_context' -describe ::Storages::FileLinks::DeleteContract do +describe ::Storages::FileLinks::DeleteContract, :enable_storages do include_context 'ModelContract shared context' let(:current_user) { create(:user) } diff --git a/modules/storages/spec/contracts/storages/project_storages/create_contract_spec.rb b/modules/storages/spec/contracts/storages/project_storages/create_contract_spec.rb index 1deb3f6007..4f5e7aa8d6 100644 --- a/modules/storages/spec/contracts/storages/project_storages/create_contract_spec.rb +++ b/modules/storages/spec/contracts/storages/project_storages/create_contract_spec.rb @@ -27,10 +27,11 @@ #++ require 'spec_helper' +require_module_spec_helper require 'contracts/shared/model_contract_shared_context' require_relative 'shared_contract_examples' -describe Storages::ProjectStorages::CreateContract do +describe Storages::ProjectStorages::CreateContract, :enable_storages do include_context 'ModelContract shared context' it_behaves_like 'ProjectStorages contract' do diff --git a/modules/storages/spec/contracts/storages/project_storages/delete_contract_spec.rb b/modules/storages/spec/contracts/storages/project_storages/delete_contract_spec.rb index dbd99d1147..b7b4772085 100644 --- a/modules/storages/spec/contracts/storages/project_storages/delete_contract_spec.rb +++ b/modules/storages/spec/contracts/storages/project_storages/delete_contract_spec.rb @@ -27,9 +27,10 @@ #++ require 'spec_helper' +require_module_spec_helper require 'contracts/shared/model_contract_shared_context' -describe ::Storages::ProjectStorages::DeleteContract do +describe ::Storages::ProjectStorages::DeleteContract, :enable_storages do include_context 'ModelContract shared context' let(:current_user) { create(:user) } diff --git a/modules/storages/spec/contracts/storages/storages/base_contract_spec.rb b/modules/storages/spec/contracts/storages/storages/base_contract_spec.rb index 3906477e94..7a939606d2 100644 --- a/modules/storages/spec/contracts/storages/storages/base_contract_spec.rb +++ b/modules/storages/spec/contracts/storages/storages/base_contract_spec.rb @@ -28,7 +28,7 @@ require_relative '../../../spec_helper' -describe Storages::Storages::BaseContract, :storage_server_helpers, webmock: true do +describe Storages::Storages::BaseContract, :enable_storages, :storage_server_helpers, webmock: true do let(:current_user) { create(:admin) } let(:storage_host) { 'https://host1.example.com' } let(:storage) { build(:storage, host: storage_host) } diff --git a/modules/storages/spec/contracts/storages/storages/create_contract_spec.rb b/modules/storages/spec/contracts/storages/storages/create_contract_spec.rb index 164259c7b0..a4eee44bee 100644 --- a/modules/storages/spec/contracts/storages/storages/create_contract_spec.rb +++ b/modules/storages/spec/contracts/storages/storages/create_contract_spec.rb @@ -27,10 +27,11 @@ #++ require 'spec_helper' +require_module_spec_helper require 'contracts/shared/model_contract_shared_context' require_relative 'shared_contract_examples' -describe Storages::Storages::CreateContract do +describe Storages::Storages::CreateContract, :enable_storages do include_context 'ModelContract shared context' it_behaves_like 'storage contract' do diff --git a/modules/storages/spec/contracts/storages/storages/delete_contract_spec.rb b/modules/storages/spec/contracts/storages/storages/delete_contract_spec.rb index 10bddf2647..0453a04120 100644 --- a/modules/storages/spec/contracts/storages/storages/delete_contract_spec.rb +++ b/modules/storages/spec/contracts/storages/storages/delete_contract_spec.rb @@ -27,9 +27,10 @@ #++ require 'spec_helper' +require_module_spec_helper require 'contracts/shared/model_contract_shared_context' -describe ::Storages::Storages::DeleteContract do +describe ::Storages::Storages::DeleteContract, :enable_storages do include_context 'ModelContract shared context' let(:storage) { create(:storage) } diff --git a/modules/storages/spec/contracts/storages/storages/update_contract_spec.rb b/modules/storages/spec/contracts/storages/storages/update_contract_spec.rb index da1a56d2e8..2a86c22de4 100644 --- a/modules/storages/spec/contracts/storages/storages/update_contract_spec.rb +++ b/modules/storages/spec/contracts/storages/storages/update_contract_spec.rb @@ -27,10 +27,11 @@ #++ require 'spec_helper' +require_module_spec_helper require 'contracts/shared/model_contract_shared_context' require_relative 'shared_contract_examples' -describe ::Storages::Storages::UpdateContract do +describe ::Storages::Storages::UpdateContract, :enable_storages do include_context 'ModelContract shared context' it_behaves_like 'storage contract' do diff --git a/modules/storages/spec/features/admin_storages_spec.rb b/modules/storages/spec/features/admin_storages_spec.rb index 95c0dcdd29..434710e6a0 100644 --- a/modules/storages/spec/features/admin_storages_spec.rb +++ b/modules/storages/spec/features/admin_storages_spec.rb @@ -28,7 +28,7 @@ require_relative '../spec_helper' -describe 'Admin storages', :storage_server_helpers, type: :feature, js: true do +describe 'Admin storages', :enable_storages, :storage_server_helpers, type: :feature, js: true do let(:admin) { create(:admin) } before do diff --git a/modules/storages/spec/features/create_and_delete_project_storage_spec.rb b/modules/storages/spec/features/create_and_delete_project_storage_spec.rb index 754919d426..4425abc5e4 100644 --- a/modules/storages/spec/features/create_and_delete_project_storage_spec.rb +++ b/modules/storages/spec/features/create_and_delete_project_storage_spec.rb @@ -31,7 +31,7 @@ require_relative '../spec_helper' # Setup storages in Project -> Settings -> File Storages # This tests assumes that a Storage has already been setup # in the Admin section, tested by admin_storage_spec.rb. -describe 'Activation of storages in projects', type: :feature, js: true do +describe 'Activation of storages in projects', :enable_storages, type: :feature, js: true do let(:user) { create(:user) } # The first page is the Project -> Settings -> General page, so we need # to provide the user with the edit_project permission in the role. diff --git a/modules/storages/spec/features/delete_project_storage_and_file_links_spec.rb b/modules/storages/spec/features/delete_project_storage_and_file_links_spec.rb index aa61ec4757..db50a3ac73 100644 --- a/modules/storages/spec/features/delete_project_storage_and_file_links_spec.rb +++ b/modules/storages/spec/features/delete_project_storage_and_file_links_spec.rb @@ -30,7 +30,7 @@ require_relative '../spec_helper' # Test if the deletion of a ProjectStorage actually deletes related FileLink # objects. -describe 'Delete ProjectStorage with FileLinks', type: :feature, js: true do +describe 'Delete ProjectStorage with FileLinks', :enable_storages, type: :feature, js: true do let(:user) { create(:user) } let(:role) { create(:existing_role, permissions: [:manage_storages_in_project]) } let(:project) do diff --git a/modules/storages/spec/permissions/manage_storage_in_project_spec.rb b/modules/storages/spec/permissions/manage_storage_in_project_spec.rb index 0aa6b6a124..f3253be905 100644 --- a/modules/storages/spec/permissions/manage_storage_in_project_spec.rb +++ b/modules/storages/spec/permissions/manage_storage_in_project_spec.rb @@ -28,11 +28,17 @@ require 'spec_helper' require 'support/permission_specs' +require_module_spec_helper -describe Storages::Admin::ProjectsStoragesController, 'manage_storage_in_project permission', type: :controller do +# rubocop:disable RSpec/EmptyExampleGroup +describe Storages::Admin::ProjectsStoragesController, + 'manage_storage_in_project permission', + :enable_storages, + type: :controller do include PermissionSpecs controller_actions.each do |action| check_permission_required_for("#{described_class.controller_path}##{action}", :manage_storages_in_project) end end +# rubocop:enable RSpec/EmptyExampleGroup 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.rb index 119b6dbca1..dd100cda92 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 @@ -27,9 +27,10 @@ #++ require 'spec_helper' +require_module_spec_helper # rubocop:disable RSpec/MultipleMemoizedHelpers -describe 'API v3 file links resource', type: :request do +describe 'API v3 file links resource', :enable_storages, type: :request do include API::V3::Utilities::PathHelper let(:permissions) { %i(view_work_packages view_file_links) } diff --git a/modules/storages/spec/requests/api/v3/storages/storages_spec.rb b/modules/storages/spec/requests/api/v3/storages/storages_spec.rb index 03ae5650a5..df59cc3123 100644 --- a/modules/storages/spec/requests/api/v3/storages/storages_spec.rb +++ b/modules/storages/spec/requests/api/v3/storages/storages_spec.rb @@ -27,8 +27,9 @@ #++ require 'spec_helper' +require_module_spec_helper -describe 'API v3 storages resource', type: :request, content_type: :json do +describe 'API v3 storages resource', :enable_storages, type: :request, content_type: :json do include API::V3::Utilities::PathHelper let(:permissions) { %i(view_file_links) } 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 57ea1d9fb4..4bb50b637a 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 @@ -27,9 +27,11 @@ #++ require 'spec_helper' +require_module_spec_helper # rubocop:disable RSpec/MultipleMemoizedHelpers describe 'API v3 work packages resource with filters for the linkable to storage attribute', + :enable_storages, type: :request, content_type: :json do include API::V3::Utilities::PathHelper 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 df8992c633..13fa6462e1 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 @@ -27,9 +27,11 @@ #++ require 'spec_helper' +require_module_spec_helper # rubocop:disable RSpec/MultipleMemoizedHelpers describe 'API v3 work packages resource with filters for linked storage file', + :enable_storages, type: :request, content_type: :json do include API::V3::Utilities::PathHelper diff --git a/modules/storages/spec/services/storages/project_storages/delete_service_spec.rb b/modules/storages/spec/services/storages/project_storages/delete_service_spec.rb index a69709e1bd..15d8575afd 100644 --- a/modules/storages/spec/services/storages/project_storages/delete_service_spec.rb +++ b/modules/storages/spec/services/storages/project_storages/delete_service_spec.rb @@ -27,9 +27,10 @@ #++ require 'spec_helper' +require_module_spec_helper require 'services/base_services/behaves_like_delete_service' -describe ::Storages::ProjectStorages::DeleteService, type: :model do +describe ::Storages::ProjectStorages::DeleteService, :enable_storages, type: :model do context 'with records written to DB' do let(:user) { create(:user) } let(:role) { create(:existing_role, permissions: [:manage_storages_in_project]) } diff --git a/modules/storages/spec/support/enable_storages_module.rb b/modules/storages/spec/support/enable_storages_module.rb new file mode 100644 index 0000000000..7c11aa48f9 --- /dev/null +++ b/modules/storages/spec/support/enable_storages_module.rb @@ -0,0 +1,9 @@ +RSpec.shared_context "with storages module enabled" do + before do + allow(OpenProject::FeatureDecisions).to receive(:storages_module_active?).and_return(true) + end +end + +RSpec.configure do |rspec| + rspec.include_context "with storages module enabled", enable_storages: true +end diff --git a/spec/support/module_spec_helper.rb b/spec/support/module_spec_helper.rb new file mode 100644 index 0000000000..84a9e4781b --- /dev/null +++ b/spec/support/module_spec_helper.rb @@ -0,0 +1,37 @@ +#-- 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 docs/COPYRIGHT.rdoc for more details. +#++ + +# load the module spec_helper.rb from calling spec if it exists +def require_module_spec_helper + module_caller = caller.grep(Regexp.new("\\A#{Rails.root.join('modules')}")).first + return unless module_caller + + module_name = module_caller.scan(/modules\/\w+/).first + module_spec_helper = Rails.root.join("#{module_name}/spec/spec_helper.rb") + require module_spec_helper if module_spec_helper.file? +end