Skip to content

Commit

Permalink
[#49218] Configuration checks that prevent activation of unconfigured…
Browse files Browse the repository at this point in the history
  • Loading branch information
akabiru committed Sep 4, 2023
1 parent b96922a commit 0b2d53e
Show file tree
Hide file tree
Showing 12 changed files with 358 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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?
!@storage.configured?
end

def content
I18n.t('storages.configuration_checks.incomplete')
end
end
end
22 changes: 15 additions & 7 deletions modules/storages/app/components/storages/admin/row_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,24 @@ def storage
row
end

delegate :created_at, to: :storage
# Delegate delegates the execution of certain methods to :storage.
# https://www.rubydoc.info/gems/activesupport/Module:delegate
delegate :created_at, :host, :provider_type, :configured?, to: :storage

def name
link_to storage.name, admin_settings_storage_path(storage)
def row_css_id
helpers.dom_id storage
end

# Delegate delegates the execution of certain methods to :storage.
# https://www.rubydoc.info/gems/activesupport/Module:delegate
delegate :host, to: :storage
delegate :provider_type, to: :storage
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
end

def creator
icon = helpers.avatar storage.creator, size: :mini
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ def permitted_storage_settings_params
end

def available_storages
Storages::Storage.visible.not_enabled_for_project(@project)
Storages::Storage
.visible
.not_enabled_for_project(@project)
.configured
end
end
Original file line number Diff line number Diff line change
@@ -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
end
2 changes: 2 additions & 0 deletions modules/storages/app/models/storages/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
class Storages::Storage < ApplicationRecord
self.inheritance_column = :provider_type

include ::Storages::Common::ConfigurationChecks

# One Storage can have multiple FileLinks, representing external files.
#
# FileLink deletion is done:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" %>
Expand Down
2 changes: 2 additions & 0 deletions modules/storages/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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
end
Original file line number Diff line number Diff line change
@@ -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 do
Expand Down
40 changes: 40 additions & 0 deletions modules/storages/spec/features/admin_storages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,44 @@
# Also check that there are no more OAuthClient instances anymore
expect(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
end
end
18 changes: 18 additions & 0 deletions modules/storages/spec/features/manage_project_storage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,22 @@
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
end
end

0 comments on commit 0b2d53e

Please sign in to comment.