Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

feat[Op#50737]: Introduce OneDrive general info form

Kabiru Mwenja98cec86c0a77
diff --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.erb
index dcfb25f133e..14d38c47695 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
@@ -14,12 +14,22 @@
render(Storages::Admin::ProviderNameInputForm.new(form))
end
- if render_host?
+ if storage.provider_type_nextcloud?
general_info_row.with_row(mb: 3) do
render(Storages::Admin::ProviderHostInputForm.new(form))
end
end
+ if storage.provider_type_one_drive?
+ general_info_row.with_row(mb: 3) do
+ render(Storages::Admin::ProviderTenantIdInputForm.new(form))
+ end
+
+ general_info_row.with_row(mb: 3) do
+ render(Storages::Admin::ProviderDriveIdInputForm.new(form))
+ end
+ end
+
general_info_row.with_row do
render(
Storages::Admin::SubmitOrCancelForm.new(
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.rb
index 3a68fae1a7a..7644214c9ad 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
@@ -34,13 +34,10 @@ module Storages::Admin::Forms
alias_method :storage, :model
options form_method: :post,
- render_host: true,
submit_button_disabled: false,
cancel_button_should_break_from_frame: false,
cancel_button_path: Rails.application.routes.url_helpers.admin_settings_storages_path
- alias_method :render_host?, :render_host
-
def form_url
options[:form_url] || default_form_url
end
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 135b96f3809..cf405e618d7 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
@@ -19,48 +19,50 @@
end
end
- component.with_row(scheme: :neutral) 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_applications') }
+ if storage.provider_type_nextcloud?
+ component.with_row(scheme: :neutral) 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_applications') }
+ end
end
end
- end
- component.with_row(scheme: :default) do
- render(OpTurbo::FrameComponent.new(id: :storage_openproject_oauth_section)) do
- if storage.new_record? || openproject_oauth_application_section_closed?
- render(Storages::Admin::OAuthApplicationInfoComponent.new(oauth_application:, storage:))
- else
- render(
- Storages::Admin::OAuthApplicationInfoCopyComponent.new(
- oauth_application:,
- storage:,
- submit_button_path: show_oauth_application_admin_settings_storage_path(storage),
- cancel_button_path: admin_settings_storages_path
+ component.with_row(scheme: :default) do
+ render(OpTurbo::FrameComponent.new(id: :storage_openproject_oauth_section)) do
+ if storage.new_record? || openproject_oauth_application_section_closed?
+ render(Storages::Admin::OAuthApplicationInfoComponent.new(oauth_application:, storage:))
+ else
+ render(
+ Storages::Admin::OAuthApplicationInfoCopyComponent.new(
+ oauth_application:,
+ storage:,
+ submit_button_path: show_oauth_application_admin_settings_storage_path(storage),
+ cancel_button_path: admin_settings_storages_path
+ )
)
- )
+ end
end
end
- end
- component.with_row(scheme: :default) do
- render(OpTurbo::FrameComponent.new(id: :storage_oauth_client_section)) do
- render(Storages::Admin::OAuthClientInfoComponent.new(oauth_client: storage.oauth_client, storage:))
+ component.with_row(scheme: :default) do
+ render(OpTurbo::FrameComponent.new(id: :storage_oauth_client_section)) do
+ render(Storages::Admin::OAuthClientInfoComponent.new(oauth_client: storage.oauth_client, storage:))
+ end
end
- end
- component.with_row(scheme: :neutral) 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') }
+ component.with_row(scheme: :neutral) 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
- end
- component.with_row(scheme: :default) do
- render(OpTurbo::FrameComponent.new(id: :automatically_managed_project_folders_section)) do
- render(Storages::Admin::AutomaticallyManagedProjectFoldersInfoComponent.new(storage))
+ component.with_row(scheme: :default) do
+ render(OpTurbo::FrameComponent.new(id: :automatically_managed_project_folders_section)) do
+ render(Storages::Admin::AutomaticallyManagedProjectFoldersInfoComponent.new(storage))
+ end
end
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 3ae95aca18d..c2c125f9442 100644
--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb
@@ -239,14 +239,11 @@ class Storages::Admin::StoragesController < ApplicationController
.permit('name', 'provider_type', 'host', 'oauth_client_id', 'oauth_client_secret', 'tenant_id', 'drive_id')
end
- # TODO: Work out how to retrieve the storage provider resource name as it's based on the provider type
- # PrimerForms implements Rails `form_with` which doesn't support overriding the form name as we would with
- # `form_for`.
- # See: https://github.com/opf/primer_view_components/blob/79fb58474771bd06946554f8325cd0b1bdd6dd31/app/helpers/primer/form_helper.rb#L7
- #
def storage_provider_parameter_name
if params.key?(:storages_nextcloud_storage)
:storages_nextcloud_storage
+ elsif params.key?(:storages_one_drive_storage)
+ :storages_one_drive_storage
else
:storages_storage
end
diff --git a/modules/storages/app/forms/storages/admin/provider_drive_id_input_form.rb b/modules/storages/app/forms/storages/admin/provider_drive_id_input_form.rb
new file mode 100644
index 00000000000..126fc7f90a2
--- /dev/null
+++ b/modules/storages/app/forms/storages/admin/provider_drive_id_input_form.rb
@@ -0,0 +1,42 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module Storages::Admin
+ class ProviderDriveIdInputForm < ApplicationForm
+ form do |storage_form|
+ storage_form.text_field(
+ name: :drive_id,
+ label: Storages::Admin::LABEL_DRIVE_ID,
+ visually_hide_label: false,
+ required: true,
+ caption: I18n.t("storages.instructions.one_drive.drive_id"),
+ placeholder: I18n.t("storages.instructions.one_drive.drive_id_placeholder")
+ )
+ end
+ end
+end
diff --git a/modules/storages/app/forms/storages/admin/provider_name_input_form.rb b/modules/storages/app/forms/storages/admin/provider_name_input_form.rb
index f8ba9f36887..a963517e713 100644
--- a/modules/storages/app/forms/storages/admin/provider_name_input_form.rb
+++ b/modules/storages/app/forms/storages/admin/provider_name_input_form.rb
@@ -33,7 +33,8 @@ module Storages::Admin
name: :name,
label: I18n.t('activerecord.attributes.storages/storage.name'),
required: true,
- caption: I18n.t('storages.instructions.name')
+ caption: I18n.t('storages.instructions.name'),
+ placeholder: I18n.t("storages.label_file_storage")
)
end
end
diff --git a/modules/storages/app/forms/storages/admin/provider_tenant_id_input_form.rb b/modules/storages/app/forms/storages/admin/provider_tenant_id_input_form.rb
new file mode 100644
index 00000000000..91296346b19
--- /dev/null
+++ b/modules/storages/app/forms/storages/admin/provider_tenant_id_input_form.rb
@@ -0,0 +1,42 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module Storages::Admin
+ class ProviderTenantIdInputForm < ApplicationForm
+ form do |storage_form|
+ storage_form.text_field(
+ name: :tenant_id,
+ label: I18n.t('activerecord.attributes.storages/storage.tenant'),
+ visually_hide_label: false,
+ required: true,
+ caption: I18n.t("storages.instructions.one_drive.tenant_id"),
+ placeholder: I18n.t("storages.instructions.one_drive.tenant_id_placeholder")
+ )
+ end
+ end
+end