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

[#55382] restructured connection validation in sidebar

Eric Schubertc2a122bfbd9c
diff --git a/modules/storages/app/common/storages/peripherals/one_drive_connection_validator.rb b/modules/storages/app/common/storages/peripherals/one_drive_connection_validator.rb
index 01a7c9e2788..86b6c6feb0d 100644
--- a/modules/storages/app/common/storages/peripherals/one_drive_connection_validator.rb
+++ b/modules/storages/app/common/storages/peripherals/one_drive_connection_validator.rb
@@ -47,9 +47,7 @@ module Storages
.or { drive_id_wrong }
.or { request_failed_with_unknown_error }
.or { drive_with_unexpected_content }
- .value_or(ConnectionValidation.new(icon: "check-circle",
- scheme: :success,
- description: I18n.t("storages.connection_validation.success")))
+ .value_or(ConnectionValidation.new(type: :healthy, timestamp: Time.current, description: nil))
end
private
@@ -63,17 +61,17 @@ module Storages
def maybe_is_not_configured
return None() if @storage.configured?
- Some(ConnectionValidation.new(icon: :alert,
- scheme: :warning,
- description: I18n.t("storages.connection_validation.not_configured")))
+ Some(ConnectionValidation.new(type: :none,
+ timestamp: Time.current,
+ description: I18n.t("storages.health.connection_validation.not_configured")))
end
def drive_id_wrong
return None() if query.result != :not_found
- Some(ConnectionValidation.new(icon: :skip,
- scheme: :danger,
- description: I18n.t("storages.connection_validation.drive_id_wrong")))
+ Some(ConnectionValidation.new(type: :error,
+ timestamp: Time.current,
+ description: I18n.t("storages.health.connection_validation.drive_id_wrong")))
end
def tenant_id_wrong
@@ -85,9 +83,9 @@ module Storages
tenant_id_string = "Tenant '#{@storage.tenant_id}' not found."
return None() unless payload["error_description"].include?(tenant_id_string)
- Some(ConnectionValidation.new(icon: :skip,
- scheme: :danger,
- description: I18n.t("storages.connection_validation.tenant_id_wrong")))
+ Some(ConnectionValidation.new(type: :error,
+ timestamp: Time.current,
+ description: I18n.t("storages.health.connection_validation.tenant_id_wrong")))
end
def client_id_wrong
@@ -96,9 +94,9 @@ module Storages
payload = JSON.parse(query.error_payload)
return None() if payload["error"] != "unauthorized_client"
- Some(ConnectionValidation.new(icon: :skip,
- scheme: :danger,
- description: I18n.t("storages.connection_validation.client_id_wrong")))
+ Some(ConnectionValidation.new(type: :error,
+ timestamp: Time.current,
+ description: I18n.t("storages.health.connection_validation.client_id_wrong")))
end
def client_secret_wrong
@@ -107,9 +105,9 @@ module Storages
payload = JSON.parse(query.error_payload)
return None() if payload["error"] != "invalid_client"
- Some(ConnectionValidation.new(icon: :skip,
- scheme: :danger,
- description: I18n.t("storages.connection_validation.client_secret_wrong")))
+ Some(ConnectionValidation.new(type: :error,
+ timestamp: Time.current,
+ description: I18n.t("storages.health.connection_validation.client_secret_wrong")))
end
# rubocop:disable Metrics/AbcSize
@@ -124,9 +122,9 @@ module Storages
unexpected_files = query.result.files.reject { |file| expected_folder_ids.include?(file.id) }
return None() if unexpected_files.empty?
- Some(ConnectionValidation.new(icon: :alert,
- scheme: :warning,
- description: I18n.t("storages.connection_validation.unexpected_content")))
+ Some(ConnectionValidation.new(type: :warning,
+ timestamp: Time.current,
+ description: I18n.t("storages.health.connection_validation.unexpected_content")))
end
# rubocop:enable Metrics/AbcSize
@@ -137,9 +135,9 @@ module Storages
Rails.logger.error("Connection validation failed with unknown error:\n\t" \
"status: #{query.result}\n\tresponse: #{query.error_payload}")
- Some(ConnectionValidation.new(icon: :skip,
- scheme: :danger,
- description: I18n.t("storages.connection_validation.unknown_error")))
+ Some(ConnectionValidation.new(type: :error,
+ timestamp: Time.current,
+ description: I18n.t("storages.health.connection_validation.unknown_error")))
end
def root_folder
diff --git a/modules/storages/app/components/storages/admin/sidebar/health_status_component.html.erb b/modules/storages/app/components/storages/admin/sidebar/health_status_component.html.erb
index 013a1272589..64e2b2e94f0 100644
--- a/modules/storages/app/components/storages/admin/sidebar/health_status_component.html.erb
+++ b/modules/storages/app/components/storages/admin/sidebar/health_status_component.html.erb
@@ -31,34 +31,55 @@ See COPYRIGHT and LICENSE files for more details.
component_wrapper do
flex_layout do |health_status_container|
health_status_container.with_row do
- flex_layout do |heading|
- heading.with_row do
- render(Primer::Beta::Heading.new(tag: :h4)) { I18n.t("storages.health.title") }
+ render(Primer::Beta::Heading.new(tag: :h4)) { I18n.t("storages.health.title") }
+ end
+
+ if @storage.provider_type_one_drive?
+ health_status_container.with_row(mt: 2) do
+ render(OpTurbo::FrameComponent.new(id: :connection_validation_result)) do
+ render(Storages::Admin::Sidebar::ValidationResultComponent.new(result: validation_result_placeholder))
end
+ end
- heading.with_row(mt: 2) do
- render(Primer::Beta::Text.new(font_weight: :bold)) { I18n.t("storages.health.subtitle") }
+ health_status_container.with_row(mt: 2) do
+ primer_form_with(
+ model: @storage,
+ url: validate_connection_admin_settings_storage_connection_validation_path(@storage),
+ method: :post,
+ data: { turbo: true }
+ ) do
+ render(Primer::Beta::Button.new(
+ scheme: :link,
+ color: :default,
+ font_weight: :bold,
+ type: :submit,
+ )) do |button|
+ button.with_leading_visual_icon(icon: "meter")
+ I18n.t("storages.health.connection_validation.action")
+ end
end
end
end
- health_status_container.with_row(mt: 2) do
- flex_layout do |health_status_label|
- health_status_label.with_row do
- concat(render(Primer::Beta::Text.new(pr: 2, test_selector: "storage-health-checked-at")) do
- I18n.t('storages.health.checked', datetime: helpers.format_time(@storage.health_checked_at))
- end)
+ if @storage.automatic_management_enabled?
+ health_status_container.with_row(mt: 2) do
+ render(Primer::Beta::Text.new(font_weight: :bold)) { I18n.t("storages.health.project_folders.subtitle") }
+ end
- concat(render(Primer::Beta::Label.new(scheme: health_status_indicator[:scheme], test_selector: "storage-health-status")) do
- health_status_indicator[:label]
- end)
- end
+ health_status_container.with_row(mt: 2) do
+ concat(render(Primer::Beta::Text.new(pr: 2, test_selector: "storage-health-checked-at")) do
+ I18n.t('storages.health.checked', datetime: helpers.format_time(@storage.health_checked_at))
+ end)
+
+ concat(render(Primer::Beta::Label.new(scheme: health_status_indicator[:scheme], test_selector: "storage-health-status")) do
+ health_status_indicator[:label]
+ end)
+ end
- if @storage.health_unhealthy?
- health_status_label.with_row(mt: 2) do
- render(Primer::Beta::Text.new(color: :muted, test_selector: "storage-health-error")) do
- formatted_health_reason
- end
+ if @storage.health_unhealthy?
+ health_status_container.with_row(mt: 2) do
+ render(Primer::Beta::Text.new(color: :muted, test_selector: "storage-health-error")) do
+ formatted_health_reason
end
end
end
diff --git a/modules/storages/app/components/storages/admin/sidebar/health_status_component.rb b/modules/storages/app/components/storages/admin/sidebar/health_status_component.rb
index 42e05f958ca..ff6e386ac24 100644
--- a/modules/storages/app/components/storages/admin/sidebar/health_status_component.rb
+++ b/modules/storages/app/components/storages/admin/sidebar/health_status_component.rb
@@ -1,62 +1,44 @@
# frozen_string_literal: true
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2024 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 Sidebar::HealthStatusComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
- include ApplicationHelper
- include OpTurbo::Streamable
- include OpPrimer::ComponentHelpers
+module Storages
+ module Admin
+ module Sidebar
+ class HealthStatusComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
+ include ApplicationHelper
+ include OpTurbo::Streamable
+ include OpPrimer::ComponentHelpers
- def initialize(storage:)
- super(storage)
- @storage = storage
- end
+ def initialize(storage:)
+ super(storage)
+ @storage = storage
+ end
- private
+ private
- def health_status_indicator
- case @storage.health_status
- when "healthy"
- { scheme: :success, label: I18n.t("storages.health.label_healthy") }
- when "unhealthy"
- { scheme: :danger, label: I18n.t("storages.health.label_error") }
- else
- { scheme: :attention, label: I18n.t("storages.health.label_pending") }
- end
- end
+ def health_status_indicator
+ case @storage.health_status
+ when "healthy"
+ { scheme: :success, label: I18n.t("storages.health.label_healthy") }
+ when "unhealthy"
+ { scheme: :danger, label: I18n.t("storages.health.label_error") }
+ else
+ { scheme: :attention, label: I18n.t("storages.health.label_pending") }
+ end
+ end
- # This method returns the health identifier, description and the time since when the error occurs in a
- # formatted manner. e.g. "Not found: Outbound request destination not found since 12/07/2023 03:45 PM"
- def formatted_health_reason
- "#{@storage.health_reason_identifier.tr('_', ' ').strip.capitalize}: #{@storage.health_reason_description} " +
- I18n.t("storages.health.since", datetime: helpers.format_time(@storage.health_changed_at))
+ # This method returns the health identifier, description and the time since when the error occurs in a
+ # formatted manner. e.g. "Not found: Outbound request destination not found since 12/07/2023 03:45 PM"
+ def formatted_health_reason
+ "#{@storage.health_reason_identifier.tr('_', ' ').strip.capitalize}: #{@storage.health_reason_description} " +
+ I18n.t("storages.health.since", datetime: helpers.format_time(@storage.health_changed_at))
+ end
+
+ def validation_result_placeholder
+ ConnectionValidation.new(type: :none,
+ timestamp: Time.current,
+ description: I18n.t("storages.health.connection_validation.placeholder"))
+ end
+ end
end
end
end
diff --git a/modules/storages/app/components/storages/admin/sidebar/connection_validation_component.html.erb b/modules/storages/app/components/storages/admin/sidebar/validation_result_component.html.erb
similarity index 54%
rename from modules/storages/app/components/storages/admin/sidebar/connection_validation_component.html.erb
rename to modules/storages/app/components/storages/admin/sidebar/validation_result_component.html.erb
index d5e13502875..16c3869be12 100644
--- a/modules/storages/app/components/storages/admin/sidebar/connection_validation_component.html.erb
+++ b/modules/storages/app/components/storages/admin/sidebar/validation_result_component.html.erb
@@ -28,40 +28,25 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
<%=
- component_wrapper do
- flex_layout do |container|
- container.with_row do
- flex_layout do |heading|
- heading.with_row do
- render(Primer::Beta::Heading.new(tag: :h4)) { I18n.t("storages.connection_validation.title") }
- end
- end
- end
+ flex_layout do |container|
+ container.with_row do
+ render(Primer::Beta::Text.new(font_weight: :bold)) { I18n.t("storages.health.connection_validation.subtitle") }
+ end
+ if @result.type != :none
container.with_row(mt: 2) do
- primer_form_with(
- model: @storage,
- url: validate_connection_admin_settings_storage_connection_validation_path(@storage),
- method: :post,
- data: { turbo: true }
- ) do
- flex_layout do |form|
- form.with_row do
- render(OpTurbo::FrameComponent.new(id: :connection_validation_result))
- end
+ status = status_indicator
+
+ concat(render(Primer::Beta::Text.new(pr: 2)) do
+ I18n.t('storages.health.checked', datetime: helpers.format_time(@result.timestamp))
+ end)
+ concat(render(Primer::Beta::Label.new(scheme: status[:scheme])) { status[:label] })
+ end
+ end
- form.with_row(mt: 2) do
- render(Primer::Beta::Button.new(
- scheme: :default,
- block: :true,
- type: :submit,
- )) do |button|
- button.with_leading_visual_icon(icon: "tasklist")
- I18n.t("storages.connection_validation.action")
- end
- end
- end
- end
+ if @result.description.present?
+ container.with_row(mt: 2) do
+ render(Primer::Beta::Text.new(color: :muted)) { @result.description }
end
end
end
diff --git a/modules/storages/app/components/storages/admin/sidebar/connection_validation_component.rb b/modules/storages/app/components/storages/admin/sidebar/validation_result_component.rb
similarity index 65%
rename from modules/storages/app/components/storages/admin/sidebar/connection_validation_component.rb
rename to modules/storages/app/components/storages/admin/sidebar/validation_result_component.rb
index f8f0176d52f..4c745fba7f5 100644
--- a/modules/storages/app/components/storages/admin/sidebar/connection_validation_component.rb
+++ b/modules/storages/app/components/storages/admin/sidebar/validation_result_component.rb
@@ -31,13 +31,27 @@
module Storages
module Admin
module Sidebar
- class ConnectionValidationComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
- include OpTurbo::Streamable
+ class ValidationResultComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
include OpPrimer::ComponentHelpers
- def initialize(storage:)
- super(storage)
- @storage = storage
+ def initialize(result:)
+ super(result)
+ @result = result
+ end
+
+ private
+
+ def status_indicator
+ case @result.type
+ when :healthy
+ { scheme: :success, label: I18n.t("storages.health.label_healthy") }
+ when :warning
+ { scheme: :attention, label: I18n.t("storages.health.label_warning") }
+ when :error
+ { scheme: :danger, label: I18n.t("storages.health.label_error") }
+ else
+ raise ArgumentError, "Unknown validation result type for status indicator: #{@result.type}"
+ end
end
end
end
diff --git a/modules/storages/app/components/storages/admin/sidebar_component.html.erb b/modules/storages/app/components/storages/admin/sidebar_component.html.erb
index 879910a3132..69515e44110 100644
--- a/modules/storages/app/components/storages/admin/sidebar_component.html.erb
+++ b/modules/storages/app/components/storages/admin/sidebar_component.html.erb
@@ -1,12 +1,9 @@
<%=
component_wrapper do
render(Primer::OpenProject::BorderGrid.new) do |border_grid|
- if @storage.provider_type_one_drive?
- border_grid.with_row { render(Storages::Admin::Sidebar::ConnectionValidationComponent.new(storage: @storage)) }
- end
-
+ border_grid.with_row { render(Storages::Admin::Sidebar::HealthStatusComponent.new(storage: @storage)) }
+
if @storage.automatic_management_enabled?
- border_grid.with_row { render(Storages::Admin::Sidebar::HealthStatusComponent.new(storage: @storage)) }
border_grid.with_row { render(Storages::Admin::Sidebar::HealthNotificationsComponent.new(storage: @storage)) }
end
end
diff --git a/modules/storages/app/models/storages/connection_validation.rb b/modules/storages/app/models/storages/connection_validation.rb
index 9840279040e..6b2845089ad 100644
--- a/modules/storages/app/models/storages/connection_validation.rb
+++ b/modules/storages/app/models/storages/connection_validation.rb
@@ -29,5 +29,5 @@
#++
module Storages
- ConnectionValidation = Data.define(:icon, :scheme, :description)
+ ConnectionValidation = Data.define(:type, :description, :timestamp)
end
diff --git a/modules/storages/app/views/storages/admin/connection_validation/validate_connection.turbo_stream.erb b/modules/storages/app/views/storages/admin/connection_validation/validate_connection.turbo_stream.erb
index 8c6bf8749e2..f42b7b4d08a 100644
--- a/modules/storages/app/views/storages/admin/connection_validation/validate_connection.turbo_stream.erb
+++ b/modules/storages/app/views/storages/admin/connection_validation/validate_connection.turbo_stream.erb
@@ -28,5 +28,5 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
<%= turbo_stream.update :connection_validation_result do %>
- <%= render(Primer::Alpha::Banner.new(icon: @result.icon, scheme: @result.scheme)) { @result.description } %>
+ <%= render(Storages::Admin::Sidebar::ValidationResultComponent.new(result: @result)) %>
<% end %>
diff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.yml
index 8c61a1d5aee..cd43dcf15bf 100644
--- a/modules/storages/config/locales/en.yml
+++ b/modules/storages/config/locales/en.yml
@@ -102,13 +102,26 @@ en:
redirect_uri: Redirect URI
storage_provider: Storage provider
health:
+ title: Health status
checked: Last checked %{datetime}
label_error: Error
+ label_warning: Warning
label_healthy: Healthy
label_pending: Pending
since: since %{datetime}
- subtitle: Automatically managed project folders
- title: Health status
+ project_folders:
+ subtitle: Automatically managed project folders
+ connection_validation:
+ subtitle: Connection validation
+ placeholder: Check your connection against the server.
+ action: Recheck connection
+ not_configured: The connection could not be validated. Please finish configuration first.
+ drive_id_wrong: The configured drive id could not be found. Please check the configuration.
+ tenant_id_wrong: The configured directory (tenant) id is invalid. Please check the configuration.
+ client_id_wrong: The configured OAuth 2 client id is invalid. Please check the configuration.
+ client_secret_wrong: The configured OAuth 2 client secret is invalid. Please check the configuration.
+ unknown_error: The connection could not be validated. An unknown error occurred. Please check the server logs for further information.
+ unexpected_content: Unexpected content found in the drive.
health_email_notifications:
description_subscribed: All administrators receive health status email notifications for this storage.
description_unsubscribed: Health status email notifications for this storage have been turned off for all administrators.
@@ -116,17 +129,6 @@ en:
subscribe: Subscribe
title: Email notifications
unsubscribe: Unsubscribe
- connection_validation:
- title: Connection validation
- action: Validate connection
- not_configured: The connection could not be validated. Please finish configuration first.
- drive_id_wrong: The configured drive id could not be found. Please check the configuration.
- tenant_id_wrong: The configured directory (tenant) id is invalid. Please check the configuration.
- client_id_wrong: The configured OAuth 2 client id is invalid. Please check the configuration.
- client_secret_wrong: The configured OAuth 2 client secret is invalid. Please check the configuration.
- unknown_error: The connection could not be validated. An unknown error occurred. Please check the server logs for further information.
- unexpected_content: Unexpected content found in the drive.
- success: The connection works as expected.
help_texts:
project_folder: The project folder is the default folder for file uploads for this project. Users can nevertheless still upload files to other locations.
instructions: