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

Utilize wizard in StorageViewComponent

Jan Sandbrink321646258981
diff --git a/modules/storages/app/common/storages/peripherals/nextcloud_registry.rb b/modules/storages/app/common/storages/peripherals/nextcloud_registry.rb
index a831f1cf9c0..29fd50b82a9 100644
--- a/modules/storages/app/common/storages/peripherals/nextcloud_registry.rb
+++ b/modules/storages/app/common/storages/peripherals/nextcloud_registry.rb
@@ -58,7 +58,19 @@ module Storages
end
namespace("components") do
+ namespace("forms") do
+ register(:automatically_managed_folders, ::Storages::Admin::Forms::AutomaticallyManagedProjectFoldersFormComponent)
+ register(:general_information, ::Storages::Admin::Forms::GeneralInfoFormComponent)
+ register(:oauth_application, ::Storages::Admin::OAuthApplicationInfoCopyComponent)
+ register(:oauth_client, ::Storages::Admin::Forms::OAuthClientFormComponent)
+ end
+
register(:setup_wizard, NextcloudStorageWizard)
+
+ register(:automatically_managed_folders, ::Storages::Admin::AutomaticallyManagedProjectFoldersInfoComponent)
+ register(:general_information, ::Storages::Admin::GeneralInfoComponent)
+ register(:oauth_application, ::Storages::Admin::OAuthApplicationInfoComponent)
+ register(:oauth_client, ::Storages::Admin::OAuthClientInfoComponent)
end
namespace("contracts") do
diff --git a/modules/storages/app/common/storages/peripherals/nextcloud_storage_wizard.rb b/modules/storages/app/common/storages/peripherals/nextcloud_storage_wizard.rb
index 92f598b4f4f..da4dd958725 100644
--- a/modules/storages/app/common/storages/peripherals/nextcloud_storage_wizard.rb
+++ b/modules/storages/app/common/storages/peripherals/nextcloud_storage_wizard.rb
@@ -31,17 +31,19 @@
module Storages
module Peripherals
class NextcloudStorageWizard < Wizard
- step :general_info, completed_if: ->(storage) { storage.host.present? && storage.name.present? }
+ step :general_information, completed_if: ->(storage) { storage.host.present? && storage.name.present? }
step :oauth_application,
+ section: :oauth_configuration,
completed_if: ->(storage) { storage.oauth_application.present? },
preparation: :prepare_oauth_application
step :oauth_client,
+ section: :oauth_configuration,
completed_if: ->(storage) { storage.oauth_client.present? },
preparation: ->(storage) { storage.build_oauth_client }
- step :automatically_managed_project_folders,
+ step :automatically_managed_folders,
completed_if: ->(storage) { !storage.automatic_management_unspecified? },
preparation: :prepare_storage_for_automatic_management_form
diff --git a/modules/storages/app/common/storages/peripherals/one_drive_registry.rb b/modules/storages/app/common/storages/peripherals/one_drive_registry.rb
index 4bc565b1ea0..5b4cd94b1d3 100644
--- a/modules/storages/app/common/storages/peripherals/one_drive_registry.rb
+++ b/modules/storages/app/common/storages/peripherals/one_drive_registry.rb
@@ -52,7 +52,19 @@ module Storages
end
namespace("components") do
+ namespace("forms") do
+ register(:access_management, ::Storages::Admin::Forms::AccessManagementFormComponent)
+ register(:general_information, ::Storages::Admin::Forms::GeneralInfoFormComponent)
+ register(:oauth_client, ::Storages::Admin::Forms::OAuthClientFormComponent)
+ register(:redirect_uri, ::Storages::Admin::Forms::RedirectUriFormComponent)
+ end
+
register(:setup_wizard, OneDriveStorageWizard)
+
+ register(:access_management, ::Storages::Admin::AccessManagementComponent)
+ register(:general_information, ::Storages::Admin::GeneralInfoComponent)
+ register(:oauth_client, ::Storages::Admin::OAuthClientInfoComponent)
+ register(:redirect_uri, ::Storages::Admin::RedirectUriComponent)
end
namespace("contracts") do
diff --git a/modules/storages/app/common/storages/peripherals/one_drive_storage_wizard.rb b/modules/storages/app/common/storages/peripherals/one_drive_storage_wizard.rb
index 72598709360..242aaeb81c0 100644
--- a/modules/storages/app/common/storages/peripherals/one_drive_storage_wizard.rb
+++ b/modules/storages/app/common/storages/peripherals/one_drive_storage_wizard.rb
@@ -31,17 +31,20 @@
module Storages
module Peripherals
class OneDriveStorageWizard < Wizard
- step :general_info, completed_if: ->(storage) { storage.name.present? }
+ step :general_information, completed_if: ->(storage) { storage.name.present? }
step :access_management,
+ section: :access_management_section,
completed_if: ->(storage) { !storage.automatic_management_unspecified? },
preparation: :prepare_storage_for_access_management_form
step :oauth_client,
+ section: :oauth_configuration,
completed_if: ->(storage) { storage.oauth_client.present? },
preparation: ->(storage) { storage.build_oauth_client }
step :redirect_uri,
+ section: :oauth_configuration,
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
diff --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.rb
index 9ea99d12b2f..01574e16714 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
@@ -33,18 +33,12 @@ module Storages::Admin::Forms
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
- attr_reader :storage
- alias_method :oauth_client, :model
+ alias_method :storage, :model
options in_wizard: false
def self.wrapper_key = :storage_oauth_client_section
- def initialize(oauth_client:, storage:, **)
- super(oauth_client, **)
- @storage = storage
- end
-
def form_url
query = { continue_wizard: storage.id } if in_wizard
admin_settings_storage_oauth_client_path(storage, query)
@@ -65,6 +59,10 @@ module Storages::Admin::Forms
private
+ def oauth_client
+ options[:oauth_client] || storage.oauth_client
+ end
+
def one_drive_integration_link(target: "_blank")
href = ::OpenProject::Static::Links[:storage_docs][:one_drive_oauth_application][:href]
render(Primer::Beta::Link.new(href:, target:)) { I18n.t("storages.instructions.one_drive.application_link_text") }
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.rb
index 4e2b83c4f43..dbab6ee3504 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
@@ -33,18 +33,13 @@ module Storages::Admin::Forms
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
- attr_reader :storage
- alias_method :oauth_client, :model
+ alias_method :storage, :model
+ delegate :oauth_client, to: :storage
options in_wizard: false
def self.wrapper_key = :storage_redirect_uri_section
- def initialize(oauth_client:, storage:, **)
- super(oauth_client, **)
- @storage = storage
- end
-
def form_url
query = { continue_wizard: storage.id } if in_wizard
finish_setup_admin_settings_storage_oauth_client_path(storage, query)
diff --git a/modules/storages/app/components/storages/admin/oauth_application_info_component.rb b/modules/storages/app/components/storages/admin/oauth_application_info_component.rb
index 90070af8630..5942b42fb55 100644
--- a/modules/storages/app/components/storages/admin/oauth_application_info_component.rb
+++ b/modules/storages/app/components/storages/admin/oauth_application_info_component.rb
@@ -34,13 +34,8 @@ module Storages::Admin
include OpTurbo::Streamable
include StorageViewInformation
- attr_reader :storage
- alias_method :oauth_application, :model
-
- def initialize(oauth_application:, storage:, **)
- super(oauth_application, **)
- @storage = storage
- end
+ alias_method :storage, :model
+ delegate :oauth_application, to: :storage
def self.wrapper_key = :storage_openproject_oauth_section
end
diff --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.rb
index d2ae8e8e3b0..8a0d6df3b98 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
@@ -33,16 +33,11 @@ module Storages::Admin
include OpTurbo::Streamable
include OpPrimer::ComponentHelpers
- attr_reader :storage
- alias_method :oauth_application, :model
+ alias_method :storage, :model
+ delegate :oauth_application, to: :storage
options in_wizard: false
- def initialize(oauth_application:, storage:, **)
- super(oauth_application, **)
- @storage = storage
- end
-
def self.wrapper_key = :storage_openproject_oauth_section
def oauth_application_details_link
diff --git a/modules/storages/app/components/storages/admin/oauth_client_info_component.rb b/modules/storages/app/components/storages/admin/oauth_client_info_component.rb
index b4379d32cf8..917957b5a1f 100644
--- a/modules/storages/app/components/storages/admin/oauth_client_info_component.rb
+++ b/modules/storages/app/components/storages/admin/oauth_client_info_component.rb
@@ -34,13 +34,8 @@ module Storages::Admin
include OpTurbo::Streamable
include StorageViewInformation
- attr_reader :storage
- alias_method :oauth_client, :model
-
- def initialize(oauth_client:, storage:, **)
- super(oauth_client, **)
- @storage = storage
- end
+ alias_method :storage, :model
+ delegate :oauth_client, to: :storage
def self.wrapper_key = :storage_oauth_client_section
diff --git a/modules/storages/app/components/storages/admin/redirect_uri_component.rb b/modules/storages/app/components/storages/admin/redirect_uri_component.rb
index 525a476158b..56b79da3359 100644
--- a/modules/storages/app/components/storages/admin/redirect_uri_component.rb
+++ b/modules/storages/app/components/storages/admin/redirect_uri_component.rb
@@ -34,13 +34,8 @@ module Storages::Admin
include OpTurbo::Streamable
include StorageViewInformation
- attr_reader :storage
- alias_method :oauth_client, :model
-
- def initialize(oauth_client:, storage:, **)
- super(oauth_client, **)
- @storage = storage
- end
+ alias_method :storage, :model
+ delegate :oauth_client, to: :storage
def self.wrapper_key = :storage_redirect_uri_section
diff --git a/modules/storages/app/components/storages/admin/storage_view_component.html.erb b/modules/storages/app/components/storages/admin/storage_view_component.html.erb
index 0423a7cb750..269abc97890 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
@@ -1,97 +1,25 @@
<%=
render(border_box_container) do |component|
- component.with_header(color: :muted) do
- render(Primer::Beta::Text.new(font_weight: :semibold)) { I18n.t('storages.file_storage_view.general_information') }
- end
-
- component.with_row(scheme: :default) do
- if wizard_step == "general_info"
- render(Storages::Admin::Forms::GeneralInfoFormComponent.new(storage, in_wizard: true))
- else
- render(Storages::Admin::GeneralInfoComponent.new(storage))
- end
- end
-
- if storage.provider_type_nextcloud?
- component.with_row(scheme: :neutral, color: :muted) do
- grid_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_configuration') }
- end
- end
- end
-
- component.with_row(scheme: :default) do
- if wizard_step == "oauth_application"
- render(Storages::Admin::OAuthApplicationInfoCopyComponent.new(oauth_application:, storage:, in_wizard: true))
- else
- render(Storages::Admin::OAuthApplicationInfoComponent.new(oauth_application:, storage:))
- end
- end
-
- component.with_row(scheme: :default) do
- 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:))
- end
- end
-
- component.with_row(scheme: :neutral, color: :muted) do
- grid_layout('op-storage-view--row', tag: :div, align_items: :center) do |grid|
- grid.with_area(:item, tag: :div) do
- render(Primer::Beta::Text.new(font_weight: :semibold, mr: 1)) { I18n.t('storages.file_storage_view.project_folders') }
- end
- end
- end
-
- component.with_row(scheme: :default) do
- if wizard_step == "automatically_managed_project_folders"
- render(Storages::Admin::Forms::AutomaticallyManagedProjectFoldersFormComponent.new(storage, in_wizard: true))
- else
- render(Storages::Admin::AutomaticallyManagedProjectFoldersInfoComponent.new(storage))
- end
- end
- end
-
- if storage.provider_type_one_drive?
- component.with_row(scheme: :neutral, color: :muted) do
- grid_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.access_management.title') }
+ last_section = nil
+ wizard.steps.each do |step_name|
+ if wizard.section_name(step_name) != last_section
+ section_name = wizard.section_name(step_name)
+ component.with_row(scheme: :neutral, color: :muted) do
+ grid_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.#{section_name}") }
+ end
end
end
- end
- component.with_row(scheme: :default) do
- if wizard_step == "access_management"
- render(Storages::Admin::Forms::AccessManagementFormComponent.new(storage, in_wizard: true))
- else
- render(Storages::Admin::AccessManagementComponent.new(storage))
- end
- end
-
- component.with_row(scheme: :neutral, color: :muted) do
- grid_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_configuration') }
- end
- end
- end
-
- component.with_row(scheme: :default) do
- 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:))
- end
+ last_section = section_name
end
component.with_row(scheme: :default) do
- if wizard_step == "redirect_uri"
- render(Storages::Admin::Forms::RedirectUriFormComponent.new(oauth_client: storage.oauth_client, storage:, in_wizard: true))
+ if wizard_step == step_name
+ render(Storages::Peripherals::Registry.resolve("#{storage}.components.forms.#{step_name}").new(storage, in_wizard: true))
else
- render(Storages::Admin::RedirectUriComponent.new(oauth_client: storage.oauth_client, storage:))
+ render(Storages::Peripherals::Registry.resolve("#{storage}.components.#{step_name}").new(storage))
end
end
end
diff --git a/modules/storages/app/components/storages/admin/storage_view_component.rb b/modules/storages/app/components/storages/admin/storage_view_component.rb
index ac891fab8d7..98f57b89db1 100644
--- a/modules/storages/app/components/storages/admin/storage_view_component.rb
+++ b/modules/storages/app/components/storages/admin/storage_view_component.rb
@@ -33,10 +33,15 @@ module Storages::Admin
include OpPrimer::ComponentHelpers
include StorageViewInformation
- options wizard_step: nil
+ options wizard: nil,
+ wizard_step: nil
- alias_method :storage, :model
+ def initialize(*, **)
+ super
+
+ raise ArgumentError, "wizard is required" if wizard.nil?
+ end
- delegate :oauth_application, to: :model
+ alias_method :storage, :model
end
end
diff --git a/modules/storages/app/controllers/storages/admin/automatically_managed_project_folders_controller.rb b/modules/storages/app/controllers/storages/admin/automatically_managed_project_folders_controller.rb
index b8732de7ed6..c17eff8a72c 100644
--- a/modules/storages/app/controllers/storages/admin/automatically_managed_project_folders_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/automatically_managed_project_folders_controller.rb
@@ -99,6 +99,8 @@ class Storages::Admin::AutomaticallyManagedProjectFoldersController < Applicatio
if service_result.success?
redirect_to edit_admin_settings_storage_path(@storage)
else
+ @wizard = ::Storages::Peripherals::Registry.resolve("#{@storage}.components.setup_wizard")
+ .new(model: @storage, user: current_user)
render :edit
end
end
@@ -123,6 +125,8 @@ class Storages::Admin::AutomaticallyManagedProjectFoldersController < Applicatio
component: Storages::Admin::Forms::AutomaticallyManagedProjectFoldersFormComponent.new(@storage)
)
+ @wizard = ::Storages::Peripherals::Registry.resolve("#{@storage}.components.setup_wizard")
+ .new(model: @storage, user: current_user)
respond_with_turbo_streams do |format|
format.html { render :edit }
end
diff --git a/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rb b/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rb
index aa6691d0115..9be0c0cfea9 100644
--- a/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rb
@@ -47,30 +47,31 @@ class Storages::Admin::OAuthClientsController < ApplicationController
# Show the admin page to create a new OAuthClient object.
def new
- @oauth_client = ::OAuthClients::SetAttributesService
+ oauth_client = ::OAuthClients::SetAttributesService
.new(user: User.current,
model: OAuthClient.new,
contract_class: EmptyContract)
.call
.result
- update_via_turbo_stream(component: Storages::Admin::Forms::OAuthClientFormComponent.new(oauth_client: @oauth_client,
- storage: @storage))
+ update_via_turbo_stream(component: Storages::Admin::Forms::OAuthClientFormComponent.new(@storage, oauth_client:))
respond_with_turbo_streams
end
- def create # rubocop:disable Metrics/AbcSize
+ def create
call_oauth_clients_create_service
service_result.on_failure do
- update_via_turbo_stream(component: Storages::Admin::Forms::OAuthClientFormComponent.new(oauth_client: @oauth_client,
- storage: @storage,
- in_wizard: true))
+ update_via_turbo_stream(component: Storages::Admin::Forms::OAuthClientFormComponent.new(
+ @storage,
+ oauth_client: @oauth_client,
+ in_wizard: in_wizard?
+ ))
respond_with_turbo_streams
end
service_result.on_success do
- redirect_to(new_admin_settings_storage_path(continue_wizard: @storage.id), status: :see_other)
+ respond_for_success
end
end
@@ -78,19 +79,16 @@ class Storages::Admin::OAuthClientsController < ApplicationController
call_oauth_clients_create_service
service_result.on_failure do
- update_via_turbo_stream(component: Storages::Admin::Forms::OAuthClientFormComponent.new(oauth_client: @oauth_client,
- storage: @storage))
+ update_via_turbo_stream(component: Storages::Admin::Forms::OAuthClientFormComponent.new(
+ @storage,
+ oauth_client: @oauth_client
+ ))
+ respond_with_turbo_streams
end
service_result.on_success do
- update_via_turbo_stream(component: Storages::Admin::OAuthClientInfoComponent.new(oauth_client: @oauth_client,
- storage: @storage))
- update_via_turbo_stream(component: Storages::Admin::RedirectUriComponent.new(
- oauth_client: @oauth_client, storage: @storage
- ))
+ respond_for_success
end
-
- respond_with_turbo_streams
end
# Used by: admin layout
@@ -150,4 +148,17 @@ class Storages::Admin::OAuthClientsController < ApplicationController
def find_storage
@storage = ::Storages::Storage.find(params[:storage_id])
end
+
+ def respond_for_success
+ if in_wizard?
+ redirect_to(new_admin_settings_storage_path(continue_wizard: @storage.id), status: :see_other)
+ else
+ update_via_turbo_stream(component: Storages::Admin::OAuthClientInfoComponent.new(@storage))
+ respond_with_turbo_streams
+ end
+ end
+
+ def in_wizard?
+ params[:continue_wizard].present?
+ 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 1b6718ac7c7..3599b0d72f0 100644
--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb
@@ -75,7 +75,8 @@ class Storages::Admin::StoragesController < ApplicationController
.result
end
- @target_step = storage_wizard(@storage).prepare_next_step.to_s
+ @wizard = storage_wizard(@storage)
+ @target_step = @wizard.prepare_next_step
end
def upsale; end
@@ -105,7 +106,9 @@ class Storages::Admin::StoragesController < ApplicationController
end
end
- def edit; end
+ def edit
+ @wizard = storage_wizard(@storage)
+ end
def edit_host
update_via_turbo_stream(
@@ -141,6 +144,7 @@ class Storages::Admin::StoragesController < ApplicationController
)
)
+ @wizard = storage_wizard(@storage)
respond_with_turbo_streams do |format|
# FIXME: This should be a partial stream update
format.html { render :edit }
@@ -156,6 +160,7 @@ class Storages::Admin::StoragesController < ApplicationController
respond_with_turbo_streams
else
flash.now[:error] = I18n.t("storages.health_email_notifications.error_could_not_be_saved")
+ @wizard = storage_wizard(@storage)
render :edit
end
end
@@ -185,20 +190,16 @@ class Storages::Admin::StoragesController < ApplicationController
def replace_oauth_application
@storage.oauth_application.destroy
service_result = ::Storages::OAuthApplications::CreateService.new(storage: @storage, user: current_user).call
- @oauth_application = service_result.result
if service_result.success?
- update_via_turbo_stream(component: Storages::Admin::GeneralInfoComponent.new(@storage))
+ @storage.oauth_application = service_result.result
- update_via_turbo_stream(
- component: Storages::Admin::OAuthApplicationInfoCopyComponent.new(
- oauth_application: @oauth_application,
- storage: @storage
- )
- )
+ update_via_turbo_stream(component: Storages::Admin::GeneralInfoComponent.new(@storage))
+ update_via_turbo_stream(component: Storages::Admin::OAuthApplicationInfoCopyComponent.new(@storage))
respond_with_turbo_streams
else
+ @wizard = storage_wizard(@storage)
# FIXME: This should be a partial stream update
render :edit
end
diff --git a/modules/storages/app/services/storages/wizard.rb b/modules/storages/app/services/storages/wizard.rb
index 344664966bb..b9aa09cc597 100644
--- a/modules/storages/app/services/storages/wizard.rb
+++ b/modules/storages/app/services/storages/wizard.rb
@@ -30,7 +30,7 @@
module Storages
class Wizard
- StepDefinition = Data.define(:name, :if, :completed_if, :preparation) do
+ StepDefinition = Data.define(:name, :section, :if, :completed_if, :preparation) do
def use_on?(wizard)
call_with_model(self.if, wizard)
end
@@ -63,9 +63,9 @@ module Storages
steps_by_name.values
end
- def step(name, completed_if:, if: ->(_) { true }, preparation: ->(_) {})
+ def step(name, completed_if:, if: ->(_) { true }, preparation: ->(_) {}, section: name)
name = name.to_sym
- steps_by_name[name] = StepDefinition.new(name:, if:, completed_if:, preparation:)
+ steps_by_name[name] = StepDefinition.new(name:, section:, if:, completed_if:, preparation:)
end
end
@@ -85,6 +85,10 @@ module Storages
next_step
end
+ def section_name(name)
+ steps_by_name.fetch(name).section
+ end
+
def steps
self.class.steps.select { |s| s.use_on?(self) }.map(&:name)
end
diff --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.erb
index 533b63de450..dc0f540ac11 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, wizard_step: "automatically_managed_project_folders")) %>
+<%= render(Storages::Admin::StorageViewComponent.new(@storage, wizard: @wizard, wizard_step: :automatically_managed_folders)) %>
diff --git a/modules/storages/app/views/storages/admin/oauth_clients/show_redirect_uri.html.erb b/modules/storages/app/views/storages/admin/oauth_clients/show_redirect_uri.html.erb
index d02d665398a..099985eedfc 100644
--- a/modules/storages/app/views/storages/admin/oauth_clients/show_redirect_uri.html.erb
+++ b/modules/storages/app/views/storages/admin/oauth_clients/show_redirect_uri.html.erb
@@ -27,4 +27,4 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
-<%= render(Storages::Admin::Forms::RedirectUriFormComponent.new(oauth_client: @storage.oauth_client, storage: @storage, is_complete: true)) %>
+<%= render(Storages::Admin::Forms::RedirectUriFormComponent.new(@storage, is_complete: true)) %>
diff --git a/modules/storages/app/views/storages/admin/storages/edit.html.erb b/modules/storages/app/views/storages/admin/storages/edit.html.erb
index 4c349bb1a60..55aea48a593 100644
--- a/modules/storages/app/views/storages/admin/storages/edit.html.erb
+++ b/modules/storages/app/views/storages/admin/storages/edit.html.erb
@@ -29,20 +29,15 @@ See COPYRIGHT and LICENSE files for more details.
<% html_title t(:label_administration), t(:project_module_storages), t(:label_edit_x, x: @storage.name) %>
-
<%= content_tag("turbo-frame", id: "page-content") do %>
- <%= render(Storages::Admin::EditFormHeaderComponent.new(
- storage: @storage,
- selected: :edit
- ))
- %>
+ <%= 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)) %>
+ <%= render(Storages::Admin::StorageViewComponent.new(@storage, wizard: @wizard)) %>
<% end %>
<% component.with_sidebar(col_placement: :end, row_placement: :end) do %>
- <%= render(::Storages::Admin::SidePanelComponent.new(storage: @storage)) %>
+ <%= render(Storages::Admin::SidePanelComponent.new(storage: @storage)) %>
<% end %>
<% end %>
<% 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 0845b7d2c2d..0c1a6243ac7 100644
--- a/modules/storages/app/views/storages/admin/storages/new.html.erb
+++ b/modules/storages/app/views/storages/admin/storages/new.html.erb
@@ -26,5 +26,5 @@
<% end %>
<%= content_tag("turbo-frame", id: "page-content") do %>
- <%= render(Storages::Admin::StorageViewComponent.new(@storage, wizard_step: @target_step)) %>
+ <%= render(Storages::Admin::StorageViewComponent.new(@storage, wizard: @wizard, wizard_step: @target_step)) %>
<% end %>
diff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.yml
index ac149773170..c26e5ade9f1 100644
--- a/modules/storages/config/locales/en.yml
+++ b/modules/storages/config/locales/en.yml
@@ -200,7 +200,7 @@ en:
manual_management_description: Create and manage folders per project manually on your own. You will need to manually ensure relevant users have access.
setup_incomplete: Select the type of management of user access and folder creation.
subtitle: Access management
- title: Access and project folders
+ access_management_section: Access and project folders
automatically_managed_folders: Automatically managed folders
general_information: General information
nextcloud_oauth: Nextcloud OAuth
diff --git a/modules/storages/spec/common/storages/peripherals/nextcloud_storage_wizard_spec.rb b/modules/storages/spec/common/storages/peripherals/nextcloud_storage_wizard_spec.rb
index 830dea365ff..d3f4b0a781e 100644
--- a/modules/storages/spec/common/storages/peripherals/nextcloud_storage_wizard_spec.rb
+++ b/modules/storages/spec/common/storages/peripherals/nextcloud_storage_wizard_spec.rb
@@ -45,10 +45,10 @@ RSpec.describe Storages::Peripherals::NextcloudStorageWizard do
end
it "has all steps pending in correct order" do
- expect(wizard.pending_steps).to eq(%i[general_info
+ expect(wizard.pending_steps).to eq(%i[general_information
oauth_application
oauth_client
- automatically_managed_project_folders])
+ automatically_managed_folders])
end
context "when name and host were set" do
@@ -58,8 +58,8 @@ RSpec.describe Storages::Peripherals::NextcloudStorageWizard do
model.save!
end
- it "has general_info step completed" do
- expect(wizard.completed_steps).to eq(%i[general_info])
+ it "has general_information step completed" do
+ expect(wizard.completed_steps).to eq(%i[general_information])
end
it "has no oauth_application yet" do
@@ -72,7 +72,7 @@ RSpec.describe Storages::Peripherals::NextcloudStorageWizard do
end
it "automatically finished the oauth_application step" do
- expect(wizard.completed_steps).to eq(%i[general_info
+ expect(wizard.completed_steps).to eq(%i[general_information
oauth_application])
end
@@ -90,7 +90,7 @@ RSpec.describe Storages::Peripherals::NextcloudStorageWizard do
end
it "finishes the oauth_client step" do
- expect(wizard.completed_steps).to eq(%i[general_info
+ expect(wizard.completed_steps).to eq(%i[general_information
oauth_application
oauth_client])
end
@@ -122,10 +122,10 @@ RSpec.describe Storages::Peripherals::NextcloudStorageWizard do
end
it "has all steps completed" do
- expect(wizard.completed_steps).to eq(%i[general_info
+ expect(wizard.completed_steps).to eq(%i[general_information
oauth_application
oauth_client
- automatically_managed_project_folders])
+ automatically_managed_folders])
end
end
end
diff --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.rb
index 5ae76703ed1..d06fcd07847 100644
--- 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.rb
@@ -45,7 +45,7 @@ RSpec.describe Storages::Peripherals::OneDriveStorageWizard do
end
it "has all steps pending in correct order" do
- expect(wizard.pending_steps).to eq(%i[general_info
+ expect(wizard.pending_steps).to eq(%i[general_information
access_management
oauth_client
redirect_uri])
@@ -57,8 +57,8 @@ RSpec.describe Storages::Peripherals::OneDriveStorageWizard do
model.save!
end
- it "has general_info step completed" do
- expect(wizard.completed_steps).to eq(%i[general_info])
+ it "has general_information step completed" do
+ expect(wizard.completed_steps).to eq(%i[general_information])
end
it "still didn't specify how to manage folders" do
@@ -71,7 +71,7 @@ RSpec.describe Storages::Peripherals::OneDriveStorageWizard do
end
it "automatically finished the access_management step" do
- expect(wizard.completed_steps).to eq(%i[general_info
+ expect(wizard.completed_steps).to eq(%i[general_information
access_management])
end
@@ -93,7 +93,7 @@ RSpec.describe Storages::Peripherals::OneDriveStorageWizard do
end
it "finishes the oauth_client step" do
- expect(wizard.completed_steps).to eq(%i[general_info
+ expect(wizard.completed_steps).to eq(%i[general_information
access_management
oauth_client])
end
@@ -115,7 +115,7 @@ RSpec.describe Storages::Peripherals::OneDriveStorageWizard do
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
+ expect(wizard.completed_steps).to eq(%i[general_information
access_management
oauth_client
redirect_uri])
diff --git a/modules/storages/spec/components/storages/admin/oauth_client_info_component_spec.rb b/modules/storages/spec/components/storages/admin/oauth_client_info_component_spec.rb
index e638f208e83..72e39108781 100644
--- a/modules/storages/spec/components/storages/admin/oauth_client_info_component_spec.rb
+++ b/modules/storages/spec/components/storages/admin/oauth_client_info_component_spec.rb
@@ -35,7 +35,7 @@ RSpec.describe Storages::Admin::OAuthClientInfoComponent, type: :component do #
it "returns false, does not render view component" do
storage = build_stubbed(:nextcloud_storage,
oauth_client: build_stubbed(:oauth_client))
- component = described_class.new(storage:, oauth_client: storage.oauth_client)
+ component = described_class.new(storage)
expect(component.edit_icon_button_options)
.to include(icon: :sync,
data: { turbo_confirm:
@@ -49,7 +49,7 @@ RSpec.describe Storages::Admin::OAuthClientInfoComponent, type: :component do #
context "without oauth client" do
it "returns true, renders view component" do
storage = build_stubbed(:nextcloud_storage)
- component = described_class.new(storage:, oauth_client: nil)
+ component = described_class.new(storage)
edit_icon_button_data_options = component.edit_icon_button_options
expect(edit_icon_button_data_options).to include(icon: :pencil, data: { turbo_stream: true })
diff --git a/modules/storages/spec/services/storages/wizard_spec.rb b/modules/storages/spec/services/storages/wizard_spec.rb
index eeacb58af5c..228bdf4c4ba 100644
--- a/modules/storages/spec/services/storages/wizard_spec.rb
+++ b/modules/storages/spec/services/storages/wizard_spec.rb
@@ -141,4 +141,21 @@ RSpec.describe Storages::Wizard do
end
end
end
+
+ describe "#section_name" do
+ let(:wizard_class) do
+ Class.new(described_class) do
+ step :a, completed_if: ->(i) { i > 0 }
+ step :b, completed_if: ->(i) { i > 10 }, section: :c
+ end
+ end
+
+ it "defaults to the step name" do
+ expect(wizard.section_name(:a)).to eq(:a)
+ end
+
+ it "uses the name passed by section parameter if present" do
+ expect(wizard.section_name(:b)).to eq(:c)
+ end
+ end
end