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
hide storages from web pages if module is not active
Christophe Bliard05c804801b30
diff --git a/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb b/modules/storages/app/controllers/storages/admin/projects_storages_controller.rbindex 99d0478ad5d..d7e6346886a 100644--- a/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb+++ b/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb@@ -39,6 +39,10 @@ class Storages::Admin::ProjectsStoragesController < Projects::SettingsController# This defines @object as the model instance.model_object Storages::ProjectStorage+ # Will return a 404 if the storages module has not been made available through+ # a feature flag.+ before_action :ensure_storages_module_active+before_action :find_model_object, only: %i[destroy] # Fill @object with ProjectStorage# No need to before_action :find_project_by_project_id as SettingsController already checks# No need to check for before_action :authorize, as the SettingsController already checks this.@@ -114,6 +118,12 @@ class Storages::Admin::ProjectsStoragesController < Projects::SettingsControllerprivate+ def ensure_storages_module_active+ return if OpenProject::FeatureDecisions.storages_module_active?++ raise ActionController::RoutingError, 'Not Found'+ end+# Define the list of permitted parameters for creating/updating a ProjectStorage.# Called by create and update actions above.def permitted_create_paramsdiff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rbindex cfcbbaf3a4f..292b4232886 100644--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb@@ -34,6 +34,10 @@ class Storages::Admin::StoragesController < ApplicationController# specify which model #find_model_object should look upmodel_object Storages::Storage+ # Will return a 404 if the storages module has not been made available through+ # a feature flag.+ before_action :ensure_storages_module_active+# Before executing any action below: Make sure the current user is an admin# and set the @<controller_name> variable to the object referenced in the URL.before_action :require_admin@@ -150,6 +154,12 @@ class Storages::Admin::StoragesController < ApplicationControllerprivate+ def ensure_storages_module_active+ return if OpenProject::FeatureDecisions.storages_module_active?++ raise ActionController::RoutingError, 'Not Found'+ end+# Called by create and update above in order to check if the# update parameters are correctly set.def permitted_storage_paramsdiff --git a/modules/storages/lib/open_project/storages/engine.rb b/modules/storages/lib/open_project/storages/engine.rbindex 03a99dc02df..88e07eef128 100644--- a/modules/storages/lib/open_project/storages/engine.rb+++ b/modules/storages/lib/open_project/storages/engine.rb@@ -70,13 +70,14 @@ module OpenProject::Storagesmenu :admin_menu,:storages_admin_settings,{ controller: '/storages/admin/storages', action: :index },- if: Proc.new { User.current.admin? },+ if: Proc.new { User.current.admin? && OpenProject::FeatureDecisions.storages_module_active? },caption: :project_module_storages,icon: 'icon2 icon-hosting'menu :project_menu,:settings_projects_storages,{ controller: '/storages/admin/projects_storages', action: 'index' },+ if: Proc.new { OpenProject::FeatureDecisions.storages_module_active? },caption: :project_module_storages,parent: :settingsenddiff --git a/modules/storages/spec/features/storages_module_disabled_spec.rb b/modules/storages/spec/features/storages_module_disabled_spec.rbnew file mode 100644index 00000000000..0d6fe05db74--- /dev/null+++ b/modules/storages/spec/features/storages_module_disabled_spec.rb@@ -0,0 +1,111 @@+#-- 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_relative '../spec_helper'++# Checks that disabling storages modules hides everything related to it in web+# interface. Enable it first, check everything present, then disable it, and+# check everything present.+describe 'Disablement of storages module', type: :feature, js: true do+ let(:admin) { create(:admin) }++ let(:role) do+ create(:role,+ permissions: %i[manage_storages_in_project+ select_project_modules+ edit_project])+ end+ let(:storage) { create(:storage, name: "Storage 1") }+ let(:project) do+ create(:project,+ enabled_module_names: %i[storages work_package_tracking])+ end++ before do+ storage+ project+ login_as admin++ @old_value = Capybara.raise_server_errors+ Capybara.raise_server_errors = false+ end++ around do |example|+ old_value = Capybara.raise_server_errors+ Capybara.raise_server_errors = false+ example.run+ ensure+ Capybara.raise_server_errors = old_value+ end++ it 'removes storages from administration and project pages' do+ Setting.feature_storages_module_active = true+ expect_pages_to_include_storages_information+ Setting.feature_storages_module_active = false+ expect_pages_not_to_include_storages_information+ end++ def expect_pages_not_to_include_storages_information+ run_pages_assertions_about_storages_visibility(expectation_target: :not_to)+ end++ def expect_pages_to_include_storages_information+ run_pages_assertions_about_storages_visibility(expectation_target: :to)+ end++ def run_pages_assertions_about_storages_visibility(expectation_target:)+ # Administration+ visit admin_index_path+ within '#menu-sidebar' do+ expect(page).send(expectation_target, have_text(I18n.t(:project_module_storages)))+ end+ within '#content' do+ expect(page).send(expectation_target, have_text(I18n.t(:project_module_storages)))+ end++ visit admin_settings_projects_path+ within '#content' do+ expect(page).send(expectation_target, have_text(I18n.t(:project_module_storages)))+ end++ visit admin_settings_storages_path+ expect(page).send(expectation_target, have_text(I18n.t(:project_module_storages)))++ # Project settings+ visit project_settings_modules_path(project)+ within '#menu-sidebar' do+ expect(page).send(expectation_target, have_text(I18n.t(:project_module_storages)))+ end+ within '#content' do+ expect(page).send(expectation_target, have_text(I18n.t(:project_module_storages)))+ end++ visit project_settings_projects_storages_path(project)+ expect(page).send(expectation_target, have_text(I18n.t('storages.page_titles.project_settings.index')))+ end+end