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
[#49760] separated partials out for storages administration
Andreas Pfohlb66699a0bb77
diff --git a/app/helpers/oauth_helper.rb b/app/helpers/oauth_helper.rbindex 893b9768624..6f67ae07558 100644--- a/app/helpers/oauth_helper.rb+++ b/app/helpers/oauth_helper.rb@@ -56,4 +56,8 @@ module OAuthHelpertokens = ::Doorkeeper::AccessToken.active_for(user).includes(:application)tokens.group_by(&:application)end++ def oauth_client_redirect_uri(oauth_client)+ "#{request.protocol}#{request.host_with_port}/oauth_clients/#{oauth_client.client_id}/callback"+ endenddiff --git a/app/services/oauth_clients/set_attributes_service.rb b/app/services/oauth_clients/set_attributes_service.rbindex 176f10068f1..e1827834e80 100644--- a/app/services/oauth_clients/set_attributes_service.rb+++ b/app/services/oauth_clients/set_attributes_service.rb@@ -28,4 +28,19 @@# See also: create_service.rb for commentsclass OAuthClients::SetAttributesService < BaseServices::SetAttributes+ private++ def set_attributes(params)+ super(replace_client_secret_with_nil(params))+ end++ def replace_client_secret_with_nil(params)+ cloned_param = params.clone++ if cloned_param[:client_secret] == ''+ cloned_param.merge!(client_secret: nil)+ end++ cloned_param+ endenddiff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rbindex 9949badeffa..93b0b3d6dfb 100644--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb@@ -86,14 +86,14 @@ class Storages::Admin::StoragesController < ApplicationControllerservice_result = Storages::Storages::CreateService.new(user: current_user, contract_class:).call(storage_params)+ @storage = service_result.result+ @oauth_application = oauth_application(service_result)+service_result.on_failure do@errors = service_result.errorsrender :newend- @storage = service_result.result- @oauth_application = oauth_application(service_result)-service_result.on_success docase @storage.provider_typewhen ::Storages::Storage::PROVIDER_TYPE_ONE_DRIVEdiff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rbindex 02e7608f698..796e6cfd4d0 100644--- a/modules/storages/app/models/storages/storage.rb+++ b/modules/storages/app/models/storages/storage.rb@@ -66,7 +66,7 @@ class Storages::Storage < ApplicationRecord].freeze# Uniqueness - no two storages should have the same host.- validates_uniqueness_of :host+ validates_uniqueness_of :host, allow_nil: truevalidates_uniqueness_of :name# Creates a scope of all storages, which belong to a project the user is a memberdiff --git a/modules/storages/app/services/storages/storages/set_attributes_service.rb b/modules/storages/app/services/storages/storages/set_attributes_service.rbindex a251e60fa04..3c6113d6104 100644--- a/modules/storages/app/services/storages/storages/set_attributes_service.rb+++ b/modules/storages/app/services/storages/storages/set_attributes_service.rb@@ -39,7 +39,7 @@ module Storages::Storagesprivatedef set_attributes(params)- super(params)+ super(replace_empty_host_with_nil(params))unset_nextcloud_application_credentials if nextcloud_storage?end@@ -47,6 +47,16 @@ module Storages::Storagesstorage.host = storage.host&.gsub(/\/+$/, '')end+ def replace_empty_host_with_nil(params)+ cloned_param = params.clone++ if cloned_param[:host] == ''+ cloned_param.merge!(host: nil)+ end++ cloned_param+ end+def unset_nextcloud_application_credentials# Do not overwrite if has never been set.# E.g. when setting up a new storage for the first time, passthrough, credentials are set in a later stage.diff --git a/modules/storages/app/views/storages/admin/storages/_form.html.erb b/modules/storages/app/views/storages/admin/storages/_new.html.erbsimilarity index 72%rename from modules/storages/app/views/storages/admin/storages/_form.html.erbrename to modules/storages/app/views/storages/admin/storages/_new.html.erbindex 138bbc0e72d..3efa55fff5d 100644--- a/modules/storages/app/views/storages/admin/storages/_form.html.erb+++ b/modules/storages/app/views/storages/admin/storages/_new.html.erb@@ -24,7 +24,6 @@ along with this program; if not, write to the Free SoftwareFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.See COPYRIGHT and LICENSE files for more details.-++#%><% content_controller 'storages--storage-form',@@ -39,27 +38,18 @@ See COPYRIGHT and LICENSE files for more details.<fieldset class="form--fieldset" data-storages--storage-form-target="fieldset"><legend class="form--fieldset-legend"><%= I18n.t(:label_general) %></legend><div class="form--field -required">- <% if action_name == 'new' || action_name == 'create' %>- <%= f.hidden_field :provider_type %>- <%= f.select :provider_type,- ::Storages::Storage::PROVIDER_TYPES.map { |provider_type| [I18n.t("storages.provider_types.#{::Storages::Storage.shorten_provider_type(provider_type)}.name"), provider_type] },- {- selected: ::Storages::Storage::PROVIDER_TYPE_NEXTCLOUD,- container_class: '-slim'- },- data: {- 'storages--storage-form-target': 'selectProviderType'- }- %>- <span class="form--field-instructions"><%= t('storages.instructions.type') %> <%= t('storages.instructions.type_link_text') %></span>- <% elsif action_name == 'edit' %>- <%= f.label :provider_type, class: "form--label" do %>- <%= t(:"storages.label_provider_type") %>- <% end %>- <div class="form--field-container -horizontal">- <span><%= I18n.t("storages.provider_types.#{@storage.short_provider_type}.name") %></span>- </div>- <% end %>+ <%= f.hidden_field :provider_type %>+ <%= f.select :provider_type,+ ::Storages::Storage::PROVIDER_TYPES.map { |provider_type| [I18n.t("storages.provider_types.#{::Storages::Storage.shorten_provider_type(provider_type)}.name"), provider_type] },+ {+ selected: ::Storages::Storage::PROVIDER_TYPE_NEXTCLOUD,+ container_class: '-slim'+ },+ data: {+ 'storages--storage-form-target': 'selectProviderType'+ }+ %>+ <span class="form--field-instructions"><%= t('storages.instructions.type') %> <%= t('storages.instructions.type_link_text') %></span></div><div class="form--field -required"><%= f.text_field :name,diff --git a/modules/storages/app/views/storages/admin/storages/edit.html.erb b/modules/storages/app/views/storages/admin/storages/edit.html.erbindex b63f25036da..4b443fc159d 100644--- a/modules/storages/app/views/storages/admin/storages/edit.html.erb+++ b/modules/storages/app/views/storages/admin/storages/edit.html.erb@@ -1,6 +1,31 @@-<!-- Standard Ruby view, please see the controller for comments -->+<%#-- 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.+++#%>-<!-- We want to hide client_secret from the user while allowing the user to edit the other attributes --><% html_title t(:label_administration), t("project_module_storages"), t('label_edit_x', x: @object.name) %><% local_assigns[:additional_breadcrumb] = @storage.name %><%= toolbar title: t('label_edit_x', x: @object.name) %>@@ -8,7 +33,11 @@<%= render(::Storages::Admin::ConfigurationChecksComponent.new(storage: @storage)) %><%= labelled_tabular_form_for @storage, url: admin_settings_storage_path(@storage), as: :storages_storage do |f| -%>- <%= render partial: 'form', locals: { f: f } %>+ <% if @storage.provider_type_nextcloud? %>+ <%= render partial: 'storages/admin/storages/nextcloud/edit', locals: { f: f } %>+ <% else %>+ <%= render partial: 'storages/admin/storages/one_drive/edit', locals: { f: f } %>+ <% end %><%= styled_button_tag t(:button_save), class: "-highlight -with-icon icon-checkmark" %><% end %>@@ -29,27 +58,13 @@<% end %><% end %>-<%= render(AttributeGroups::AttributeGroupComponent.new) do |component| %>- <% component.with_header(title: "#{t("storages.provider_types.#{@storage.short_provider_type}.name")} #{t(:'storages.label_oauth_client_details')}") %>-- <% if @storage.oauth_client %>- <% component.with_attributes([- { key: "#{t("storages.provider_types.#{@storage.short_provider_type}.name")} #{Storages::Admin::LABEL_OAUTH_CLIENT_ID}",- value: @storage.oauth_client.client_id },- { key: "#{t("storages.provider_types.#{@storage.short_provider_type}.name")} #{Storages::Admin::LABEL_OAUTH_CLIENT_SECRET}",- value: short_secret(@storage.oauth_client.client_secret) },- ]) %>-- <%= link_to(t("storages.buttons.replace_provider_type_oauth", provider_type: t("storages.provider_types.#{@storage.short_provider_type}.name")),- new_admin_settings_storage_oauth_client_path(@storage),- data: { confirm: t(:'storages.confirm_replace_oauth_client') },- class: 'button -with-icon icon-reload') %>- <% else %>- <%= link_to(t("js.label_create"), new_admin_settings_storage_oauth_client_path(@storage), class: 'button -with-icon icon-add') %>- <% end %>+<% if @storage.provider_type_nextcloud? %>+ <%= render partial: 'storages/admin/storages/nextcloud/oauth_client_section' %>+<% elsif @storage.provider_type_one_drive? %>+ <%= render partial: 'storages/admin/storages/one_drive/oauth_client_section' %><% end %>-<% if @storage.provider_type == Storages::Storage::PROVIDER_TYPE_NEXTCLOUD %>+<% if @storage.provider_type_nextcloud? %><%= render(AttributeGroups::AttributeGroupComponent.new) do |component| %><% component.with_header(title: t("storages.page_titles.managed_project_folders.title")) %>diff --git a/modules/storages/app/views/storages/admin/storages/new.html.erb b/modules/storages/app/views/storages/admin/storages/new.html.erbindex ebf85cb8874..b575b763bc4 100644--- a/modules/storages/app/views/storages/admin/storages/new.html.erb+++ b/modules/storages/app/views/storages/admin/storages/new.html.erb@@ -4,7 +4,7 @@<%= toolbar title: t("storages.label_new_storage") %><%= labelled_tabular_form_for @storage, url: admin_settings_storages_path(@storage), as: :storages_storage do |f| -%>- <%= render partial: 'form', locals: { f: f } %>+ <%= render partial: 'new', locals: { f: f } %><% if @storage.oauth_client %><%= styled_button_tag t(:button_save), class: "-highlight -with-icon icon-checkmark" %><% else %>diff --git a/modules/storages/app/views/storages/admin/storages/nextcloud/_edit.html.erb b/modules/storages/app/views/storages/admin/storages/nextcloud/_edit.html.erbnew file mode 100644index 00000000000..5418e500dec--- /dev/null+++ b/modules/storages/app/views/storages/admin/storages/nextcloud/_edit.html.erb@@ -0,0 +1,58 @@+<%#-- 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.+++#%>++<%= error_messages_for_contract @storage, @errors %>++<fieldset class="form--fieldset">+ <legend class="form--fieldset-legend"><%= I18n.t(:label_general) %></legend>+ <div class="form--field -required">+ <%= f.label :provider_type, class: "form--label" do %>+ <%= t(:"storages.label_provider_type") %>+ <% end %>+ <div class="form--field-container -horizontal">+ <span><%= I18n.t("storages.provider_types.#{@storage.short_provider_type}.name") %></span>+ </div>+ </div>+ <div class="form--field -required">+ <%= f.text_field :name,+ required: true,+ placeholder: I18n.t("storages.provider_types.#{@storage.short_provider_type}.name_placeholder"),+ container_class: '-slim' %>+ <span class="form--field-instructions"><%= t('storages.instructions.name') %></span>+ </div>+ <div class="form--field -required" data-storages--storage-form-target="storageUrl">+ <%= f.text_field :host,+ label: t('storages.label_host'),+ type: :url,+ required: true,+ pattern: ".{1,255}",+ placeholder: "https://my-file-storage.com",+ container_class: '-wide' %>+ <span class="form--field-instructions"><%= t('storages.instructions.host') %></span>+ </div>+</fieldset>diff --git a/modules/storages/app/views/storages/admin/storages/nextcloud/_oauth_client_section.html.erb b/modules/storages/app/views/storages/admin/storages/nextcloud/_oauth_client_section.html.erbnew file mode 100644index 00000000000..19286720a15--- /dev/null+++ b/modules/storages/app/views/storages/admin/storages/nextcloud/_oauth_client_section.html.erb@@ -0,0 +1,47 @@+<%#-- 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.+++#%>++<%= render(AttributeGroups::AttributeGroupComponent.new) do |component| %>+ <% component.with_header(title: "#{t("storages.provider_types.#{@storage.short_provider_type}.name")} #{t(:'storages.label_oauth_client_details')}") %>++ <% if @storage.oauth_client %>+ <% component.with_attributes([+ { key: "#{t("storages.provider_types.#{@storage.short_provider_type}.name")} #{Storages::Admin::LABEL_OAUTH_CLIENT_ID}",+ value: @storage.oauth_client.client_id },+ { key: "#{t("storages.provider_types.#{@storage.short_provider_type}.name")} #{Storages::Admin::LABEL_OAUTH_CLIENT_SECRET}",+ value: short_secret(@storage.oauth_client.client_secret) },+ ]) %>++ <%= link_to(t("storages.buttons.replace_provider_type_oauth", provider_type: t("storages.provider_types.#{@storage.short_provider_type}.name")),+ new_admin_settings_storage_oauth_client_path(@storage),+ data: { confirm: t(:'storages.confirm_replace_oauth_client') },+ class: 'button -with-icon icon-reload') %>+ <% else %>+ <%= link_to(t("js.label_create"), new_admin_settings_storage_oauth_client_path(@storage), class: 'button -with-icon icon-add') %>+ <% end %>+<% end %>diff --git a/modules/storages/app/views/storages/admin/storages/one_drive/_edit.html.erb b/modules/storages/app/views/storages/admin/storages/one_drive/_edit.html.erbnew file mode 100644index 00000000000..3dc015426e8--- /dev/null+++ b/modules/storages/app/views/storages/admin/storages/one_drive/_edit.html.erb@@ -0,0 +1,48 @@+<%#-- 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.+++#%>++<%= error_messages_for_contract @storage, @errors %>++<fieldset class="form--fieldset">+ <legend class="form--fieldset-legend"><%= I18n.t(:label_general) %></legend>+ <div class="form--field -required">+ <%= f.label :provider_type, class: "form--label" do %>+ <%= t(:"storages.label_provider_type") %>+ <% end %>+ <div class="form--field-container -horizontal">+ <span><%= I18n.t("storages.provider_types.#{@storage.short_provider_type}.name") %></span>+ </div>+ </div>+ <div class="form--field -required">+ <%= f.text_field :name,+ required: true,+ placeholder: I18n.t("storages.provider_types.#{@storage.short_provider_type}.name_placeholder"),+ container_class: '-slim' %>+ <span class="form--field-instructions"><%= t('storages.instructions.name') %></span>+ </div>+</fieldset>diff --git a/modules/storages/app/views/storages/admin/storages/one_drive/_oauth_client_section.html.erb b/modules/storages/app/views/storages/admin/storages/one_drive/_oauth_client_section.html.erbnew file mode 100644index 00000000000..87c1510955b--- /dev/null+++ b/modules/storages/app/views/storages/admin/storages/one_drive/_oauth_client_section.html.erb@@ -0,0 +1,51 @@+<%#-- 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.+++#%>++<%= render(AttributeGroups::AttributeGroupComponent.new) do |component| %>+ <% component.with_header(title: "#{t("storages.provider_types.#{@storage.short_provider_type}.name")} #{t(:'storages.label_oauth_client_details')}") %>++ <% if @storage.oauth_client %>+ <% attributes = [{ key: "#{t("storages.provider_types.#{@storage.short_provider_type}.name")} #{Storages::Admin::LABEL_OAUTH_CLIENT_ID}",+ value: @storage.oauth_client.client_id }] %>+ <% if @storage.oauth_client.client_secret.present? %>+ <% attributes.append({ key: "#{t("storages.provider_types.#{@storage.short_provider_type}.name")} #{Storages::Admin::LABEL_OAUTH_CLIENT_SECRET}",+ value: short_secret(@storage.oauth_client.client_secret) }) %>+ <% end %>+ <% attributes.append({ key: "#{t("storages.provider_types.#{@storage.short_provider_type}.name")} #{Storages::Admin::LABEL_OAUTH_REDIRECT_URI}",+ value: oauth_client_redirect_uri(@storage.oauth_client) }) %>++ <% component.with_attributes(attributes) %>++ <%= link_to(t("storages.buttons.replace_provider_type_oauth", provider_type: t("storages.provider_types.#{@storage.short_provider_type}.name")),+ new_admin_settings_storage_oauth_client_path(@storage),+ data: { confirm: t(:'storages.confirm_replace_oauth_client') },+ class: 'button -with-icon icon-reload') %>+ <% else %>+ <%= link_to(t("js.label_create"), new_admin_settings_storage_oauth_client_path(@storage), class: 'button -with-icon icon-add') %>+ <% end %>+<% end %>diff --git a/modules/storages/app/views/storages/admin/storages/show_oauth_application.html.erb b/modules/storages/app/views/storages/admin/storages/show_oauth_application.html.erbindex c8c66f15027..144fe75626e 100644--- a/modules/storages/app/views/storages/admin/storages/show_oauth_application.html.erb+++ b/modules/storages/app/views/storages/admin/storages/show_oauth_application.html.erb@@ -83,9 +83,9 @@</div></fieldset>- <% if @object.oauth_client %>- <%= link_to t("storages.buttons.done_continue_setup"), edit_admin_settings_storage_path(@object), class: "-highlight -with-icon icon-checkmark button" %>+ <% if @storage.oauth_client %>+ <%= link_to t("storages.buttons.done_continue_setup"), edit_admin_settings_storage_path(@storage), class: "-highlight -with-icon icon-checkmark button" %><% else %>- <%= link_to t("storages.buttons.done_continue_setup"), new_admin_settings_storage_oauth_client_path(@object), class: "-highlight -with-icon icon-checkmark button" %>+ <%= link_to t("storages.buttons.done_continue_setup"), new_admin_settings_storage_oauth_client_path(@storage), class: "-highlight -with-icon icon-checkmark button" %><% end %><% end %>