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
[#49218] Configuration checks that prevent activation of unconfigured storages (#13536)
Kabiru Mwenja209da323b8c4
diff --git a/modules/storages/app/components/storages/admin/configuration_checks_component.rb b/modules/storages/app/components/storages/admin/configuration_checks_component.rbnew file mode 100644index 00000000000..d454457f060--- /dev/null+++ b/modules/storages/app/components/storages/admin/configuration_checks_component.rb@@ -0,0 +1,46 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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 Storages::Admin+ class ConfigurationChecksComponent < Primer::Beta::Flash+ def initialize(storage:, spacious: true, dismissible: false, icon: :alert, scheme: :danger, **kwargs)+ @storage = storage+ super(spacious:, dismissible:, icon:, scheme:, **kwargs)+ end++ def render?+ end++ def content+ I18n.t('storages.configuration_checks.incomplete')+ end+ end+enddiff --git a/modules/storages/app/components/storages/admin/row_component.rb b/modules/storages/app/components/storages/admin/row_component.rbindex d626d10890a..0679dc827e0 100644--- a/modules/storages/app/components/storages/admin/row_component.rb+++ b/modules/storages/app/components/storages/admin/row_component.rb@@ -38,7 +38,22 @@ module Storages::Admin# Delegate delegates the execution of certain methods to :storage.# https://www.rubydoc.info/gems/activesupport/Module:delegate- delegate :created_at, :name, :host, :provider_type, to: :storage+ delegate :created_at, :host, :provider_type, :configured?, to: :storage++ def row_css_id+ helpers.dom_id storage+ end++ def name+ if configured?+ storage.name+ else+ render(Primer::Beta::Octicon.new(:'alert-fill', size: :small, color: :severe)) ++ content_tag(:span,+ storage.name,+ class: 'pl-2')+ end+ enddef creatoricon = helpers.avatar storage.creator, size: :minidiff --git a/modules/storages/app/controllers/storages/admin/project_storages_controller.rb b/modules/storages/app/controllers/storages/admin/project_storages_controller.rbindex cd88eb9ff8b..c44bf34c305 100644--- a/modules/storages/app/controllers/storages/admin/project_storages_controller.rb+++ b/modules/storages/app/controllers/storages/admin/project_storages_controller.rb@@ -166,6 +166,9 @@ class Storages::Admin::ProjectStoragesController < Projects::SettingsControllerenddef available_storages- Storages::Storage.visible.not_enabled_for_project(@project)+ Storages::Storage+ .visible+ .not_enabled_for_project(@project)+ .configuredendenddiff --git a/modules/storages/app/models/storages/common/configuration_checks.rb b/modules/storages/app/models/storages/common/configuration_checks.rbnew file mode 100644index 00000000000..550b8dbea87--- /dev/null+++ b/modules/storages/app/models/storages/common/configuration_checks.rb@@ -0,0 +1,50 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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 Storages::Common+ module ConfigurationChecks+ extend ActiveSupport::Concern++ included do+ scope :configured, -> do+ where.associated(:oauth_client, :oauth_application)+ .where("storages.host IS NOT NULL AND storages.name IS NOT NULL")+ end+ end++ def configured?+ configuration_checks.values.all?+ end++ def configuration_checks+ { host_name_configured: (host.present? && name.present?),+ openproject_oauth_application_configured: oauth_application.present?,+ storage_oauth_client_configured: oauth_client.present? }+ end+ end+enddiff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rbindex 4684b28d7b8..d0a73998c48 100644--- a/modules/storages/app/models/storages/storage.rb+++ b/modules/storages/app/models/storages/storage.rb@@ -39,6 +39,8 @@class Storages::Storage < ApplicationRecordself.inheritance_column = :provider_type+ include ::Storages::Common::ConfigurationChecks+# One Storage can have multiple FileLinks, representing external files.## FileLink deletion is done:diff --git a/modules/storages/app/views/storages/admin/storages/edit.html.erb b/modules/storages/app/views/storages/admin/storages/edit.html.erbindex 19504c80415..3961fc19069 100644--- a/modules/storages/app/views/storages/admin/storages/edit.html.erb+++ b/modules/storages/app/views/storages/admin/storages/edit.html.erb@@ -5,6 +5,8 @@<% local_assigns[:additional_breadcrumb] = @object.name %><%= toolbar title: t('label_edit_x', x: @object.name) %>+<%= render(::Storages::Admin::ConfigurationChecksComponent.new(storage: @object)) %>+<%= labelled_tabular_form_for @object, url: admin_settings_storage_path(@object), as: :storages_storage do |f| -%><%= render partial: 'form', locals: { f: f } %><%= styled_button_tag t(:button_save), class: "-highlight -with-icon icon-checkmark" %>diff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.ymlindex 8dbaa19b07d..b13234a89d4 100644--- a/modules/storages/config/locales/en.yml+++ b/modules/storages/config/locales/en.yml@@ -110,6 +110,8 @@ en:project_folder: >The project folder is the default folder for file uploads for this project.Users can nevertheless still upload files to other locations.+ configuration_checks:+ incomplete: "The setup of this storage is incomplete."delete_warning:storage: >Are you sure you want to delete this storage? This will also delete the storage from all projects where it is used.diff --git a/modules/storages/spec/components/admin/configuration_checks_component_spec.rb b/modules/storages/spec/components/admin/configuration_checks_component_spec.rbnew file mode 100644index 00000000000..c17d88ac1f4--- /dev/null+++ b/modules/storages/spec/components/admin/configuration_checks_component_spec.rb@@ -0,0 +1,54 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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'++RSpec.describe Storages::Admin::ConfigurationChecksComponent,+ type: :component do+ describe '#render?' do+ context 'with all configuration checks complete' do+ it 'returns false, does not render view component' do+ storage = build_stubbed(:storage,+ oauth_application: build_stubbed(:oauth_application),+ oauth_client: build_stubbed(:oauth_client))+ component = described_class.new(storage:)++ expect(render_inline(component).content).to be_blank+ end+ end++ context 'with incomplete configuration checks' do+ it 'returns true, renders view component' do+ storage = build_stubbed(:storage, host: nil, name: nil)+ component = described_class.new(storage:)++ expect(render_inline(component)).to have_content('The setup of this storage is incomplete.')+ end+ end+ end+enddiff --git a/modules/storages/spec/components/project_storages/row_component_spec.rb b/modules/storages/spec/components/project_storages/row_component_spec.rbindex e48e3272c8d..6d1f13f46c6 100644--- a/modules/storages/spec/components/project_storages/row_component_spec.rb+++ b/modules/storages/spec/components/project_storages/row_component_spec.rb@@ -1,4 +1,32 @@-require 'rails_helper'+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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'RSpec.describe Storages::ProjectStorages::RowComponent,type: :component dodiff --git a/modules/storages/spec/features/admin_storages_spec.rb b/modules/storages/spec/features/admin_storages_spec.rbindex ede8f8d56dd..2139a96c127 100644--- a/modules/storages/spec/features/admin_storages_spec.rb+++ b/modules/storages/spec/features/admin_storages_spec.rb@@ -242,4 +242,44 @@ RSpec.describe 'Admin storages', :storage_server_helpers, js: true do# Also check that there are no more OAuthClient instances anymoreexpect(OAuthClient.all.count).to eq(0)end++ describe 'configuration checks' do+ let!(:configured_storage) do+ storage = create(:storage)+ create(:oauth_application, integration: storage)+ create(:oauth_client, integration: storage)+ storage+ end+ let!(:unconfigured_storage) { create(:storage) }++ it 'reports storages that are not configured correctly' do+ visit admin_settings_storages_path++ aggregate_failures 'storages view with configuration checks' do+ configured_storage_table_row = page.find_by_id("storages_nextcloud_storage_#{configured_storage.id}")+ unconfigured_storage_table_row = page.find_by_id("storages_nextcloud_storage_#{unconfigured_storage.id}")++ expect(configured_storage_table_row).not_to have_css('.octicon-alert-fill')+ expect(unconfigured_storage_table_row).to have_css('.octicon-alert-fill')+ end++ aggregate_failures 'individual storage view' do+ within "#storages_nextcloud_storage_#{configured_storage.id}" do+ page.find('td.buttons .icon-edit').click+ end++ expect(page).not_to have_css('.flash.flash-error')++ within('.op-breadcrumb') do+ click_link 'File storages'+ end++ within "#storages_nextcloud_storage_#{unconfigured_storage.id}" do+ page.find('td.buttons .icon-edit').click+ end++ expect(page).to have_css('.flash.flash-error', text: 'The setup of this storage is incomplete.')+ end+ end+ endenddiff --git a/modules/storages/spec/features/manage_project_storage_spec.rb b/modules/storages/spec/features/manage_project_storage_spec.rbindex a289ba078dc..5e44b612424 100644--- a/modules/storages/spec/features/manage_project_storage_spec.rb+++ b/modules/storages/spec/features/manage_project_storage_spec.rb@@ -203,4 +203,22 @@ RSpec.describe(expect(page).to have_current_path project_settings_project_storages_path(project)expect(page).to have_text(I18n.t('storages.no_results'))end++ describe 'configuration checks' do+ let(:configured_storage) { storage }+ let!(:unconfigured_storage) { create(:storage) }++ it 'excludes storages that are not configured correctly' do+ visit project_settings_project_storages_path(project)++ page.find('.toolbar .button--icon.icon-add').click++ aggregate_failures 'select field options' do+ expect(page).to have_select('storages_project_storage_storage_id',+ options: ["#{configured_storage.name} (#{configured_storage.short_provider_type})"])+ expect(page).not_to have_select('storages_project_storage_storage_id',+ options: ["#{unconfigured_storage.name} (#{unconfigured_storage.short_provider_type})"])+ end+ end+ endenddiff --git a/modules/storages/spec/models/common/configuration_checks_spec.rb b/modules/storages/spec/models/common/configuration_checks_spec.rbnew file mode 100644index 00000000000..2b835962550--- /dev/null+++ b/modules/storages/spec/models/common/configuration_checks_spec.rb@@ -0,0 +1,96 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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'++RSpec.describe Storages::Common::ConfigurationChecks do+ describe '.configured' do+ let!(:configured_storage) do+ storage = create(:storage)+ create(:oauth_application, integration: storage)+ create(:oauth_client, integration: storage)+ storage+ end+ let!(:unconfigured_storage) { create(:storage) }++ it 'returns only storages with complete configuration' do+ configured_storage_model = configured_storage.provider_type.constantize.find(configured_storage.id)+ unconfigured_storage_model = unconfigured_storage.provider_type.constantize.find(unconfigured_storage.id)++ expect(Storages::Storage.configured).to contain_exactly(configured_storage_model)+ expect(Storages::Storage.configured).not_to include(unconfigured_storage_model)+ end+ end++ describe '#configured?' do+ context 'with a complete configuration' do+ let(:storage) do+ build_stubbed(:storage,+ oauth_application: build_stubbed(:oauth_application),+ oauth_client: build_stubbed(:oauth_client))+ end++ it 'returns true' do+ expect(storage.configured?).to be(true)++ aggregate_failures 'configuration_checks' do+ expect(storage.configuration_checks)+ .to eq(host_name_configured: true,+ storage_oauth_client_configured: true,+ openproject_oauth_application_configured: true)+ end+ end+ end++ context 'without host name' do+ let(:storage) { build_stubbed(:storage, host: nil, name: nil) }++ it 'returns false' do+ aggregate_failures do+ expect(storage.configured?).to be(false)+ aggregate_failures 'configuration_checks' do+ expect(storage.configuration_checks[:host_name_configured]).to be(false)+ end+ end+ end+ end++ context 'without openproject and storage integrations' do+ let(:storage) { build_stubbed(:storage) }++ it 'returns false' do+ expect(storage.configured?).to be(false)++ aggregate_failures 'configuration_checks' do+ expect(storage.configuration_checks[:openproject_oauth_application_configured]).to be(false)+ expect(storage.configuration_checks[:storage_oauth_client_configured]).to be(false)+ end+ end+ end+ end+end