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
Refactor the step-by-step storage setup
Jan Sandbrinkbc6112e35bef
diff --git a/modules/storages/app/common/storages/peripherals/nextcloud_registry.rb b/modules/storages/app/common/storages/peripherals/nextcloud_registry.rbindex f378818170c..a831f1cf9c0 100644--- a/modules/storages/app/common/storages/peripherals/nextcloud_registry.rb+++ b/modules/storages/app/common/storages/peripherals/nextcloud_registry.rb@@ -57,6 +57,10 @@ module Storagesregister(:set_permissions, StorageInteraction::Nextcloud::SetPermissionsCommand)end+ namespace("components") do+ register(:setup_wizard, NextcloudStorageWizard)+ end+namespace("contracts") doregister(:storage, ::Storages::Storages::NextcloudContract)enddiff --git a/modules/storages/app/common/storages/peripherals/nextcloud_storage_wizard.rb b/modules/storages/app/common/storages/peripherals/nextcloud_storage_wizard.rbnew file mode 100644index 00000000000..92f598b4f4f--- /dev/null+++ b/modules/storages/app/common/storages/peripherals/nextcloud_storage_wizard.rb@@ -0,0 +1,62 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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+ module Peripherals+ class NextcloudStorageWizard < Wizard+ step :general_info, completed_if: ->(storage) { storage.host.present? && storage.name.present? }++ step :oauth_application,+ completed_if: ->(storage) { storage.oauth_application.present? },+ preparation: :prepare_oauth_application++ step :oauth_client,+ completed_if: ->(storage) { storage.oauth_client.present? },+ preparation: ->(storage) { storage.build_oauth_client }++ step :automatically_managed_project_folders,+ completed_if: ->(storage) { !storage.automatic_management_unspecified? },+ preparation: :prepare_storage_for_automatic_management_form++ private++ def prepare_oauth_application(storage)+ create_result = ::Storages::OAuthApplications::CreateService.new(storage:, user:).call+ storage.oauth_application = create_result.result if create_result.success?+ end++ def prepare_storage_for_automatic_management_form(storage)+ ::Storages::Storages::SetProviderFieldsAttributesService+ .new(user:, model: storage, contract_class: EmptyContract)+ .call+ end+ end+ end+enddiff --git a/modules/storages/app/common/storages/peripherals/one_drive_registry.rb b/modules/storages/app/common/storages/peripherals/one_drive_registry.rbindex fcc33aef1bd..4bc565b1ea0 100644--- a/modules/storages/app/common/storages/peripherals/one_drive_registry.rb+++ b/modules/storages/app/common/storages/peripherals/one_drive_registry.rb@@ -51,6 +51,10 @@ module Storagesregister(:set_permissions, StorageInteraction::OneDrive::SetPermissionsCommand)end+ namespace("components") do+ register(:setup_wizard, OneDriveStorageWizard)+ end+namespace("contracts") doregister(:storage, ::Storages::Storages::OneDriveContract)enddiff --git a/modules/storages/app/common/storages/peripherals/one_drive_storage_wizard.rb b/modules/storages/app/common/storages/peripherals/one_drive_storage_wizard.rbnew file mode 100644index 00000000000..72598709360--- /dev/null+++ b/modules/storages/app/common/storages/peripherals/one_drive_storage_wizard.rb@@ -0,0 +1,72 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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+ module Peripherals+ class OneDriveStorageWizard < Wizard+ step :general_info, completed_if: ->(storage) { storage.name.present? }++ step :access_management,+ completed_if: ->(storage) { !storage.automatic_management_unspecified? },+ preparation: :prepare_storage_for_access_management_form++ step :oauth_client,+ completed_if: ->(storage) { storage.oauth_client.present? },+ preparation: ->(storage) { storage.build_oauth_client }++ step :redirect_uri,+ completed_if: ->(storage) {+ # Working around the fact that there is nothing changed on the storage after showing+ # the redirect url. The redirect URL step only exists to show the oauth client's redirect+ # URL to the user right after the client was created.+ storage.oauth_client&.persisted? && storage.oauth_client.created_at < 10.seconds.ago+ }++ private++ def prepare_storage_for_access_management_form(storage)+ ::Storages::Storages::SetProviderFieldsAttributesService+ .new(user:, model: storage, contract_class: EmptyContract)+ .call+ end++ def prepare_oauth_application(storage)+ persist_service_result = ::Storages::OAuthApplications::CreateService.new(storage:, user:).call+ storage.oauth_application = persist_service_result.result if persist_service_result.success?+ end++ def prepare_storage_for_automatic_management_form(storage)+ ::Storages::Storages::SetProviderFieldsAttributesService+ .new(user:, model: storage, contract_class: EmptyContract)+ .call+ end+ end+ end+enddiff --git a/modules/storages/app/components/storages/admin/forms/access_management_form_component.html.erb b/modules/storages/app/components/storages/admin/forms/access_management_form_component.html.erbindex f5601c15b73..a0f91cb7eb4 100644--- a/modules/storages/app/components/storages/admin/forms/access_management_form_component.html.erb+++ b/modules/storages/app/components/storages/admin/forms/access_management_form_component.html.erb@@ -3,8 +3,9 @@render(Primer::Beta::Text.new(tag: :div, test_selector: 'storage-access-management-form')) doprimer_form_with(model:,- url: admin_settings_storage_access_management_path(storage),- method: form_method+ url: form_url,+ method: form_method,+ data: { turbo_frame: "page-content" }) do |form|flex_layout do |access_management_row|access_management_row.with_row(mb: 3) dodiff --git a/modules/storages/app/components/storages/admin/forms/access_management_form_component.rb b/modules/storages/app/components/storages/admin/forms/access_management_form_component.rbindex eabb2b3c079..009971e3aef 100644--- a/modules/storages/app/components/storages/admin/forms/access_management_form_component.rb+++ b/modules/storages/app/components/storages/admin/forms/access_management_form_component.rb@@ -35,8 +35,15 @@ module Storages::Admin::Formsalias_method :storage, :model+ options in_wizard: false+def self.wrapper_key = :access_management_section+ def form_url+ query = { continue_wizard: storage.id } if in_wizard+ admin_settings_storage_access_management_path(storage, query)+ end+privatedef form_methoddiff --git a/modules/storages/app/components/storages/admin/forms/automatically_managed_project_folders_form_component.rb b/modules/storages/app/components/storages/admin/forms/automatically_managed_project_folders_form_component.rbindex 4300911d8e8..5f8dd9e11f3 100644--- a/modules/storages/app/components/storages/admin/forms/automatically_managed_project_folders_form_component.rb+++ b/modules/storages/app/components/storages/admin/forms/automatically_managed_project_folders_form_component.rb@@ -35,6 +35,8 @@ module Storages::Admin::Formsalias_method :storage, :model+ options in_wizard: false+def self.wrapper_key = :automatically_managed_project_folders_sectiondef form_method@@ -42,7 +44,8 @@ module Storages::Admin::Formsenddef form_url- options[:form_url] || default_form_url+ query = { continue_wizard: storage.id } if in_wizard+ admin_settings_storage_automatically_managed_project_folders_path(storage, query)enddef submit_button_options@@ -82,9 +85,5 @@ module Storages::Admin::Formsdef new_record?storage.automatic_management_new_record?end-- def default_form_url- admin_settings_storage_automatically_managed_project_folders_path(storage)- endendenddiff --git a/modules/storages/app/components/storages/admin/forms/general_info_form_component.html.erb b/modules/storages/app/components/storages/admin/forms/general_info_form_component.html.erbindex 9b01d38fa0b..1fda21239d2 100644--- a/modules/storages/app/components/storages/admin/forms/general_info_form_component.html.erb+++ b/modules/storages/app/components/storages/admin/forms/general_info_form_component.html.erb@@ -6,6 +6,7 @@url: form_url,method: form_method,data: {+ "turbo-frame": "page-content",controller: "storages--automatically-managed-project-folders-form",'application-target': "dynamic",'storages--automatically-managed-project-folders-form-provider-type-value': storage.provider_type,diff --git a/modules/storages/app/components/storages/admin/forms/general_info_form_component.rb b/modules/storages/app/components/storages/admin/forms/general_info_form_component.rbindex aa0d72f39e8..7efdfa86cb3 100644--- a/modules/storages/app/components/storages/admin/forms/general_info_form_component.rb+++ b/modules/storages/app/components/storages/admin/forms/general_info_form_component.rb@@ -36,12 +36,20 @@ module Storages::Admin::Formsalias_method :storage, :modeloptions form_method: :post,- submit_button_disabled: false+ submit_button_disabled: false,+ in_wizard: falsedef self.wrapper_key = :storage_general_info_sectiondef form_url- options[:form_url] || default_form_url+ query = { continue_wizard: storage.id } if in_wizard++ case form_method+ when :get, :post+ admin_settings_storages_path(query)+ when :patch, :put+ admin_settings_storage_path(storage, query)+ endenddef submit_button_options@@ -60,15 +68,6 @@ module Storages::Admin::Formsprivate- def default_form_url- case form_method- when :get, :post- admin_settings_storages_path- when :patch, :put- admin_settings_storage_path(storage)- end- end-def cancel_button_pathoptions.fetch(:cancel_button_path) doif storage.persisted?diff --git a/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.html.erb b/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.html.erbindex 500628a42f3..9fd7cc5bbbe 100644--- a/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.html.erb+++ b/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.html.erb@@ -3,8 +3,9 @@render(Primer::Beta::Text.new(tag: :div, test_selector: 'storage-oauth-client-form')) doprimer_form_with(model: oauth_client,- url: admin_settings_storage_oauth_client_path(storage),- method: form_method+ url: form_url,+ method: form_method,+ data: data_attributes) do |form|flex_layout do |oauth_client_row|oauth_client_row.with_row(mb: 3) dodiff --git a/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.rb b/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.rbindex d2fda9355e9..9ea99d12b2f 100644--- a/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.rb+++ b/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.rb@@ -36,12 +36,19 @@ module Storages::Admin::Formsattr_reader :storagealias_method :oauth_client, :model+ options in_wizard: false++ def self.wrapper_key = :storage_oauth_client_section+def initialize(oauth_client:, storage:, **)super(oauth_client, **)@storage = storageend- def self.wrapper_key = :storage_oauth_client_section+ def form_url+ query = { continue_wizard: storage.id } if in_wizard+ admin_settings_storage_oauth_client_path(storage, query)+ enddef form_methodoptions[:form_method] || default_form_method@@ -75,5 +82,9 @@ module Storages::Admin::Formsdef default_form_methodfirst_time_configuration? ? :post : :patchend++ def data_attributes+ { turbo_frame: "page-content" }+ endendenddiff --git a/modules/storages/app/components/storages/admin/forms/redirect_uri_form_component.html.erb b/modules/storages/app/components/storages/admin/forms/redirect_uri_form_component.html.erbindex 9f78d94d16c..9888611054c 100644--- a/modules/storages/app/components/storages/admin/forms/redirect_uri_form_component.html.erb+++ b/modules/storages/app/components/storages/admin/forms/redirect_uri_form_component.html.erb@@ -3,7 +3,7 @@render(Primer::Beta::Text.new(tag: :div, test_selector: 'storage-oauth-client-form')) doprimer_form_with(model: oauth_client,- url: finish_setup_admin_settings_storage_oauth_client_path(storage),+ url: form_url,method: :post) do |form|flex_layout do |oauth_client_row|diff --git a/modules/storages/app/components/storages/admin/forms/redirect_uri_form_component.rb b/modules/storages/app/components/storages/admin/forms/redirect_uri_form_component.rbindex e8c0f8a94e9..4e2b83c4f43 100644--- a/modules/storages/app/components/storages/admin/forms/redirect_uri_form_component.rb+++ b/modules/storages/app/components/storages/admin/forms/redirect_uri_form_component.rb@@ -36,12 +36,19 @@ module Storages::Admin::Formsattr_reader :storagealias_method :oauth_client, :model+ options in_wizard: false++ def self.wrapper_key = :storage_redirect_uri_section+def initialize(oauth_client:, storage:, **)super(oauth_client, **)@storage = storageend- def self.wrapper_key = :storage_redirect_uri_section+ def form_url+ query = { continue_wizard: storage.id } if in_wizard+ finish_setup_admin_settings_storage_oauth_client_path(storage, query)+ enddef cancel_button_pathstorage.persisted? ? edit_admin_settings_storage_path(storage) : admin_settings_storages_pathdiff --git a/modules/storages/app/components/storages/admin/oauth_application_info_copy_component.rb b/modules/storages/app/components/storages/admin/oauth_application_info_copy_component.rbindex 458b2aa6645..d2ae8e8e3b0 100644--- a/modules/storages/app/components/storages/admin/oauth_application_info_copy_component.rb+++ b/modules/storages/app/components/storages/admin/oauth_application_info_copy_component.rb@@ -36,6 +36,8 @@ module Storages::Adminattr_reader :storagealias_method :oauth_application, :model+ options in_wizard: false+def initialize(oauth_application:, storage:, **)super(oauth_application, **)@storage = storage@@ -56,14 +58,16 @@ module Storages::Admin{scheme: :primary,tag: :a,- href: submit_button_path- }.merge(options.fetch(:submit_button_options, {}))+ href: submit_button_path,+ data: { turbo_stream: true, turbo_frame: "page-content" }+ }endprivatedef submit_button_path- options[:submit_button_path] || show_oauth_application_admin_settings_storage_path(storage)+ query = { continue_wizard: storage.id } if in_wizard+ show_oauth_application_admin_settings_storage_path(storage, query)endendenddiff --git a/modules/storages/app/components/storages/admin/redirect_uri_component.html.erb b/modules/storages/app/components/storages/admin/redirect_uri_component.html.erbindex 5b40e06c866..0da51bae0e2 100644--- a/modules/storages/app/components/storages/admin/redirect_uri_component.html.erb+++ b/modules/storages/app/components/storages/admin/redirect_uri_component.html.erb@@ -12,7 +12,7 @@grid.with_area(:description, tag: :div, color: :subtle, test_selector: 'storage-redirect-uri-description') doconcat(render(Primer::Beta::Text.new) { provider_redirect_uri_description })- if storage.oauth_client.present?+ if storage.oauth_client&.persisted?concat(render(Primer::Beta::ClipboardCopy.new('aria-label': I18n.t('storages.instructions.one_drive.copy_redirect_uri'),value: storage.oauth_client.redirect_uri)))enddiff --git a/modules/storages/app/components/storages/admin/storage_view_component.html.erb b/modules/storages/app/components/storages/admin/storage_view_component.html.erbindex c2cdb656367..0423a7cb750 100644--- a/modules/storages/app/components/storages/admin/storage_view_component.html.erb+++ b/modules/storages/app/components/storages/admin/storage_view_component.html.erb@@ -5,8 +5,8 @@endcomponent.with_row(scheme: :default) do- if storage.new_record?- render(Storages::Admin::Forms::GeneralInfoFormComponent.new(storage))+ if wizard_step == "general_info"+ render(Storages::Admin::Forms::GeneralInfoFormComponent.new(storage, in_wizard: true))elserender(Storages::Admin::GeneralInfoComponent.new(storage))end@@ -16,21 +16,25 @@component.with_row(scheme: :neutral, color: :muted) dogrid_layout('op-storage-view--row', tag: :div, align_items: :center) do |grid|grid.with_area(:item, tag: :div, mr: 3) do- render(Primer::Beta::Text.new(font_weight: :semibold, mr: 1)) { I18n.t('storages.file_storage_view.oauth_applications') }+ render(Primer::Beta::Text.new(font_weight: :semibold, mr: 1)) { I18n.t('storages.file_storage_view.oauth_configuration') }endendendcomponent.with_row(scheme: :default) do- if storage.new_record? || openproject_oauth_application_section_closed?- render(Storages::Admin::OAuthApplicationInfoComponent.new(oauth_application:, storage:))+ if wizard_step == "oauth_application"+ render(Storages::Admin::OAuthApplicationInfoCopyComponent.new(oauth_application:, storage:, in_wizard: true))else- render(Storages::Admin::OAuthApplicationInfoCopyComponent.new(oauth_application:, storage:))+ render(Storages::Admin::OAuthApplicationInfoComponent.new(oauth_application:, storage:))endendcomponent.with_row(scheme: :default) do- render(Storages::Admin::OAuthClientInfoComponent.new(oauth_client: storage.oauth_client, storage:))+ if wizard_step == "oauth_client"+ render(Storages::Admin::Forms::OAuthClientFormComponent.new(oauth_client: storage.oauth_client, storage:, in_wizard: true))+ else+ render(Storages::Admin::OAuthClientInfoComponent.new(oauth_client: storage.oauth_client, storage:))+ endendcomponent.with_row(scheme: :neutral, color: :muted) do@@ -42,10 +46,10 @@endcomponent.with_row(scheme: :default) do- if automatically_managed_project_folders_section_closed?- render(Storages::Admin::AutomaticallyManagedProjectFoldersInfoComponent.new(storage))+ if wizard_step == "automatically_managed_project_folders"+ render(Storages::Admin::Forms::AutomaticallyManagedProjectFoldersFormComponent.new(storage, in_wizard: true))else- render(Storages::Admin::Forms::AutomaticallyManagedProjectFoldersFormComponent.new(storage))+ render(Storages::Admin::AutomaticallyManagedProjectFoldersInfoComponent.new(storage))endendend@@ -60,23 +64,35 @@endcomponent.with_row(scheme: :default) do- render(Storages::Admin::AccessManagementComponent.new(storage))+ if wizard_step == "access_management"+ render(Storages::Admin::Forms::AccessManagementFormComponent.new(storage, in_wizard: true))+ else+ render(Storages::Admin::AccessManagementComponent.new(storage))+ endendcomponent.with_row(scheme: :neutral, color: :muted) dogrid_layout('op-storage-view--row', tag: :div, align_items: :center) do |grid|grid.with_area(:item, tag: :div, mr: 3) do- render(Primer::Beta::Text.new(font_weight: :semibold, mr: 1)) { I18n.t('storages.file_storage_view.oauth_applications') }+ render(Primer::Beta::Text.new(font_weight: :semibold, mr: 1)) { I18n.t('storages.file_storage_view.oauth_configuration') }endendendcomponent.with_row(scheme: :default) do- render(Storages::Admin::OAuthClientInfoComponent.new(oauth_client: storage.oauth_client, storage:))+ if wizard_step == "oauth_client"+ render(Storages::Admin::Forms::OAuthClientFormComponent.new(oauth_client: storage.oauth_client, storage:, in_wizard: true))+ else+ render(Storages::Admin::OAuthClientInfoComponent.new(oauth_client: storage.oauth_client, storage:))+ endendcomponent.with_row(scheme: :default) do- render(Storages::Admin::RedirectUriComponent.new(oauth_client: storage.oauth_client, storage:))+ if wizard_step == "redirect_uri"+ render(Storages::Admin::Forms::RedirectUriFormComponent.new(oauth_client: storage.oauth_client, storage:, in_wizard: true))+ else+ render(Storages::Admin::RedirectUriComponent.new(oauth_client: storage.oauth_client, storage:))+ endendendenddiff --git a/modules/storages/app/components/storages/admin/storage_view_component.rb b/modules/storages/app/components/storages/admin/storage_view_component.rbindex 840c11945d1..ac891fab8d7 100644--- a/modules/storages/app/components/storages/admin/storage_view_component.rb+++ b/modules/storages/app/components/storages/admin/storage_view_component.rb@@ -33,21 +33,10 @@ module Storages::Admininclude OpPrimer::ComponentHelpersinclude StorageViewInformation- options openproject_oauth_application_section_open: false,- automatically_managed_project_folders_section_open: false+ options wizard_step: nilalias_method :storage, :model- alias_method :openproject_oauth_application_section_open?, :openproject_oauth_application_section_open- alias_method :automatically_managed_project_folders_section_open?, :automatically_managed_project_folders_section_opendelegate :oauth_application, to: :model-- def openproject_oauth_application_section_closed?- !openproject_oauth_application_section_open?- end-- def automatically_managed_project_folders_section_closed?- !automatically_managed_project_folders_section_open?- endendenddiff --git a/modules/storages/app/components/storages/admin/storage_view_information.rb b/modules/storages/app/components/storages/admin/storage_view_information.rbindex a43f41d9f61..9dab58231e8 100644--- a/modules/storages/app/components/storages/admin/storage_view_information.rb+++ b/modules/storages/app/components/storages/admin/storage_view_information.rb@@ -95,7 +95,7 @@ module Storages::Adminenddef provider_redirect_uri_description- if storage.oauth_client+ if storage.oauth_client&.persisted?"#{I18n.t('storages.label_uri')}: #{storage.oauth_client.redirect_uri}"elseI18n.t("storages.configuration_checks.redirect_uri_incomplete.#{storage}")diff --git a/modules/storages/app/controllers/storages/admin/access_management_controller.rb b/modules/storages/app/controllers/storages/admin/access_management_controller.rbindex d30d09024b1..66f4c0bcff4 100644--- a/modules/storages/app/controllers/storages/admin/access_management_controller.rb+++ b/modules/storages/app/controllers/storages/admin/access_management_controller.rb@@ -58,17 +58,13 @@ class Storages::Admin::AccessManagementController < ApplicationControllerservice_result = call_update_serviceservice_result.on_success do- update_via_turbo_stream(component: Storages::Admin::AccessManagementComponent.new(@storage))- update_via_turbo_stream(component: Storages::Admin::Forms::OAuthClientFormComponent.new(- oauth_client: @storage.build_oauth_client, storage: @storage- ))+ redirect_to(new_admin_settings_storage_path(continue_wizard: @storage.id), status: :see_other)endservice_result.on_failure do- update_via_turbo_stream(component: Storages::Admin::Forms::AccessManagementFormComponent.new(@storage))+ update_via_turbo_stream(component: Storages::Admin::Forms::AccessManagementFormComponent.new(@storage, in_wizard: true))+ respond_with_turbo_streamsend-- respond_with_turbo_streamsenddef updatediff --git a/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rb b/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rbindex e32738fb075..aa6691d0115 100644--- a/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rb+++ b/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rb@@ -64,26 +64,14 @@ class Storages::Admin::OAuthClientsController < ApplicationControllerservice_result.on_failure doupdate_via_turbo_stream(component: Storages::Admin::Forms::OAuthClientFormComponent.new(oauth_client: @oauth_client,- storage: @storage))+ storage: @storage,+ in_wizard: true))+ respond_with_turbo_streamsendservice_result.on_success do- if @storage.provider_type_nextcloud?- prepare_storage_for_automatic_management_form- end-- update_via_turbo_stream(component: Storages::Admin::OAuthClientInfoComponent.new(oauth_client: @oauth_client,- storage: @storage))- update_via_turbo_stream(component: Storages::Admin::Forms::RedirectUriFormComponent.new(- oauth_client: @oauth_client, storage: @storage, is_complete: false- ))-- if @storage.provider_type_nextcloud? && @storage.automatic_management_new_record?- update_via_turbo_stream(component: Storages::Admin::Forms::AutomaticallyManagedProjectFoldersFormComponent.new(@storage))- end+ redirect_to(new_admin_settings_storage_path(continue_wizard: @storage.id), status: :see_other)end-- respond_with_turbo_streamsenddef updatediff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rbindex 4891d9b8119..1b6718ac7c7 100644--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb@@ -47,8 +47,8 @@ class Storages::Admin::StoragesController < ApplicationControllerbefore_action :find_model_object,only: %i[show_oauth_application destroy edit edit_host confirm_destroy updatechange_health_notifications_enabled replace_oauth_application]- before_action :ensure_valid_provider_type_selected, only: %i[select_provider]- before_action :require_ee_token_for_one_drive, only: %i[select_provider]+ before_action :ensure_valid_wizard_parameters, only: [:new]+ before_action :require_ee_token_for_one_drive, only: [:new]menu_item :external_file_storages@@ -63,87 +63,46 @@ class Storages::Admin::StoragesController < ApplicationController# Used by: The index page above, when the user presses the (+) button.# Called by: Global app/config/routes.rb to serve Web pagedef new- # Set default parameters using a "service".- # See also: storages/services/storages/storages/set_attributes_services.rb- # That service inherits from ::BaseServices::SetAttributes- @storage = ::Storages::Storages::SetAttributesService- .new(user: current_user,- model: Storages::Storage.new,- contract_class: EmptyContract)- .call- .result-- update_via_turbo_stream(component: Storages::Admin::Forms::GeneralInfoFormComponent.new(@storage))+ if @storage.blank?+ # Set default parameters using a "service".+ # See also: storages/services/storages/storages/set_attributes_services.rb+ # That service inherits from ::BaseServices::SetAttributes+ @storage = ::Storages::Storages::SetAttributesService+ .new(user: current_user,+ model: Storages::Storage.new(provider_type: @provider_type),+ contract_class: EmptyContract)+ .call+ .result+ end- respond_with_turbo_streams(&:html)+ @target_step = storage_wizard(@storage).prepare_next_step.to_senddef upsale; end- def select_provider- @object = Storages::Storage.new(provider_type: @provider_type)- service_result = ::Storages::Storages::SetAttributesService- .new(user: current_user,- model: @object,- contract_class: EmptyContract)- .call- @storage = service_result.result-- respond_to do |format|- format.html { render :new }- end- end-- def create # rubocop:disable Metrics/AbcSize+ def createservice_result = Storages::Storages::CreateService- .new(user: current_user)+ .new(user: current_user, create_oauth_app: false).call(permitted_storage_params)@storage = service_result.result- @oauth_application = oauth_application(service_result)service_result.on_failure doupdate_via_turbo_stream(component: Storages::Admin::Forms::GeneralInfoFormComponent.new(@storage))+ respond_with_turbo_streamsendservice_result.on_success do- if @storage.provider_type_one_drive?- prepare_storage_for_access_management_form- update_via_turbo_stream(component: Storages::Admin::Forms::AccessManagementFormComponent.new(@storage))- end-- update_via_turbo_stream(component: Storages::Admin::GeneralInfoComponent.new(@storage))-- if @storage.provider_type_nextcloud?- update_via_turbo_stream(- component: Storages::Admin::OAuthApplicationInfoCopyComponent.new(- oauth_application: @oauth_application,- storage: @storage,- submit_button_options: { data: { turbo_stream: true } }- )- )- end+ redirect_to_wizard(@storage)end-- respond_with_turbo_streamsenddef show_oauth_application- @oauth_application = @storage.oauth_application-- update_via_turbo_stream(- component: Storages::Admin::OAuthApplicationInfoComponent.new(oauth_application: @oauth_application,- storage: @storage)- )-- if @storage.oauth_client.blank?- update_via_turbo_stream(- component: Storages::Admin::Forms::OAuthClientFormComponent.new(oauth_client: @storage.build_oauth_client,- storage: @storage)- )+ if params[:continue_wizard]+ redirect_to_wizard(@storage)+ else+ redirect_to(edit_admin_settings_storage_path(@storage), status: :see_other)end-- respond_with_turbo_streamsenddef edit; end@@ -160,20 +119,25 @@ class Storages::Admin::StoragesController < ApplicationControllerrespond_with_turbo_streamsend- def update+ def update # rubocop:disable Metrics/AbcSizeservice_result = ::Storages::Storages::UpdateService.new(user: current_user, model: @storage).call(permitted_storage_params)@storage = service_result.resultif service_result.success?- respond_to { |format| format.turbo_stream }+ if params[:continue_wizard]+ redirect_to_wizard(@storage)+ else+ redirect_to(edit_admin_settings_storage_path(@storage), status: :see_other)+ endelseupdate_via_turbo_stream(component: Storages::Admin::Forms::GeneralInfoFormComponent.new(@storage,form_method: :patch,- cancel_button_path: edit_admin_settings_storage_path(@storage)+ cancel_button_path: edit_admin_settings_storage_path(@storage),+ in_wizard: params[:continue_wizard].present?))@@ -229,10 +193,7 @@ class Storages::Admin::StoragesController < ApplicationControllerupdate_via_turbo_stream(component: Storages::Admin::OAuthApplicationInfoCopyComponent.new(oauth_application: @oauth_application,- storage: @storage,- submit_button_options: {- data: { turbo_stream: true }- }+ storage: @storage))@@ -260,7 +221,12 @@ class Storages::Admin::StoragesController < ApplicationController.resultend- def ensure_valid_provider_type_selected+ def ensure_valid_wizard_parameters+ if params[:continue_wizard].present?+ @storage = ::Storages::Storage.find(params[:continue_wizard])+ return+ end+short_provider_type = params[:provider]if short_provider_type.blank? || (@provider_type = ::Storages::Storage::PROVIDER_TYPE_SHORT_NAMES[short_provider_type]).blank?flash[:error] = I18n.t("storages.error_invalid_provider_type")@@ -268,10 +234,6 @@ class Storages::Admin::StoragesController < ApplicationControllerendend- def oauth_application(service_result)- service_result.dependent_results&.first&.result- end-# Called by create and update above in order to check if the# update parameters are correctly set.def permitted_storage_params(model_parameter_name = storage_provider_parameter_name)@@ -303,4 +265,13 @@ class Storages::Admin::StoragesController < ApplicationControllerredirect_to action: :upsaleendend++ def storage_wizard(storage)+ ::Storages::Peripherals::Registry.resolve("#{storage}.components.setup_wizard")+ .new(model: storage, user: current_user)+ end++ def redirect_to_wizard(storage)+ redirect_to(new_admin_settings_storage_path(continue_wizard: storage.id), status: :see_other)+ endenddiff --git a/modules/storages/app/helpers/storages/open_storage_links.rb b/modules/storages/app/helpers/storages/open_storage_links.rbindex a32675f58f5..12eb78bbdbd 100644--- a/modules/storages/app/helpers/storages/open_storage_links.rb+++ b/modules/storages/app/helpers/storages/open_storage_links.rb@@ -57,7 +57,7 @@ module Storageswhen Storage::PROVIDER_TYPE_NEXTCLOUDtruewhen Storage::PROVIDER_TYPE_ONE_DRIVE- storage.oauth_client.present?+ storage.oauth_client&.persisted?elsefalseenddiff --git a/modules/storages/app/services/storages/storages/create_service.rb b/modules/storages/app/services/storages/storages/create_service.rbindex b41502e850e..68337086e64 100644--- a/modules/storages/app/services/storages/storages/create_service.rb+++ b/modules/storages/app/services/storages/storages/create_service.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -29,15 +31,21 @@# The logic for creating storage was extracted from the controller and put into# a service: https://dev.to/joker666/ruby-on-rails-pattern-service-objects-b19# Purpose: create and persist a Storages::Storage record-# Used by: Storages::Admin::StoragesController#create, could also be used by the-# API in the future.+# Used by: Storages::Admin::StoragesController#create, API::V3::Storages::StoragesAPI# The comments here are also valid for the other *_service.rb filesmodule Storages::Storagesclass CreateService < ::BaseServices::Create+ def initialize(*, create_oauth_app: true, **)+ super(*, **)++ @create_oauth_app = create_oauth_app+ end+protecteddef after_perform(service_call)super+ return service_call unless create_oauth_app?storage = service_call.result# Automatically create an OAuthApplication object for the Nextcloud storage@@ -59,5 +67,9 @@ module Storages::Storagesinstance_klass = params[:provider_type].constantizeinstance_klass.newend++ def create_oauth_app?+ @create_oauth_app+ endendenddiff --git a/modules/storages/app/services/storages/storages/update_service.rb b/modules/storages/app/services/storages/storages/update_service.rbindex 7f50b94f2dd..0f4d7d74318 100644--- a/modules/storages/app/services/storages/storages/update_service.rb+++ b/modules/storages/app/services/storages/storages/update_service.rb@@ -37,16 +37,16 @@ module Storages::Storagessuperstorage = service_call.result- if storage.provider_type_nextcloud?- application = storage.oauth_application- persist_service_result = ::OAuth::Applications::UpdateService- .new(model: application, user:)- .call(- name: "#{storage.name} (#{I18n.t("storages.provider_types.#{storage}.name")})",- redirect_uri: File.join(storage.host, "index.php/apps/integration_openproject/oauth-redirect")- )- service_call.add_dependent!(persist_service_result)- end+ return service_call unless storage.provider_type_nextcloud?+ return service_call unless storage.oauth_application++ persist_service_result = ::OAuth::Applications::UpdateService+ .new(model: storage.oauth_application, user:)+ .call(+ name: "#{storage.name} (#{I18n.t("storages.provider_types.#{storage}.name")})",+ redirect_uri: File.join(storage.host, "index.php/apps/integration_openproject/oauth-redirect")+ )+ service_call.add_dependent!(persist_service_result)service_callenddiff --git a/modules/storages/app/services/storages/wizard.rb b/modules/storages/app/services/storages/wizard.rbnew file mode 100644index 00000000000..344664966bb--- /dev/null+++ b/modules/storages/app/services/storages/wizard.rb@@ -0,0 +1,106 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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+ class Wizard+ StepDefinition = Data.define(:name, :if, :completed_if, :preparation) do+ def use_on?(wizard)+ call_with_model(self.if, wizard)+ end++ def completed_on?(wizard)+ call_with_model(completed_if, wizard)+ end++ def prepare_on(wizard)+ call_with_model(preparation, wizard)+ end++ private++ def call_with_model(sym_or_callable, wizard)+ if sym_or_callable.is_a? Symbol+ wizard.send(sym_or_callable, wizard.model)+ else+ sym_or_callable.call(wizard.model)+ end+ end+ end++ class << self+ def steps_by_name+ @steps_by_name ||= {}+ end++ def steps+ steps_by_name.values+ end++ def step(name, completed_if:, if: ->(_) { true }, preparation: ->(_) {})+ name = name.to_sym+ steps_by_name[name] = StepDefinition.new(name:, if:, completed_if:, preparation:)+ end+ end++ attr_reader :model, :user++ def initialize(model:, user: nil)+ @model = model+ @user = user+ end++ def prepare_next_step+ next_step = pending_steps.first+ return nil if next_step.nil?++ steps_by_name.fetch(next_step).prepare_on(self)++ next_step+ end++ def steps+ self.class.steps.select { |s| s.use_on?(self) }.map(&:name)+ end++ def completed_steps+ steps.select { |name| steps_by_name.fetch(name).completed_on?(self) }+ end++ def pending_steps+ steps.reject { |name| steps_by_name.fetch(name).completed_on?(self) }+ end++ private++ def steps_by_name+ self.class.steps_by_name+ end+ end+enddiff --git a/modules/storages/app/views/storages/admin/automatically_managed_project_folders/edit.html.erb b/modules/storages/app/views/storages/admin/automatically_managed_project_folders/edit.html.erbindex b846441c745..533b63de450 100644--- a/modules/storages/app/views/storages/admin/automatically_managed_project_folders/edit.html.erb+++ b/modules/storages/app/views/storages/admin/automatically_managed_project_folders/edit.html.erb@@ -29,4 +29,4 @@ See COPYRIGHT and LICENSE files for more details.<% html_title t(:label_administration), t("project_module_storages"), @storage.name, t("storages.page_titles.managed_project_folders.title") %>-<%= render(Storages::Admin::StorageViewComponent.new(@storage, automatically_managed_project_folders_section_open: true)) %>+<%= render(Storages::Admin::StorageViewComponent.new(@storage, wizard_step: "automatically_managed_project_folders")) %>diff --git a/modules/storages/app/views/storages/admin/storages/edit.html.erb b/modules/storages/app/views/storages/admin/storages/edit.html.erbindex 1fa4b93a9c4..4c349bb1a60 100644--- a/modules/storages/app/views/storages/admin/storages/edit.html.erb+++ b/modules/storages/app/views/storages/admin/storages/edit.html.erb@@ -29,17 +29,20 @@ See COPYRIGHT and LICENSE files for more details.<% html_title t(:label_administration), t(:project_module_storages), t(:label_edit_x, x: @storage.name) %>-<%= render(Storages::Admin::EditFormHeaderComponent.new(- storage: @storage,- selected: :edit- ))-%>--<%= render(Primer::Alpha::Layout.new(stacking_breakpoint: :lg)) do |component| %>- <% component.with_main do %>- <%= render(::Storages::Admin::StorageViewComponent.new(@storage)) %>- <% end %>- <% component.with_sidebar(col_placement: :end, row_placement: :end) do %>- <%= render(::Storages::Admin::SidePanelComponent.new(storage: @storage)) %>++<%= content_tag("turbo-frame", id: "page-content") do %>+ <%= render(Storages::Admin::EditFormHeaderComponent.new(+ storage: @storage,+ selected: :edit+ ))+ %>++ <%= render(Primer::Alpha::Layout.new(stacking_breakpoint: :lg)) do |component| %>+ <% component.with_main do %>+ <%= render(::Storages::Admin::StorageViewComponent.new(@storage)) %>+ <% end %>+ <% component.with_sidebar(col_placement: :end, row_placement: :end) do %>+ <%= render(::Storages::Admin::SidePanelComponent.new(storage: @storage)) %>+ <% end %><% end %><% end %>diff --git a/modules/storages/app/views/storages/admin/storages/index.html.erb b/modules/storages/app/views/storages/admin/storages/index.html.erbindex 479409a1f35..f982951ec69 100644--- a/modules/storages/app/views/storages/admin/storages/index.html.erb+++ b/modules/storages/app/views/storages/admin/storages/index.html.erb@@ -32,7 +32,7 @@ end %>menu.with_item(label: I18n.t("storages.provider_types.#{short_provider_type}.name"),- href: url_helpers.select_provider_admin_settings_storages_path(provider: short_provider_type)+ href: url_helpers.new_admin_settings_storage_path(provider: short_provider_type)) do |item|item.with_trailing_visual_icon(icon: "op-enterprise-addons",diff --git a/modules/storages/app/views/storages/admin/storages/new.html.erb b/modules/storages/app/views/storages/admin/storages/new.html.erbindex 487a108c198..0845b7d2c2d 100644--- a/modules/storages/app/views/storages/admin/storages/new.html.erb+++ b/modules/storages/app/views/storages/admin/storages/new.html.erb@@ -25,4 +25,6 @@<% end %><% end %>-<%= render(Storages::Admin::StorageViewComponent.new(@storage)) %>+<%= content_tag("turbo-frame", id: "page-content") do %>+ <%= render(Storages::Admin::StorageViewComponent.new(@storage, wizard_step: @target_step)) %>+<% end %>diff --git a/modules/storages/app/views/storages/admin/storages/update.turbo_stream.erb b/modules/storages/app/views/storages/admin/storages/update.turbo_stream.erbdeleted file mode 100644index 66c5f17c4d6..00000000000--- a/modules/storages/app/views/storages/admin/storages/update.turbo_stream.erb+++ /dev/null@@ -1,25 +0,0 @@-<%- label_storage_provider_part = render(Primer::Beta::Text.new(tag: :span, font_weight: :light, color: :muted)) do- "(#{I18n.t("storages.provider_types.#{@storage}.name")})"- end- label_storage_name_with_provider_label = "#{@storage.name} #{label_storage_provider_part}".html_safe-%>--<%= turbo_stream.update dom_id(@storage, :edit_storage_header) do %>- <%= label_storage_name_with_provider_label %>-<% end %>--<%= turbo_stream.update :full_breadcrumbs do %>- <%- breadcrumb_paths(- link_to(t(:label_administration), admin_index_path),- default_breadcrumb,- @storage.name- )- %>- <%= full_breadcrumbs %>-<% end %>--<%= turbo_stream.update ::Storages::Admin::GeneralInfoComponent.wrapper_key do %>- <%= render(::Storages::Admin::GeneralInfoComponent.new(@storage)) %>-<% end %>diff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.ymlindex 81c6f90af78..ac149773170 100644--- a/modules/storages/config/locales/en.yml+++ b/modules/storages/config/locales/en.yml@@ -204,7 +204,7 @@ en:automatically_managed_folders: Automatically managed foldersgeneral_information: General informationnextcloud_oauth: Nextcloud OAuth- oauth_applications: OAuth applications+ oauth_configuration: OAuth configurationone_drive_oauth: Azure OAuthopenproject_oauth: OpenProject OAuthproject_folders: Project foldersdiff --git a/modules/storages/config/routes.rb b/modules/storages/config/routes.rbindex bbc6a37a5ef..fe346ef8127 100644--- a/modules/storages/config/routes.rb+++ b/modules/storages/config/routes.rb@@ -59,8 +59,6 @@ Rails.application.routes.draw dopost :validate_connection, on: :memberend- get :select_provider, on: :collection-member doget :show_oauth_applicationget :edit_hostdiff --git a/modules/storages/spec/common/storages/peripherals/nextcloud_storage_wizard_spec.rb b/modules/storages/spec/common/storages/peripherals/nextcloud_storage_wizard_spec.rbnew file mode 100644index 00000000000..830dea365ff--- /dev/null+++ b/modules/storages/spec/common/storages/peripherals/nextcloud_storage_wizard_spec.rb@@ -0,0 +1,134 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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 "spec_helper"++RSpec.describe Storages::Peripherals::NextcloudStorageWizard do+ subject(:wizard) { described_class.new(model:, user:) }++ let(:model) { Storages::NextcloudStorage.new }+ let(:user) { create(:admin) }++ before do+ Storages::Storages::SetAttributesService.new(user:, model:, contract_class: EmptyContract).call+ end++ it "has no completed steps" do+ expect(wizard.completed_steps).to be_empty+ end++ it "has all steps pending in correct order" do+ expect(wizard.pending_steps).to eq(%i[general_info+ oauth_application+ oauth_client+ automatically_managed_project_folders])+ end++ context "when name and host were set" do+ before do+ model.name = "Karl"+ model.host = "https://nextcloud.local/"+ model.save!+ end++ it "has general_info step completed" do+ expect(wizard.completed_steps).to eq(%i[general_info])+ end++ it "has no oauth_application yet" do+ expect(model.oauth_application).to be_nil+ end++ context "and the next step was prepared" do+ before do+ wizard.prepare_next_step+ end++ it "automatically finished the oauth_application step" do+ expect(wizard.completed_steps).to eq(%i[general_info+ oauth_application])+ end++ it "now has an oauth_application" do+ expect(model.oauth_application).to be_present+ end++ it "has no oauth_client yet" do+ expect(model.oauth_client).to be_nil+ end++ context "and the next step was prepared" do+ before do+ wizard.prepare_next_step+ end++ it "finishes the oauth_client step" do+ expect(wizard.completed_steps).to eq(%i[general_info+ oauth_application+ oauth_client])+ end++ it "now has an unsaved oauth_client" do+ expect(model.oauth_client).to be_present+ expect(model.oauth_client).not_to be_persisted+ end++ it "still didn't specify how to manage folders" do+ expect(model).to be_automatic_management_unspecified+ end++ context "and after preparing the next step" do+ before do+ wizard.prepare_next_step+ end++ it "enabled automatic storage management, but didn't persist it" do+ expect(model).to be_automatic_management_enabled++ before, after = model.changes["provider_fields"]+ expect(before.keys).not_to include("automatically_managed")+ expect(after.keys).to include("automatically_managed")+ end++ it "has no pending steps" do+ expect(wizard.pending_steps).to be_empty+ end++ it "has all steps completed" do+ expect(wizard.completed_steps).to eq(%i[general_info+ oauth_application+ oauth_client+ automatically_managed_project_folders])+ end+ end+ end+ end+ end+enddiff --git a/modules/storages/spec/common/storages/peripherals/one_drive_storage_wizard_spec.rb b/modules/storages/spec/common/storages/peripherals/one_drive_storage_wizard_spec.rbnew file mode 100644index 00000000000..5ae76703ed1--- /dev/null+++ b/modules/storages/spec/common/storages/peripherals/one_drive_storage_wizard_spec.rb@@ -0,0 +1,128 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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 "spec_helper"++RSpec.describe Storages::Peripherals::OneDriveStorageWizard do+ subject(:wizard) { described_class.new(model:, user:) }++ let(:model) { Storages::OneDriveStorage.new }+ let(:user) { create(:admin) }++ before do+ Storages::Storages::SetAttributesService.new(user:, model:, contract_class: EmptyContract).call+ end++ it "has no completed steps" do+ expect(wizard.completed_steps).to be_empty+ end++ it "has all steps pending in correct order" do+ expect(wizard.pending_steps).to eq(%i[general_info+ access_management+ oauth_client+ redirect_uri])+ end++ context "when name was set" do+ before do+ model.name = "Karl"+ model.save!+ end++ it "has general_info step completed" do+ expect(wizard.completed_steps).to eq(%i[general_info])+ end++ it "still didn't specify how to manage folders" do+ expect(model).to be_automatic_management_unspecified+ end++ context "and the next step was prepared" do+ before do+ wizard.prepare_next_step+ end++ it "automatically finished the access_management step" do+ expect(wizard.completed_steps).to eq(%i[general_info+ access_management])+ end++ it "enabled automatic storage management, but didn't persist it" do+ expect(model).to be_automatic_management_enabled++ before, after = model.changes["provider_fields"]+ expect(before.keys).not_to include("automatically_managed")+ expect(after.keys).to include("automatically_managed")+ end++ it "has no oauth_client yet" do+ expect(model.oauth_client).to be_nil+ end++ context "and the next step was prepared" do+ before do+ wizard.prepare_next_step+ end++ it "finishes the oauth_client step" do+ expect(wizard.completed_steps).to eq(%i[general_info+ access_management+ oauth_client])+ end++ it "now has an unsaved oauth_client" do+ expect(model.oauth_client).to be_present+ expect(model.oauth_client).not_to be_persisted+ end++ context "when the client was saved" do+ before do+ model.oauth_client.assign_attributes(client_id: "Foo", client_secret: "Bar")+ model.oauth_client.save!+ end++ it "did not finish the final step immediately" do+ expect(wizard.pending_steps).to eq(%i[redirect_uri])+ end++ it "after some time, the final step is completed" do+ Timecop.travel(15.seconds.from_now) do+ expect(wizard.completed_steps).to eq(%i[general_info+ access_management+ oauth_client+ redirect_uri])+ end+ end+ end+ end+ end+ end+enddiff --git a/modules/storages/spec/features/storages/admin/create_storage_spec.rb b/modules/storages/spec/features/storages/admin/create_storage_spec.rbindex cbea8ca87e4..fbf5450c971 100644--- a/modules/storages/spec/features/storages/admin/create_storage_spec.rb+++ b/modules/storages/spec/features/storages/admin/create_storage_spec.rb@@ -56,7 +56,7 @@ RSpec.describe "Admin Create a new file storage",within_test_selector("storages-select-provider-action-menu") { click_on("Nextcloud") }end- expect(page).to have_current_path(select_provider_admin_settings_storages_path(provider: "nextcloud"))+ expect(page).to have_current_path(new_admin_settings_storage_path(provider: "nextcloud"))aggregate_failures "Select provider view" do# Page Header@@ -219,7 +219,7 @@ RSpec.describe "Admin Create a new file storage",within_test_selector("storages-select-provider-action-menu") { click_on("OneDrive/SharePoint") }end- expect(page).to have_current_path(select_provider_admin_settings_storages_path(provider: "one_drive"))+ expect(page).to have_current_path(new_admin_settings_storage_path(provider: "one_drive"))aggregate_failures "Select provider view" do# Page Header@@ -327,10 +327,10 @@ RSpec.describe "Admin Create a new file storage",endend- describe "Select provider page" do+ describe "new page" docontext "when navigating directly to the page" doit "redirects you back to the index page" do- visit select_provider_admin_settings_storages_path+ visit new_admin_settings_storage_pathexpect(page).to have_current_path(admin_settings_storages_path)wait_for { page }.to have_text("Please select a valid storage provider.")@@ -339,7 +339,7 @@ RSpec.describe "Admin Create a new file storage",context "when navigating to the page with an invalid provider" doit "redirects you back to the index page" do- visit select_provider_admin_settings_storages_path(provider: "foobar")+ visit new_admin_settings_storage_path(provider: "foobar")expect(page).to have_current_path(admin_settings_storages_path)wait_for { page }.to have_text("Please select a valid storage provider.")diff --git a/modules/storages/spec/services/storages/wizard_spec.rb b/modules/storages/spec/services/storages/wizard_spec.rbnew file mode 100644index 00000000000..eeacb58af5c--- /dev/null+++ b/modules/storages/spec/services/storages/wizard_spec.rb@@ -0,0 +1,144 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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 "spec_helper"++RSpec.describe Storages::Wizard do+ subject(:wizard) { wizard_class.new(model:) }++ let(:wizard_class) do+ Class.new(described_class) do+ step :a, completed_if: ->(i) { i > 0 }+ step :b, completed_if: :greater_five+ step :c, completed_if: ->(i) { i > 10 }++ def greater_five(number)+ number > 5+ end+ end+ end+ let(:model) { 5 }++ it "lists all steps" do+ expect(wizard.steps).to eq(%i[a b c])+ end++ it "lists all completed steps" do+ expect(wizard.completed_steps).to eq(%i[a])+ end++ it "lists all pending steps" do+ expect(wizard.pending_steps).to eq(%i[b c])+ end++ describe "conditional steps" do+ let(:wizard_class) do+ Class.new(described_class) do+ step :a, completed_if: ->(i) { i > 0 }, if: ->(i) { i.even? }+ step :b, completed_if: ->(i) { i > 4 }, if: :odd+ step :c, completed_if: ->(i) { i > 10 }, if: :even+ step :d, completed_if: ->(i) { i > 20 }, if: ->(i) { i.odd? }++ def odd(number)+ number.odd?+ end++ def even(number)+ number.even?+ end+ end+ end++ it "lists relevant steps" do+ expect(wizard.steps).to eq(%i[b d])+ end++ it "lists relevant completed steps" do+ expect(wizard.completed_steps).to eq(%i[b])+ end++ it "lists relevant pending steps" do+ expect(wizard.pending_steps).to eq(%i[d])+ end++ context "when model matches alternative conditions" do+ let(:model) { 6 }++ it "lists relevant steps" do+ expect(wizard.steps).to eq(%i[a c])+ end++ it "lists relevant completed steps" do+ expect(wizard.completed_steps).to eq(%i[a])+ end++ it "lists relevant pending steps" do+ expect(wizard.pending_steps).to eq(%i[c])+ end+ end+ end++ describe "#prepare_next_step" do+ subject(:call) { wizard_class.new(model:).prepare_next_step }++ let(:wizard_class) do+ do_call = call_double # binding to local variable, so that it can be passed into class block+ Class.new(described_class) do+ def self.dont_call(step_name)+ ->(_) { raise "Step #{step_name} should not have been prepared" }+ end++ step :a, completed_if: ->(i) { i > 0 }, preparation: dont_call(:a)+ step :b, completed_if: ->(i) { i > 10 }, if: ->(i) { i.even? }, preparation: dont_call(:b)+ step :c, completed_if: ->(i) { i > 10 }, if: ->(i) { i.odd? }, preparation: do_call+ step :d, completed_if: ->(i) { i > 20 }, if: ->(i) { i.odd? }, preparation: dont_call(:d)+ end+ end+ let(:call_double) { instance_double(Proc, call: nil) }++ it { is_expected.to eq(:c) }++ it "calls the prepare hook for step c" do+ call+ expect(call_double).to have_received(:call).with(model)+ end++ context "when all steps are completed" do+ let(:model) { 100 }++ it { is_expected.to be_nil }++ it "does not prepare anything" do+ call+ expect(call_double).not_to have_received(:call)+ end+ end+ end+end