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#50212]: Define OAuthClient Form flow

Kabiru Mwenja53d846a8f755
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.erb
new file mode 100644
index 00000000000..8f080491a1e
--- /dev/null
+++ b/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.html.erb
@@ -0,0 +1,12 @@
+<%=
+ primer_form_with(
+ model: oauth_client,
+ url: admin_settings_storage_oauth_client_path(storage)
+ ) do |form|
+ flex_layout do |oauth_client_row|
+ oauth_client_row.with_row do
+ render(Storages::Admin::OAuthClientForm.new(form, storage: storage))
+ end
+ end
+ end
+%>
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
new file mode 100644
index 00000000000..a5a6269cd4d
--- /dev/null
+++ b/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.rb
@@ -0,0 +1,59 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+#
+module Storages::Admin::Forms
+ class OAuthClientFormComponent < ApplicationComponent
+ include OpPrimer::ComponentHelpers
+
+ attr_reader :storage
+ alias_method :oauth_client, :model
+
+ def initialize(oauth_client:, storage:, **options)
+ super(oauth_client, **options)
+ @storage = storage
+ end
+
+ def form_url
+ if oauth_client.persisted?
+ Rails.application.routes.url_helpers.new_admin_settings_storage_oauth_client_path(storage)
+ else
+ Rails.application.routes.url_helpers.admin_settings_storage_oauth_client_path(storage)
+ end
+ end
+
+ def form_method
+ if oauth_client.persisted?
+ :patch
+ else
+ :post
+ end
+ end
+ end
+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 c1dd8d42b38..547e50ff106 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
@@ -82,18 +82,29 @@
end
component.with_row(scheme: :default) do
- grid_layout('op-storage-view--row', tag: :div, align_items: :center) do |grid|
- grid.with_area(:item, tag: :div, mr: 3) do
- concat(render(Primer::Beta::Text.new(font_weight: :semibold, mr: 1)) { I18n.t('storages.file_storage_view.nextcloud_oauth') })
- concat(configuration_check_label_for(:storage_oauth_client_configured))
- end
+ render(OpTurbo::FrameComponent.new(storage, context: :oauth_client)) do
+ grid_layout('op-storage-view--row', tag: :div, align_items: :center) do |grid|
+ grid.with_area(:item, tag: :div, mr: 3) do
+ concat(render(Primer::Beta::Text.new(font_weight: :semibold, mr: 1)) { I18n.t('storages.file_storage_view.nextcloud_oauth') })
+ concat(configuration_check_label_for(:storage_oauth_client_configured))
+ end
- grid.with_area(:description, tag: :div, color: :subtle, test_selector: 'storage-oauth-client-id-description') do
- render(Primer::Beta::Truncate.new(font_weight: :light)) { provider_oauth_client_description }
- end
+ grid.with_area(:description, tag: :div, color: :subtle, test_selector: 'storage-oauth-client-id-description') do
+ render(Primer::Beta::Truncate.new(font_weight: :light)) { provider_oauth_client_description }
+ end
- grid.with_area(:"icon-button", tag: :div, color: :subtle, mr: 3, justify_self: :end) do
- render(Primer::Beta::IconButton.new(icon: :sync, scheme: :invisible, aria: { label: I18n.t('storages.label_edit_storage') } , test_selector: 'storage-edit-button'))
+ grid.with_area(:"icon-button", tag: :div, color: :subtle, mr: 3, justify_self: :end) do
+ render(
+ Primer::Beta::IconButton.new(
+ icon: :sync,
+ tag: :a,
+ href: new_admin_settings_storage_oauth_client_path(storage),
+ scheme: :invisible,
+ aria: { label: I18n.t('storages.label_edit_storage_oauth_client') },
+ test_selector: 'storage-edit-oauth-client-button'
+ )
+ )
+ end
end
end
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 8de424d6b22..30876633272 100644
--- a/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rb
@@ -70,9 +70,12 @@ class Storages::Admin::OAuthClientsController < ApplicationController
service_result.on_success do
flash[:notice] = I18n.t(:notice_successful_create)
- if @storage.provider_type == ::Storages::Storage::PROVIDER_TYPE_NEXTCLOUD &&
- @storage.automatic_management_unspecified?
- redirect_to new_admin_settings_storage_automatically_managed_project_folders_path(@storage)
+ if @storage.provider_type_nextcloud? && @storage.automatic_management_unspecified?
+ if OpenProject::FeatureDecisions.storage_primer_design_active?
+ redirect_to edit_admin_settings_storage_path(@storage)
+ else
+ redirect_to new_admin_settings_storage_automatically_managed_project_folders_path(@storage)
+ end
else
redirect_to edit_admin_settings_storage_path(@storage)
end
diff --git a/modules/storages/app/forms/storages/admin/oauth_client_form.rb b/modules/storages/app/forms/storages/admin/oauth_client_form.rb
new file mode 100644
index 00000000000..6cacaca303d
--- /dev/null
+++ b/modules/storages/app/forms/storages/admin/oauth_client_form.rb
@@ -0,0 +1,71 @@
+#-- 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 OAuthClientForm < ApplicationForm
+ form do |oauth_client_form|
+ oauth_client_form.text_field(name: :client_id,
+ label: label_client_id,
+ required: true)
+
+ oauth_client_form.text_field(name: :client_secret,
+ label: label_client_secret,
+ required: true)
+
+ oauth_client_form.group(layout: :horizontal) do |button_group|
+ button_group.submit(name: :submit,
+ scheme: :primary,
+ label: I18n.t('storages.buttons.save_and_continue'))
+ button_group.button(name: :cancel,
+ scheme: :default,
+ tag: :a,
+ href: Rails.application.routes.url_helpers.edit_admin_settings_storage_path(@storage),
+ label: I18n.t('button_cancel'))
+ end
+ end
+
+ def initialize(storage: false)
+ super()
+ @storage = storage
+ end
+
+ private
+
+ def label_client_id
+ [label_provider_name, I18n.t('storages.label_oauth_client_id')].join(' ')
+ end
+
+ def label_client_secret
+ [label_provider_name, I18n.t('storages.label_oauth_client_secret')].join(' ')
+ end
+
+ def label_provider_name
+ I18n.t("storages.provider_types.#{@storage.short_provider_type}.name")
+ end
+ end
+end
diff --git a/modules/storages/app/views/storages/admin/oauth_clients/edit.html.erb b/modules/storages/app/views/storages/admin/oauth_clients/edit.html.erb
new file mode 100644
index 00000000000..5c5f1cd484a
--- /dev/null
+++ b/modules/storages/app/views/storages/admin/oauth_clients/edit.html.erb
@@ -0,0 +1,5 @@
+<%=
+ render(OpTurbo::FrameComponent.new(@storage, context: :oauth_client)) do
+ render(Storages::Admin::Forms::OAuthClientFormComponent.new(@storage))
+ end
+%>
diff --git a/modules/storages/app/views/storages/admin/storages/new_oauth_client.html.erb b/modules/storages/app/views/storages/admin/storages/new_oauth_client.html.erb
index f0bac1a99bd..a01eb5eeac3 100644
--- a/modules/storages/app/views/storages/admin/storages/new_oauth_client.html.erb
+++ b/modules/storages/app/views/storages/admin/storages/new_oauth_client.html.erb
@@ -28,13 +28,20 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
<% html_title t(:label_administration), t("project_module_storages"), @storage.name, "#{t("storages.provider_types.#{@storage.short_provider_type}.name")} #{t("storages.label_oauth_client_details")}" %>
-<% local_assigns[:additional_breadcrumb] = [
- link_to(@storage.name, edit_admin_settings_storage_path(@storage)),
- t("storages.label_oauth_breadcrumb.#{@storage.short_provider_type}")
-] %>
-<%= toolbar title: "#{t("storages.provider_types.#{@storage.short_provider_type}.name")} #{t("storages.label_oauth_client_details")}" %>
-
-<%= labelled_tabular_form_for @oauth_client, url: admin_settings_storage_oauth_client_path do |f| -%>
- <%= render partial: "storages/admin/storages/#{@storage.short_provider_type}/oauth_client", locals: { f: f } %>
-<% end %>
+<% if OpenProject::FeatureDecisions.storage_primer_design_active? %>
+ <%=
+ render(OpTurbo::FrameComponent.new(@storage, context: :oauth_client)) do
+ render(Storages::Admin::Forms::OAuthClientFormComponent.new(oauth_client: @oauth_client, storage: @storage))
+ end
+ %>
+<% else %>
+ <% local_assigns[:additional_breadcrumb] = [
+ link_to(@storage.name, edit_admin_settings_storage_path(@storage)),
+ t("storages.label_oauth_breadcrumb.#{@storage.short_provider_type}")
+ ] %>
+ <%= toolbar title: "#{t("storages.provider_types.#{@storage.short_provider_type}.name")} #{t("storages.label_oauth_client_details")}" %>
+ <%= labelled_tabular_form_for @oauth_client, url: admin_settings_storage_oauth_client_path do |f| -%>
+ <%= render partial: "storages/admin/storages/#{@storage.short_provider_type}/oauth_client", locals: { f: f } %>
+ <% end %>
+<% end %>
diff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.yml
index dc8b174d34d..f85cd80a4ba 100644
--- a/modules/storages/config/locales/en.yml
+++ b/modules/storages/config/locales/en.yml
@@ -188,11 +188,13 @@ en:
label_openproject_oauth_client_id: "OpenProject OAuth Client ID"
label_openproject_oauth_client_secret: "OpenProject OAuth Client Secret"
label_oauth_client_id: "OAuth Client ID"
+ label_oauth_client_secret: "OAuth Client Secret"
label_provider_type: "Provider type"
label_project_folder: "Project folder"
label_new_storage: "New storage"
label_edit_storage: "Edit storage"
label_edit_storage_host: "Edit storage host"
+ label_edit_storage_oauth_client: "Edit storage OAuth client"
label_existing_manual_folder: "Existing folder with manually managed permissions"
label_no_specific_folder: "No specific folder"
label_automatic_folder: "New folder with automatically managed permissions"