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

[#47629] Prepare the database to store the application password and managed folder flag.

Pavel Balashov5caabe1a9d37
diff --git a/app/controllers/oauth_clients_controller.rb b/app/controllers/oauth_clients_controller.rb
index e4534cfbddf..b4edbe69364 100644
--- a/app/controllers/oauth_clients_controller.rb
+++ b/app/controllers/oauth_clients_controller.rb
@@ -157,9 +157,7 @@ class OAuthClientsController < ApplicationController
end
def nextcloud?
- @oauth_client&.integration && \
- @oauth_client.integration.is_a?(::Storages::Storage) && \
- @oauth_client.integration.provider_type == 'nextcloud'
+ @oauth_client&.integration&.provider_type == ::Storages::Storage::PROVIDER_TYPE_NEXTCLOUD
end
def get_redirect_uri
diff --git a/app/services/oauth_clients/create_service.rb b/app/services/oauth_clients/create_service.rb
index 64e34bb91e8..35d75686e6c 100644
--- a/app/services/oauth_clients/create_service.rb
+++ b/app/services/oauth_clients/create_service.rb
@@ -31,7 +31,6 @@
# Purpose: create and persist a Storages::Storage record
# Used by: Storages::Admin::StoragesController#create, could also be used by the
# API in the future.
-# Reference: https://www.openproject.org/docs/development/concepts/contracted-services/
# The comments here are also valid for the other *_service.rb files
module OAuthClients
class CreateService < ::BaseServices::Create
diff --git a/db/migrate/20230420063148_add_provider_fields_to_storages.rb b/db/migrate/20230420063148_add_provider_fields_to_storages.rb
new file mode 100644
index 00000000000..525c2a5c2cd
--- /dev/null
+++ b/db/migrate/20230420063148_add_provider_fields_to_storages.rb
@@ -0,0 +1,32 @@
+# 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.
+#++
+
+class AddProviderFieldsToStorages < ActiveRecord::Migration[7.0]
+ def change
+ add_column :storages, :provider_fields, :jsonb, null: false, default: '{}'
+ end
+end
diff --git a/db/migrate/20230420071113_migrate_storages_to_use_provider_type_as_sti_column.rb b/db/migrate/20230420071113_migrate_storages_to_use_provider_type_as_sti_column.rb
new file mode 100644
index 00000000000..7cbbb09b63b
--- /dev/null
+++ b/db/migrate/20230420071113_migrate_storages_to_use_provider_type_as_sti_column.rb
@@ -0,0 +1,36 @@
+# 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.
+#++
+
+class MigrateStoragesToUseProviderTypeAsStiColumn < ActiveRecord::Migration[7.0]
+ def up
+ Storages::Storage.update_all("provider_type = 'Storages::NextcloudStorage'")
+ end
+
+ def down
+ Storages::Storage.update_all("provider_type = 'nextcloud'")
+ end
+end
diff --git a/modules/storages/app/components/storages/projects_storages/row_component.rb b/modules/storages/app/components/storages/projects_storages/row_component.rb
index 08e38dc38cc..cf82d219aeb 100644
--- a/modules/storages/app/components/storages/projects_storages/row_component.rb
+++ b/modules/storages/app/components/storages/projects_storages/row_component.rb
@@ -44,7 +44,7 @@ module Storages::ProjectsStorages
end
def provider_type
- project_storage.storage.provider_type
+ project_storage.storage.short_provider_type
end
def creator
diff --git a/modules/storages/app/contracts/storages/storages/base_contract.rb b/modules/storages/app/contracts/storages/storages/base_contract.rb
index a422371e658..275ff14f7d9 100644
--- a/modules/storages/app/contracts/storages/storages/base_contract.rb
+++ b/modules/storages/app/contracts/storages/storages/base_contract.rb
@@ -44,7 +44,7 @@ module Storages::Storages
validates :name, presence: true, length: { maximum: 255 }
attribute :provider_type
- validates :provider_type, inclusion: { in: ->(*) { Storages::Storage::PROVIDER_TYPES } }
+ validates :provider_type, inclusion: { in: Storages::Storage::PROVIDER_TYPES }
attribute :host
validates :host, url: { message: I18n.t('activerecord.errors.messages.invalid_url') }, length: { maximum: 255 }
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 a3287d29354..71b3e8b6984 100644
--- a/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rb
@@ -54,7 +54,6 @@ class Storages::Admin::OAuthClientsController < ApplicationController
# Actually create a OAuthClient object.
# Use service pattern to create a new OAuthClient
- # See also: https://www.openproject.org/docs/development/concepts/contracted-services/
# Called by: Global app/config/routes.rb to serve Web page
def create
service_result = ::OAuthClients::CreateService.new(user: User.current)
diff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rb
index 7454e951dbd..facb3a52b12 100644
--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb
@@ -63,11 +63,10 @@ class Storages::Admin::StoragesController < ApplicationController
def new
# Set default parameters using a "service".
# See also: storages/services/storages/storages/set_attributes_services.rb
- # See also: https://www.openproject.org/docs/development/concepts/contracted-services/
# That service inherits from ::BaseServices::SetAttributes
@object = ::Storages::Storages::SetAttributesService
.new(user: current_user,
- model: Storages::Storage.new(provider_type: Storages::Storage::PROVIDER_TYPE_NEXTCLOUD),
+ model: Storages::NextcloudStorage.new,
contract_class: EmptyContract)
.call
.result
@@ -77,7 +76,6 @@ class Storages::Admin::StoragesController < ApplicationController
# Overwrite the creator_id with the current_user. Is this this pattern always used?
# Use service pattern to create a new Storage
# See also: storages/services/storages/storages/create_service.rb
- # See also: https://www.openproject.org/docs/development/concepts/contracted-services/
# Called by: Global app/config/routes.rb to serve Web page
def create
service_result = Storages::Storages::CreateService.new(user: current_user).call(permitted_storage_params)
@@ -100,7 +98,6 @@ class Storages::Admin::StoragesController < ApplicationController
# Update is similar to create above
# See also: create above
- # See also: https://www.openproject.org/docs/development/concepts/contracted-services/
# Called by: Global app/config/routes.rb to serve Web page
def update
service_result = ::Storages::Storages::UpdateService
diff --git a/modules/storages/app/models/storages/nextcloud_storage.rb b/modules/storages/app/models/storages/nextcloud_storage.rb
new file mode 100644
index 00000000000..9fca69cb03d
--- /dev/null
+++ b/modules/storages/app/models/storages/nextcloud_storage.rb
@@ -0,0 +1,11 @@
+class Storages::NextcloudStorage < Storages::Storage
+ store :provider_fields, accessors: %i[username password managed_folders]
+
+ def managed_folders=(value)
+ super(!!value)
+ end
+
+ def managed_folders
+ !!super
+ end
+end
diff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rb
index 7ab73b56857..a31dabb5bff 100644
--- a/modules/storages/app/models/storages/storage.rb
+++ b/modules/storages/app/models/storages/storage.rb
@@ -37,6 +37,8 @@
# Additional attributes and constraints are defined in
# db/migrate/20220113144323_create_storage.rb "migration".
class Storages::Storage < ApplicationRecord
+ self.inheritance_column = :provider_type
+
# One Storage can have multiple FileLinks, representing external files.
#
# FileLink deletion is done:
@@ -57,7 +59,7 @@ class Storages::Storage < ApplicationRecord
has_one :oauth_application, class_name: '::Doorkeeper::Application', as: :integration, dependent: :destroy
PROVIDER_TYPES = [
- PROVIDER_TYPE_NEXTCLOUD = 'nextcloud'.freeze
+ PROVIDER_TYPE_NEXTCLOUD = 'Storages::NextcloudStorage'.freeze
].freeze
# Uniqueness - no two storages should have the same host.
@@ -77,4 +79,12 @@ class Storages::Storage < ApplicationRecord
)
end
}
+
+ def self.shorten_provider_type(provider_type)
+ provider_type.demodulize[0..-8].downcase
+ end
+
+ def short_provider_type
+ @short_provider_type ||= self.class.shorten_provider_type(provider_type)
+ end
end
diff --git a/modules/storages/app/services/storages/oauth_applications/create_service.rb b/modules/storages/app/services/storages/oauth_applications/create_service.rb
index 8d6f92f987b..03e3716cb01 100644
--- a/modules/storages/app/services/storages/oauth_applications/create_service.rb
+++ b/modules/storages/app/services/storages/oauth_applications/create_service.rb
@@ -31,7 +31,6 @@
# Purpose: create and persist a Storages::Storage record
# Used by: Storages::Admin::StoragesController#create, could also be used by the
# API in the future.
-# Reference: https://www.openproject.org/docs/development/concepts/contracted-services/
# The comments here are also valid for the other *_service.rb files
module Storages::OAuthApplications
class CreateService
@@ -46,7 +45,7 @@ module Storages::OAuthApplications
::OAuth::PersistApplicationService
.new(::Doorkeeper::Application.new, user:)
.call({
- name: "#{storage.name} (#{I18n.t("storages.provider_types.#{storage.provider_type}.name")})",
+ name: "#{storage.name} (#{I18n.t("storages.provider_types.#{storage.short_provider_type}.name")})",
redirect_uri: File.join(storage.host, "index.php/apps/integration_openproject/oauth-redirect"),
scopes: 'api_v3',
confidential: true,
diff --git a/modules/storages/app/services/storages/storages/create_service.rb b/modules/storages/app/services/storages/storages/create_service.rb
index 387fe0dc21d..03c599007f5 100644
--- a/modules/storages/app/services/storages/storages/create_service.rb
+++ b/modules/storages/app/services/storages/storages/create_service.rb
@@ -31,7 +31,6 @@
# Purpose: create and persist a Storages::Storage record
# Used by: Storages::Admin::StoragesController#create, could also be used by the
# API in the future.
-# Reference: https://www.openproject.org/docs/development/concepts/contracted-services/
# The comments here are also valid for the other *_service.rb files
module Storages::Storages
class CreateService < ::BaseServices::Create
@@ -43,7 +42,7 @@ module Storages::Storages
storage = service_call.result
# Automatically create an OAuthApplication object for the Nextcloud storage
# using values from storage (particularly :host) as defaults
- if storage.provider_type == 'nextcloud'
+ if storage.provider_type == Storages::Storage::PROVIDER_TYPE_NEXTCLOUD
persist_service_result = ::Storages::OAuthApplications::CreateService.new(storage:, user:).call
storage.oauth_application = persist_service_result.result if persist_service_result.success?
service_call.add_dependent!(persist_service_result)
diff --git a/modules/storages/app/services/storages/storages/set_attributes_service.rb b/modules/storages/app/services/storages/storages/set_attributes_service.rb
index 45c58490a2e..f7d2a73b2b1 100644
--- a/modules/storages/app/services/storages/storages/set_attributes_service.rb
+++ b/modules/storages/app/services/storages/storages/set_attributes_service.rb
@@ -47,7 +47,7 @@ module Storages::Storages
end
def derive_default_storage_name
- prefix = I18n.t("storages.provider_types.#{storage.provider_type}.default_name")
+ prefix = I18n.t("storages.provider_types.#{storage.short_provider_type}.default_name")
last_id = Storages::Storage.where("name like ?", "#{prefix}%").maximum(:id)
return prefix if last_id.nil?
diff --git a/modules/storages/app/services/storages/storages/update_service.rb b/modules/storages/app/services/storages/storages/update_service.rb
index 3b55135b49e..d6bd01ed1c1 100644
--- a/modules/storages/app/services/storages/storages/update_service.rb
+++ b/modules/storages/app/services/storages/storages/update_service.rb
@@ -35,12 +35,12 @@ module Storages::Storages
super(service_call)
storage = service_call.result
- if storage.provider_type == 'nextcloud'
+ if storage.provider_type == ::Storages::Storage::PROVIDER_TYPE_NEXTCLOUD
application = storage.oauth_application
persist_service_result = ::OAuth::PersistApplicationService
.new(application, user:)
.call({
- name: "#{storage.name} (#{I18n.t("storages.provider_types.#{storage.provider_type}.name")})",
+ name: "#{storage.name} (#{I18n.t("storages.provider_types.#{storage.short_provider_type}.name")})",
redirect_uri: File.join(storage.host, "index.php/apps/integration_openproject/oauth-redirect")
})
service_call.add_dependent!(persist_service_result)
diff --git a/modules/storages/app/views/storages/admin/storages/_form.html.erb b/modules/storages/app/views/storages/admin/storages/_form.html.erb
index 47d8fa1c825..37bd6121822 100644
--- a/modules/storages/app/views/storages/admin/storages/_form.html.erb
+++ b/modules/storages/app/views/storages/admin/storages/_form.html.erb
@@ -35,7 +35,7 @@ See COPYRIGHT and LICENSE files for more details.
<div class="form--field -required">
<%= f.hidden_field :provider_type %>
<%= f.select :provider_type,
- ::Storages::Storage::PROVIDER_TYPES.map { |provider_type| [I18n.t("storages.provider_types.#{provider_type}.name"), 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'
@@ -48,7 +48,7 @@ See COPYRIGHT and LICENSE files for more details.
<div class="form--field -required">
<%= f.text_field :name,
required: true,
- placeholder: I18n.t('storages.provider_types.nextcloud.name_placeholder'),
+ placeholder: I18n.t("storages.provider_types.#{@object.short_provider_type}.name_placeholder"),
container_class: '-slim' %>
<span class="form--field-instructions"><%= t('storages.instructions.name') %></span>
</div>
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 b6a4a6be468..a4d300fc242 100644
--- a/modules/storages/app/views/storages/admin/storages/edit.html.erb
+++ b/modules/storages/app/views/storages/admin/storages/edit.html.erb
@@ -9,7 +9,7 @@
<% local_assigns[:additional_breadcrumb] = @object.name %>
<%= toolbar title: t('label_edit_x', x: @object.name) %>
-<%= labelled_tabular_form_for @object, url: admin_settings_storage_path(@object) do |f| -%>
+<%= labelled_tabular_form_for @object, url: admin_settings_storage_path(@object), as: :storages_storage do |f| -%>
<%= render partial: 'form', locals: { f: f } %>
<%= styled_button_tag t(:button_save), class: "-highlight -with-icon icon-checkmark" %>
<% end %>
@@ -41,23 +41,23 @@
<% end %>
<fieldset class="form--fieldset">
- <legend class="form--fieldset-legend"><%= t("storages.provider_types.#{@object.provider_type}.name") %> <%= t(:'storages.label_oauth_client_details') %></legend>
+ <legend class="form--fieldset-legend"><%= t("storages.provider_types.#{@object.short_provider_type}.name") %> <%= t(:'storages.label_oauth_client_details') %></legend>
<% if @object.oauth_client %>
<div class="attributes-key-value">
- <div class="attributes-key-value--key"><%= t("storages.provider_types.#{@object.provider_type}.name") %> <%= Storages::Admin::LABEL_OAUTH_CLIENT_ID %></div>
+ <div class="attributes-key-value--key"><%= t("storages.provider_types.#{@object.short_provider_type}.name") %> <%= Storages::Admin::LABEL_OAUTH_CLIENT_ID %></div>
<div class="attributes-key-value--value-container">
<div class="attributes-key-value--value -text">
<span><%= @object.oauth_client.client_id %></span>
</div>
</div>
- <div class="attributes-key-value--key"><%= t("storages.provider_types.#{@object.provider_type}.name") %> <%= Storages::Admin::LABEL_OAUTH_CLIENT_SECRET %></div>
+ <div class="attributes-key-value--key"><%= t("storages.provider_types.#{@object.short_provider_type}.name") %> <%= Storages::Admin::LABEL_OAUTH_CLIENT_SECRET %></div>
<div class="attributes-key-value--value-container">
<div class="attributes-key-value--value -text">
<span><%= short_secret(@object.oauth_client.client_secret) %></span>
</div>
</div>
</div>
- <%= link_to(t("storages.buttons.replace_provider_type_oauth", provider_type: t("storages.provider_types.#{@object.provider_type}.name")),
+ <%= link_to(t("storages.buttons.replace_provider_type_oauth", provider_type: t("storages.provider_types.#{@object.short_provider_type}.name")),
new_admin_settings_storage_oauth_client_path(@object),
data: { confirm: t(:'storages.confirm_replace_oauth_client') },
class: 'button -with-icon icon-reload') %>
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 a43acecf182..067b742f24a 100644
--- a/modules/storages/app/views/storages/admin/storages/new.html.erb
+++ b/modules/storages/app/views/storages/admin/storages/new.html.erb
@@ -3,7 +3,7 @@
<% local_assigns[:additional_breadcrumb] = t('storages.label_new_storage') %>
<%= toolbar title: t("storages.label_new_storage") %>
-<%= labelled_tabular_form_for @object, url: admin_settings_storages_path(@object) do |f| -%>
+<%= labelled_tabular_form_for @object, url: admin_settings_storages_path(@object), as: :storages_storage do |f| -%>
<%= render partial: 'form', locals: { f: f } %>
<% if @object.oauth_client %>
<%= styled_button_tag t(:button_save), class: "-highlight -with-icon icon-checkmark" %>
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 1268e41e730..8dff7453605 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
@@ -1,10 +1,10 @@
<!-- Standard Ruby view, please see the controller for comments -->
-<% html_title t(:label_administration), t("project_module_storages"), @storage.name, "#{t("storages.provider_types.#{@storage.provider_type}.name")} #{t("storages.label_oauth_client_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, admin_settings_storage_path(@storage)),
- t("storages.label_oauth_breadcrumb.#{@storage.provider_type}")
+ t("storages.label_oauth_breadcrumb.#{@storage.short_provider_type}")
] %>
-<%= toolbar title: "#{t("storages.provider_types.#{@storage.provider_type}.name")} #{t("storages.label_oauth_client_details")}" %>
+<%= 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| -%>
<fieldset class="form--fieldset">
@@ -16,7 +16,7 @@
container_class: '-wide' %>
<span class="form--field-instructions">
<%= "#{t("storages.instructions.copy_from")}: " %>
- <%= link_to "#{t("storages.instructions.#{@storage.provider_type}.integration")}",
+ <%= link_to "#{t("storages.instructions.#{@storage.short_provider_type}.integration")}",
File.join(@storage.host, "settings/admin/openproject").to_s,
target: "_blank" %>
</span>
@@ -29,7 +29,7 @@
container_class: '-wide' %>
<span class="form--field-instructions">
<%= "#{t("storages.instructions.copy_from")}: " %>
- <%= link_to "#{t("storages.instructions.#{@storage.provider_type}.integration")}",
+ <%= link_to "#{t("storages.instructions.#{@storage.short_provider_type}.integration")}",
File.join(@storage.host, "settings/admin/openproject").to_s,
target: "blank" %>
</span>
diff --git a/modules/storages/app/views/storages/admin/storages/show.html.erb b/modules/storages/app/views/storages/admin/storages/show.html.erb
index a0f47651343..557bddd949c 100644
--- a/modules/storages/app/views/storages/admin/storages/show.html.erb
+++ b/modules/storages/app/views/storages/admin/storages/show.html.erb
@@ -76,7 +76,7 @@ See COPYRIGHT and LICENSE files for more details.
<div class="attributes-key-value--key"><%= t(:'storages.label_provider_type') %></div>
<div class="attributes-key-value--value-container">
<div class="attributes-key-value--value -text">
- <span><%= t(:"storages.provider_types.#{@object.provider_type}.name") %></span>
+ <span><%= t(:"storages.provider_types.#{@object.short_provider_type}.name") %></span>
</div>
</div>
@@ -130,18 +130,18 @@ See COPYRIGHT and LICENSE files for more details.
<div class="attributes-group">
<div class="attributes-group--header">
<div class="attributes-group--header-container">
- <h3 class="attributes-group--header-text"><%= t("storages.provider_types.#{@object.provider_type}.name") %> <%= t(:'storages.label_oauth_client_details') %></h3>
+ <h3 class="attributes-group--header-text"><%= t("storages.provider_types.#{@object.short_provider_type}.name") %> <%= t(:'storages.label_oauth_client_details') %></h3>
</div>
</div>
<% if @object.oauth_client %>
<div class="attributes-key-value">
- <div class="attributes-key-value--key"><%= t("storages.provider_types.#{@object.provider_type}.name") %> <%= Storages::Admin::LABEL_OAUTH_CLIENT_ID %></div>
+ <div class="attributes-key-value--key"><%= t("storages.provider_types.#{@object.short_provider_type}.name") %> <%= Storages::Admin::LABEL_OAUTH_CLIENT_ID %></div>
<div class="attributes-key-value--value-container">
<div class="attributes-key-value--value -text">
<span><%= @object.oauth_client.client_id %></span>
</div>
</div>
- <div class="attributes-key-value--key"><%= t("storages.provider_types.#{@object.provider_type}.name") %> <%= Storages::Admin::LABEL_OAUTH_CLIENT_SECRET %></div>
+ <div class="attributes-key-value--key"><%= t("storages.provider_types.#{@object.short_provider_type}.name") %> <%= Storages::Admin::LABEL_OAUTH_CLIENT_SECRET %></div>
<div class="attributes-key-value--value-container">
<div class="attributes-key-value--value -text">
<span><%= short_secret(@object.oauth_client.client_secret) %></span>
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.erb
index c9e545ee00e..dbb51780873 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
@@ -1,5 +1,5 @@
<!-- Standard Ruby view, please see the controller for comments -->
-<% html_title t(:label_administration), t("project_module_storages"), @object.name, "#{t("storages.provider_types.#{@object.provider_type}.name")} #{t("storages.label_oauth_application_details")}" %>
+<% html_title t(:label_administration), t("project_module_storages"), @object.name, "#{t("storages.provider_types.#{@object.short_provider_type}.name")} #{t("storages.label_oauth_application_details")}" %>
<% local_assigns[:additional_breadcrumb] = [
link_to(@object.name, admin_settings_storage_path(@object)),
t("storages.label_oauth_breadcrumb.openproject")
diff --git a/modules/storages/app/views/storages/project_settings/new.html.erb b/modules/storages/app/views/storages/project_settings/new.html.erb
index 1bab96a0de1..e87a8384174 100644
--- a/modules/storages/app/views/storages/project_settings/new.html.erb
+++ b/modules/storages/app/views/storages/project_settings/new.html.erb
@@ -10,7 +10,7 @@
<% if @available_storages.any? %>
<div class="form--field -required">
<%= f.select :storage_id,
- @available_storages.map { |storage| ["#{storage.name} (#{storage.provider_type})", storage.id] },
+ @available_storages.map { |storage| ["#{storage.name} (#{storage.short_provider_type})", storage.id] },
selected: @available_storages.first.id.to_s,
container_class: '-slim' %>
<% if User.current.admin? %>
diff --git a/modules/storages/lib/open_project/storages/engine.rb b/modules/storages/lib/open_project/storages/engine.rb
index 2b66fd648e7..355b9d532e4 100644
--- a/modules/storages/lib/open_project/storages/engine.rb
+++ b/modules/storages/lib/open_project/storages/engine.rb
@@ -96,7 +96,7 @@ module OpenProject::Storages
storage.host,
caption: storage.name,
before: :members,
- icon: "#{storage.provider_type}-circle",
+ icon: "#{storage.short_provider_type}-circle",
icon_after: "external-link",
skip_permissions_check: true
)
diff --git a/modules/storages/spec/contracts/storages/storages/shared_contract_examples.rb b/modules/storages/spec/contracts/storages/storages/shared_contract_examples.rb
index 30acd4127eb..9dc39841830 100644
--- a/modules/storages/spec/contracts/storages/storages/shared_contract_examples.rb
+++ b/modules/storages/spec/contracts/storages/storages/shared_contract_examples.rb
@@ -72,12 +72,6 @@ shared_examples_for 'storage contract', :storage_server_helpers, webmock: true d
end
context 'when provider_type is invalid' do
- context 'as it is unknown' do
- let(:storage_provider_type) { 'unknown_provider_type' }
-
- include_examples 'contract is invalid', provider_type: :inclusion
- end
-
context 'as it is empty' do
let(:storage_provider_type) { '' }
diff --git a/modules/storages/spec/features/admin_storages_spec.rb b/modules/storages/spec/features/admin_storages_spec.rb
index 4466f961202..2c3a078521a 100644
--- a/modules/storages/spec/features/admin_storages_spec.rb
+++ b/modules/storages/spec/features/admin_storages_spec.rb
@@ -54,6 +54,9 @@ describe 'Admin storages', :storage_server_helpers, js: true do
# Mock a valid response (=200) for example.com, so the host validation should succeed
mock_server_capabilities_response("https://example.com")
mock_server_config_check_response("https://example.com")
+
+ # Setting to "" is needed to avoid receiving "My NextcloudNC 1"
+ page.find_by_id('storages_storage_name').set("")
page.find_by_id('storages_storage_name').set("NC 1")
page.find_by_id('storages_storage_host').set("https://example.com")
page.find('button[type=submit]', text: "Save and continue setup").click
diff --git a/modules/storages/spec/services/storages/oauth_applications/create_service_spec.rb b/modules/storages/spec/services/storages/oauth_applications/create_service_spec.rb
index 4e5159135e2..8a82055d557 100644
--- a/modules/storages/spec/services/storages/oauth_applications/create_service_spec.rb
+++ b/modules/storages/spec/services/storages/oauth_applications/create_service_spec.rb
@@ -42,7 +42,7 @@ describe Storages::OAuthApplications::CreateService, type: :model do
expect(subject).to be_success
expect(subject.result).to be_a Doorkeeper::Application
expect(subject.result.name).to include storage.name
- expect(subject.result.name).to include I18n.t("storages.provider_types.#{storage.provider_type}.name")
+ expect(subject.result.name).to include I18n.t("storages.provider_types.#{storage.short_provider_type}.name")
expect(subject.result.scopes.to_s).to eql "api_v3"
expect(subject.result.redirect_uri).to include storage.host
expect(subject.result.redirect_uri).to include 'apps/integration_openproject/oauth-redirect'
diff --git a/modules/storages/spec/services/storages/storages/create_service_spec.rb b/modules/storages/spec/services/storages/storages/create_service_spec.rb
index 781c7f9372a..38cbf8269cb 100644
--- a/modules/storages/spec/services/storages/storages/create_service_spec.rb
+++ b/modules/storages/spec/services/storages/storages/create_service_spec.rb
@@ -44,7 +44,7 @@ describe Storages::Storages::CreateService, type: :model do
{
name: 'My storage',
host: 'https://example.org',
- provider_type: :nextcloud
+ provider_type: 'Storages::NextcloudStorage'
}
end
diff --git a/modules/storages/spec/services/storages/storages/update_service_spec.rb b/modules/storages/spec/services/storages/storages/update_service_spec.rb
index f7fc29707ca..3a403e16055 100644
--- a/modules/storages/spec/services/storages/storages/update_service_spec.rb
+++ b/modules/storages/spec/services/storages/storages/update_service_spec.rb
@@ -51,8 +51,7 @@ describe Storages::Storages::UpdateService, type: :model do
build_stubbed(factory,
creator: user,
name: 'My updated storage',
- host: 'https://updated.example.org',
- provider_type: 'nextcloud')
+ host: 'https://updated.example.org')
end
let!(:oauth_application) { create(:oauth_application, integration: model_instance) }
@@ -90,7 +89,7 @@ describe Storages::Storages::UpdateService, type: :model do
end
it 'must update the name of the OAuth application' do
- expect(subject.result.oauth_application.name).to eq("#{name} (#{storage.provider_type.to_s.capitalize})")
+ expect(subject.result.oauth_application.name).to eq("Awesome Storage (Nextcloud)")
end
end
end