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
feat[#50212]: Define edit provider host form with validation
Kabiru Mwenjac9488fda028c
diff --git a/modules/storages/app/components/storages/admin/storage_general_info_form_component.html.erb b/modules/storages/app/components/storages/admin/storage_general_info_form_component.html.erbindex 9e2df3bae6d..87f2906f4b1 100644--- a/modules/storages/app/components/storages/admin/storage_general_info_form_component.html.erb+++ b/modules/storages/app/components/storages/admin/storage_general_info_form_component.html.erb@@ -5,16 +5,21 @@method: :patch) do |form|flex_layout do |general_info_row|- general_info_row.with_column do+ general_info_row.with_row(mb: 3) dorender(Storages::Admin::ProviderTypeSelectForm.new(form))end- general_info_row.with_column do- render(Primer::Beta::Button.new(scheme: :primary, type: :submit)) { I18n.t('storages.buttons.save_and_continue') }+ general_info_row.with_row(mb: 3) do+ render(Storages::Admin::StorageNameInputForm.new(form))end- general_info_row.with_column do- render(Primer::Beta::Button.new(scheme: :default, tag: :a, href: edit_admin_settings_storage_path(storage))) { I18n.t('button_cancel') }+ general_info_row.with_row(mb: 3) do+ render(Storages::Admin::StorageHostInputForm.new(form))+ end++ general_info_row.with_row do+ concat(render(Primer::Beta::Button.new(scheme: :primary, type: :submit)) { I18n.t('storages.buttons.save_and_continue') })+ concat(render(Primer::Beta::Button.new(scheme: :default, tag: :a, href: edit_admin_settings_storage_path(storage))) { I18n.t('button_cancel') })endendenddiff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rbindex 2d52df93f34..8a7f4d80f18 100644--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb@@ -120,6 +120,9 @@ class Storages::Admin::StoragesController < ApplicationControllerif service_result.success?flash[:notice] = I18n.t(:notice_successful_update)redirect_to edit_admin_settings_storage_path(@storage)+ elsif OpenProject::FeatureDecisions.storage_primer_design_active?+ @storage = ServiceResultErrorsPresenter.new(service_result)+ render :edit_host_name_configurationelse@errors = service_result.errorsrender :edit@@ -181,7 +184,31 @@ class Storages::Admin::StoragesController < ApplicationController# update parameters are correctly set.def permitted_storage_paramsparams- .require(:storages_storage)+ .require(storage_provider_parameter_name).permit('name', 'provider_type', 'host', 'oauth_client_id', 'oauth_client_secret')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 OpenProject::FeatureDecisions.storage_primer_design_active?+ :storages_nextcloud_storage+ else+ :storages_storage+ end+ end++ class ServiceResultErrorsPresenter < SimpleDelegator+ attr_reader :service_result++ def initialize(service_result)+ super(service_result.result)+ @service_result = service_result+ end++ delegate :errors, to: :service_result+ endenddiff --git a/modules/storages/app/forms/storages/admin/provider_type_select_form.rb b/modules/storages/app/forms/storages/admin/provider_type_select_form.rbindex 2520f09b9d3..18142e8a651 100644--- a/modules/storages/app/forms/storages/admin/provider_type_select_form.rb+++ b/modules/storages/app/forms/storages/admin/provider_type_select_form.rb@@ -32,7 +32,7 @@ module Storages::Adminselect_form.select_list(name: :provider_type,label: I18n.t('activerecord.attributes.storages/storage.provider_type'),- caption: I18n.t('storages.forms.general_information.provider_type_select_form.nextcloud_caption'),+ caption: I18n.t('storages.instructions.provider_type', type_link_text: "“Integration OpenProject”"),include_blank: false,required: true) do |storage_provider_list|diff --git a/modules/storages/app/forms/storages/admin/storage_host_input_form.rb b/modules/storages/app/forms/storages/admin/storage_host_input_form.rbnew file mode 100644index 00000000000..c3b80059e10--- /dev/null+++ b/modules/storages/app/forms/storages/admin/storage_host_input_form.rb@@ -0,0 +1,41 @@+#-- 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 StorageHostInputForm < ApplicationForm+ form do |input_form|+ input_form.text_field(+ name: :host,+ label: I18n.t('activerecord.attributes.storages/storage.host'),+ visually_hide_label: false,+ required: true,+ caption: I18n.t('storages.instructions.host')+ )+ end+ end+enddiff --git a/modules/storages/app/forms/storages/admin/storage_name_input_form.rb b/modules/storages/app/forms/storages/admin/storage_name_input_form.rbnew file mode 100644index 00000000000..05438568f89--- /dev/null+++ b/modules/storages/app/forms/storages/admin/storage_name_input_form.rb@@ -0,0 +1,40 @@+#-- 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 StorageNameInputForm < ApplicationForm+ form do |input_form|+ input_form.text_field(+ name: :name,+ label: I18n.t('activerecord.attributes.storages/storage.name'),+ required: true,+ caption: I18n.t('storages.instructions.name')+ )+ end+ end+enddiff --git a/modules/storages/app/views/storages/admin/storages/edit_host_name_configuration.html.erb b/modules/storages/app/views/storages/admin/storages/edit_host_name_configuration.html.erbindex 3e3fac85837..313eba70b29 100644--- a/modules/storages/app/views/storages/admin/storages/edit_host_name_configuration.html.erb+++ b/modules/storages/app/views/storages/admin/storages/edit_host_name_configuration.html.erb@@ -1,5 +1,5 @@<div>- <h1>Edit Host Name Configuration</h1>+ <h1><%= t('label_edit_x', x: @storage.name) %></h1><turbo-frame id="<%= dom_id(@storage) %>"><%= render(Storages::Admin::StorageGeneralInfoFormComponent.new(@storage)) %>diff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.ymlindex 8ce77ffbad9..dd6a8cd818d 100644--- a/modules/storages/config/locales/en.yml+++ b/modules/storages/config/locales/en.yml@@ -29,6 +29,7 @@ en:name: "Name"creator: "Creator"provider_type: "Provider type"+ host: "Host"storages/file_link:origin_id: "Origin Id"@@ -76,11 +77,6 @@ en:save_and_complete_setup: "Save and complete setup"select_folder: "Select folder"configure: "Configure"- forms:- general_information:- provider_type_select_form:- nextcloud_caption: >- Please make sure you have administration privileges in your Nextcloud instance and the application “Integration OpenProject” is installed before doing the setup.file_storage_view:general_information: "General information"oauth_applications: "OAuth applications"@@ -107,6 +103,7 @@ en:title: "Members connection status"subtitle: "Check the connection status for the storage %{storage_name_link} of all project members."instructions:+ provider_type: "Please make sure you have administration privileges in your Nextcloud instance and the application %{type_link_text} is installed before doing the setup."type: "Please make sure you have administration privileges in your Nextcloud instance and have the following application installed before doing the setup:"type_link_text: "“Integration OpenProject”"name: "Give your storage a name so that users can differentiate between multiple storages."