Skip to content

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

feat[Op#50737]: Blueprint for select storage provider form

Kabiru Mwenja268ba1710e36
diff --git a/modules/storages/app/components/storages/admin/select_storage_provider_component.html.erb b/modules/storages/app/components/storages/admin/select_storage_provider_component.html.erb
new file mode 100644
index 00000000000..9438d9bffca
--- /dev/null
+++ b/modules/storages/app/components/storages/admin/select_storage_provider_component.html.erb
@@ -0,0 +1,69 @@
+<%=
+ render(OpTurbo::FrameComponent.new(id: :storages_storage, context: :select_storage_provider)) do
+ render(Primer::Beta::BorderBox.new) do |component|
+ component.with_header(color: :default) do
+ render(Primer::Beta::Text.new(font_weight: :semibold)) { I18n.t('storages.file_storage_view.general_information') }
+ end
+
+ component.with_row(scheme: :default) do
+ render(
+ Primer::Beta::Text.new(
+ tag: :div,
+ test_selector: 'storage-select-provider-form',
+ data: {
+ controller: "storages--select-provider-form",
+ application_target: "dynamic"
+ }
+ )
+ ) do
+ primer_form_with(
+ model: storage,
+ url: select_provider_admin_settings_storages_path,
+ data: {
+ storages__select_provider_form_provider_type_value: storage.provider_type,
+ storages__select_provider_form_target: 'providerForm',
+ }
+ ) do |form|
+ flex_layout do |general_info_row|
+ general_info_row.with_row(mb: 3) do
+ render(
+ Storages::Admin::ProviderTypeSelectForm.new(
+ form,
+ storage:,
+ select_list_options: {
+ # FIXME: Auto submit on provider select
+ # data: { action: 'change->storages--select-provider-form#showProviderForm' },
+ }
+ )
+ )
+ end
+
+ general_info_row.with_row(mb: 3) do
+ render(Storages::Admin::ProviderNameInputForm.new(form))
+ end
+
+ general_info_row.with_row do
+ render(
+ Storages::Admin::SubmitOrCancelForm.new(
+ form,
+ storage:,
+ submit_button_options: {
+ # FIXME: change to disabled: true, should Auto submit on provider select
+ disabled: false,
+ test_selector: 'storage-select-provider-submit-button'
+ },
+ cancel_button_options: {
+ href: admin_settings_storages_path,
+ test_selector: 'storage-select-provider-cancel-button',
+ target: '_top'
+ }
+ )
+ )
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+%>
diff --git a/modules/storages/app/components/storages/admin/select_storage_provider_component.rb b/modules/storages/app/components/storages/admin/select_storage_provider_component.rb
new file mode 100644
index 00000000000..3061a77acc6
--- /dev/null
+++ b/modules/storages/app/components/storages/admin/select_storage_provider_component.rb
@@ -0,0 +1,36 @@
+# 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 SelectStorageProviderComponent < ApplicationComponent
+ include OpPrimer::ComponentHelpers
+ alias_method :storage, :model
+ end
+end
diff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rb
index 02a7e13aad7..8af1367e97e 100644
--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb
@@ -65,14 +65,29 @@ class Storages::Admin::StoragesController < ApplicationController
# Set default parameters using a "service".
# See also: storages/services/storages/storages/set_attributes_services.rb
# That service inherits from ::BaseServices::SetAttributes
+ model_class = OpenProject::FeatureDecisions.storage_primer_design_active? ? Storages::Storage : Storages::NextcloudStorage
@storage = ::Storages::Storages::SetAttributesService
.new(user: current_user,
- model: Storages::NextcloudStorage.new,
+ model: model_class.new,
contract_class: EmptyContract)
.call
.result
end
+ def select_provider
+ @object = Storages::Storage.new(permitted_storage_params(:storages_storage))
+ service_result = ::Storages::Storages::SetAttributesService
+ .new(user: current_user,
+ model: @object,
+ contract_class: Storages::Storages::BaseContract,
+ contract_options: { skip_provider_type_strategy: true })
+ .call
+ @storage = service_result.result
+
+ service_result.on_failure { render :new }
+ service_result.on_success { render :storage_view_component }
+ end
+
# rubocop:disable Metrics/AbcSize
def create
service_result = Storages::Storages::CreateService.new(user: current_user).call(permitted_storage_params)
@@ -194,9 +209,9 @@ class Storages::Admin::StoragesController < ApplicationController
# Called by create and update above in order to check if the
# update parameters are correctly set.
- def permitted_storage_params
+ def permitted_storage_params(model_parameter_name = storage_provider_parameter_name)
params
- .require(storage_provider_parameter_name)
+ .require(model_parameter_name)
.permit('name', 'provider_type', 'host', 'oauth_client_id', 'oauth_client_secret', 'tenant_id', 'drive_id')
end
diff --git a/modules/storages/app/views/storages/admin/storages/new.html.erb b/modules/storages/app/views/storages/admin/storages/new.html.erb
index b575b763bc4..d8aad3ee0a9 100644
--- a/modules/storages/app/views/storages/admin/storages/new.html.erb
+++ b/modules/storages/app/views/storages/admin/storages/new.html.erb
@@ -1,14 +1,30 @@
<!-- Standard Ruby view, please see the controller for comments -->
<% html_title t(:label_administration), t("project_module_storages"), t('storages.label_new_storage') %>
<% local_assigns[:additional_breadcrumb] = t('storages.label_new_storage') %>
-<%= toolbar title: t("storages.label_new_storage") %>
-
-<%= labelled_tabular_form_for @storage, url: admin_settings_storages_path(@storage), as: :storages_storage do |f| -%>
- <%= render partial: 'new', locals: { f: f } %>
- <% if @storage.oauth_client %>
- <%= styled_button_tag t(:button_save), class: "-highlight -with-icon icon-checkmark" %>
- <% else %>
- <%= styled_button_tag t("storages.buttons.save_and_continue_setup"), class: "-highlight -with-icon icon-checkmark" %>
+
+<% if OpenProject::FeatureDecisions.storage_primer_design_active? %>
+ <%= render(Primer::OpenProject::PageHeader.new) do |header| %>
+ <% header.with_title(test_selector: 'storage-name-title') do %>
+ <%= t("storages.label_new_storage") %>
+ <% end %>
+
+ <% header.with_description do %>
+ <%= t("storages.instructions.new_storage") %>
+ <% end %>
+
+ <% end %>
+
+ <%= render(::Storages::Admin::SelectStorageProviderComponent.new(@storage)) %>
+<% else %>
+ <%= toolbar title: t("storages.label_new_storage") %>
+
+ <%= labelled_tabular_form_for @storage, url: admin_settings_storages_path(@storage), as: :storages_storage do |f| -%>
+ <%= render partial: 'new', locals: { f: f } %>
+ <% if @storage.oauth_client %>
+ <%= styled_button_tag t(:button_save), class: "-highlight -with-icon icon-checkmark" %>
+ <% else %>
+ <%= styled_button_tag t("storages.buttons.save_and_continue_setup"), class: "-highlight -with-icon icon-checkmark" %>
+ <% end %>
+ <%= link_to t(:button_cancel), admin_settings_storages_path, class: 'button -with-icon icon-close' %>
<% end %>
- <%= link_to t(:button_cancel), admin_settings_storages_path, class: 'button -with-icon icon-close' %>
<% end %>
diff --git a/modules/storages/app/views/storages/admin/storages/storage_view_component.html.erb b/modules/storages/app/views/storages/admin/storages/storage_view_component.html.erb
new file mode 100644
index 00000000000..468a2a0e2f1
--- /dev/null
+++ b/modules/storages/app/views/storages/admin/storages/storage_view_component.html.erb
@@ -0,0 +1,37 @@
+<%#-- 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.
+
+++#%>
+
+<% html_title t(:label_administration), t("project_module_storages"), t('storages.label_new_storage') %>
+<% local_assigns[:additional_breadcrumb] = t('storages.label_new_storage') %>
+
+<%=
+ render(OpTurbo::FrameComponent.new(id: :storages_storage, context: :select_storage_provider)) do
+ render(Storages::Admin::StorageViewComponent.new(@storage))
+ end
+%>
diff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.yml
index 6f335165cbf..666e7462454 100644
--- a/modules/storages/config/locales/en.yml
+++ b/modules/storages/config/locales/en.yml
@@ -116,6 +116,7 @@ en:
managed_project_folders_application_password: >
Copy this value from:
managed_project_folders_application_password_caption: "Enable automatic managed folders by copying this value from: %{provider_type_link}."
+ new_storage: "Read our file storage documentation for more information about this setup."
no_storage_set_up: "There are no file storages set up yet."
no_specific_folder: "By default, each user will start at their own home folder when they upload a file."
automatic_folder: "This will automatically create a root folder for this project and manage the access permissions for each project member."
diff --git a/modules/storages/config/routes.rb b/modules/storages/config/routes.rb
index 7d9c98d2978..ac2a2e71d66 100644
--- a/modules/storages/config/routes.rb
+++ b/modules/storages/config/routes.rb
@@ -36,6 +36,8 @@ OpenProject::Application.routes.draw do
resource :automatically_managed_project_folders, controller: '/storages/admin/automatically_managed_project_folders',
only: %i[new edit update]
+ post :select_provider, on: :collection
+
member do
get '/edit_host' => '/storages/admin/storages#edit_host'
delete '/replace_oauth_application' => '/storages/admin/storages#replace_oauth_application'