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
[#55382] adapt PR suggestions
Eric Schubertaa732f793082
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.rbindex 86b6c6feb0d..0d53bc9cb96 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,7 +47,10 @@ module Storages.or { drive_id_wrong }.or { request_failed_with_unknown_error }.or { drive_with_unexpected_content }- .value_or(ConnectionValidation.new(type: :healthy, timestamp: Time.current, description: nil))+ .value_or(ConnectionValidation.new(type: :healthy,+ error_code: :none,+ timestamp: Time.current,+ description: nil))endprivate@@ -62,6 +65,7 @@ module Storagesreturn None() if @storage.configured?Some(ConnectionValidation.new(type: :none,+ error_code: :wrn_not_configured,timestamp: Time.current,description: I18n.t("storages.health.connection_validation.not_configured")))end@@ -70,6 +74,7 @@ module Storagesreturn None() if query.result != :not_foundSome(ConnectionValidation.new(type: :error,+ error_code: :err_drive_invalid,timestamp: Time.current,description: I18n.t("storages.health.connection_validation.drive_id_wrong")))end@@ -84,6 +89,7 @@ module Storagesreturn None() unless payload["error_description"].include?(tenant_id_string)Some(ConnectionValidation.new(type: :error,+ error_code: :err_tenant_invalid,timestamp: Time.current,description: I18n.t("storages.health.connection_validation.tenant_id_wrong")))end@@ -95,6 +101,7 @@ module Storagesreturn None() if payload["error"] != "unauthorized_client"Some(ConnectionValidation.new(type: :error,+ error_code: :err_client_invalid,timestamp: Time.current,description: I18n.t("storages.health.connection_validation.client_id_wrong")))end@@ -106,6 +113,7 @@ module Storagesreturn None() if payload["error"] != "invalid_client"Some(ConnectionValidation.new(type: :error,+ error_code: :err_client_invalid,timestamp: Time.current,description: I18n.t("storages.health.connection_validation.client_secret_wrong")))end@@ -123,6 +131,7 @@ module Storagesreturn None() if unexpected_files.empty?Some(ConnectionValidation.new(type: :warning,+ error_code: :wrn_unexpected_content,timestamp: Time.current,description: I18n.t("storages.health.connection_validation.unexpected_content")))end@@ -136,6 +145,7 @@ module Storages"status: #{query.result}\n\tresponse: #{query.error_payload}")Some(ConnectionValidation.new(type: :error,+ error_code: :err_unknown,timestamp: Time.current,description: I18n.t("storages.health.connection_validation.unknown_error")))enddiff --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.erbindex 64e2b2e94f0..81159ee2538 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@@ -36,9 +36,7 @@ See COPYRIGHT and LICENSE files for more details.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+ render(Storages::Admin::Sidebar::ValidationResultComponent.new(result: validation_result_placeholder))endhealth_status_container.with_row(mt: 2) dodiff --git a/modules/storages/app/components/storages/admin/sidebar/health_status_component.rb b/modules/storages/app/components/storages/admin/sidebar/health_status_component.rbindex 53f563c199d..97a3383375a 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@@ -63,6 +63,7 @@ module Storagesdef validation_result_placeholderConnectionValidation.new(type: :none,+ error_code: :none,timestamp: Time.current,description: I18n.t("storages.health.connection_validation.placeholder"))enddiff --git a/modules/storages/app/components/storages/admin/sidebar/validation_result_component.html.erb b/modules/storages/app/components/storages/admin/sidebar/validation_result_component.html.erbindex 383618b5dff..b50ef244204 100644--- a/modules/storages/app/components/storages/admin/sidebar/validation_result_component.html.erb+++ b/modules/storages/app/components/storages/admin/sidebar/validation_result_component.html.erb@@ -28,28 +28,32 @@ See COPYRIGHT and LICENSE files for more details.++#%><%=- flex_layout do |container|- container.with_row do- render(Primer::Beta::Text.new(font_weight: :bold, test_selector: "validation-result--subtitle")) do- I18n.t("storages.health.connection_validation.subtitle")+ component_wrapper do+ flex_layout do |container|+ container.with_row do+ render(Primer::Beta::Text.new(font_weight: :bold, test_selector: "validation-result--subtitle")) do+ I18n.t("storages.health.connection_validation.subtitle")+ endend- end- if @result.type != :none- container.with_row(mt: 2) do- status = status_indicator+ if @result.validation_result_exists?+ container.with_row(mt: 2) do+ status = status_indicator- concat(render(Primer::Beta::Text.new(pr: 2, test_selector: "validation-result--timestamp")) do- I18n.t('storages.health.checked', datetime: helpers.format_time(@result.timestamp))- end)- concat(render(Primer::Beta::Label.new(scheme: status[:scheme])) { status[:label] })+ concat(render(Primer::Beta::Text.new(pr: 2, test_selector: "validation-result--timestamp")) do+ I18n.t('storages.health.checked', datetime: helpers.format_time(@result.timestamp))+ end)+ concat(render(Primer::Beta::Label.new(scheme: status[:scheme])) { status[:label] })+ endend- end- if @result.description.present?- container.with_row(mt: 2) do- render(Primer::Beta::Text.new(color: :muted, test_selector: "validation-result--description")) do- @result.description+ if @result.description.present?+ prefix = @result.error_code? ? "#{@result.error_code.upcase}: " : ""++ container.with_row(mt: 2) do+ render(Primer::Beta::Text.new(color: :muted, test_selector: "validation-result--description")) do+ prefix + @result.description+ endendendenddiff --git a/modules/storages/app/components/storages/admin/sidebar/validation_result_component.rb b/modules/storages/app/components/storages/admin/sidebar/validation_result_component.rbindex 4c745fba7f5..f145051b292 100644--- a/modules/storages/app/components/storages/admin/sidebar/validation_result_component.rb+++ b/modules/storages/app/components/storages/admin/sidebar/validation_result_component.rb@@ -33,6 +33,7 @@ module Storagesmodule Sidebarclass ValidationResultComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponentinclude OpPrimer::ComponentHelpers+ include OpTurbo::Streamabledef initialize(result:)super(result)diff --git a/modules/storages/app/components/storages/admin/sidebar_component.html.erb b/modules/storages/app/components/storages/admin/sidebar_component.html.erbindex 69515e44110..918d19b5039 100644--- a/modules/storages/app/components/storages/admin/sidebar_component.html.erb+++ b/modules/storages/app/components/storages/admin/sidebar_component.html.erb@@ -2,7 +2,7 @@component_wrapper dorender(Primer::OpenProject::BorderGrid.new) do |border_grid|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::HealthNotificationsComponent.new(storage: @storage)) }enddiff --git a/modules/storages/app/controllers/storages/admin/connection_validation_controller.rb b/modules/storages/app/controllers/storages/admin/connection_validation_controller.rbindex 123a95a9407..fd758c0ea16 100644--- a/modules/storages/app/controllers/storages/admin/connection_validation_controller.rb+++ b/modules/storages/app/controllers/storages/admin/connection_validation_controller.rb@@ -45,10 +45,8 @@ module Storages@result = Peripherals::OneDriveConnectionValidator.new(storage: @storage).validate-- respond_to do |format|- format.turbo_stream- end+ update_via_turbo_stream(component: Sidebar::ValidationResultComponent.new(result: @result))+ respond_to_with_turbo_streamsendprivatediff --git a/modules/storages/app/models/storages/connection_validation.rb b/modules/storages/app/models/storages/connection_validation.rbindex 6b2845089ad..a9ad82f087d 100644--- a/modules/storages/app/models/storages/connection_validation.rb+++ b/modules/storages/app/models/storages/connection_validation.rb@@ -29,5 +29,13 @@#++module Storages- ConnectionValidation = Data.define(:type, :description, :timestamp)+ ConnectionValidation = Data.define(:type, :error_code, :description, :timestamp) do+ def validation_result_exists?+ type.present? && type != :none+ end++ def error_code?+ error_code.present? && error_code != :none+ end+ endenddiff --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.erbdeleted file mode 100644index f42b7b4d08a..00000000000--- a/modules/storages/app/views/storages/admin/connection_validation/validate_connection.turbo_stream.erb+++ /dev/null@@ -1,32 +0,0 @@-<%#-- 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.--++#%>--<%= turbo_stream.update :connection_validation_result do %>- <%= render(Storages::Admin::Sidebar::ValidationResultComponent.new(result: @result)) %>-<% end %>diff --git a/modules/storages/spec/common/storages/peripherals/one_drive_connection_validator_spec.rb b/modules/storages/spec/common/storages/peripherals/one_drive_connection_validator_spec.rbindex 37744b344ce..6aed3e2cf69 100644--- a/modules/storages/spec/common/storages/peripherals/one_drive_connection_validator_spec.rb+++ b/modules/storages/spec/common/storages/peripherals/one_drive_connection_validator_spec.rb@@ -43,6 +43,7 @@ RSpec.describe Storages::Peripherals::OneDriveConnectionValidator doit "returns a validation failure" doexpect(subject.type).to eq(:none)+ expect(subject.error_code).to eq(:wrn_not_configured)expect(subject.description).to eq("The connection could not be validated. Please finish configuration first.")endend@@ -58,6 +59,7 @@ RSpec.describe Storages::Peripherals::OneDriveConnectionValidator doit "returns a validation failure" doexpect(subject.type).to eq(:error)+ expect(subject.error_code).to eq(:err_tenant_invalid)expect(subject.description).to eq("The configured directory (tenant) id is invalid. Please check the configuration.")end@@ -69,6 +71,7 @@ RSpec.describe Storages::Peripherals::OneDriveConnectionValidator doit "returns a validation failure" doexpect(subject.type).to eq(:error)+ expect(subject.error_code).to eq(:err_client_invalid)expect(subject.description).to eq("The configured OAuth 2 client id is invalid. Please check the configuration.")endend@@ -79,6 +82,7 @@ RSpec.describe Storages::Peripherals::OneDriveConnectionValidator doit "returns a validation failure" doexpect(subject.type).to eq(:error)+ expect(subject.error_code).to eq(:err_client_invalid)expect(subject.description).to eq("The configured OAuth 2 client secret is invalid. Please check the configuration.")end@@ -89,6 +93,7 @@ RSpec.describe Storages::Peripherals::OneDriveConnectionValidator doit "returns a validation failure" doexpect(subject.type).to eq(:error)+ expect(subject.error_code).to eq(:err_drive_invalid)expect(subject.description).to eq("The configured drive id could not be found. Please check the configuration.")endend@@ -102,6 +107,7 @@ RSpec.describe Storages::Peripherals::OneDriveConnectionValidator doit "returns a validation failure" doexpect(subject.type).to eq(:error)+ expect(subject.error_code).to eq(:err_unknown)expect(subject.description).to eq("The connection could not be validated. An unknown error occurred. " \"Please check the server logs for further information.")@@ -141,6 +147,7 @@ RSpec.describe Storages::Peripherals::OneDriveConnectionValidator doit "returns a validation failure" doexpect(subject.type).to eq(:warning)+ expect(subject.error_code).to eq(:wrn_unexpected_content)expect(subject.description).to eq("Unexpected content found in the drive.")endend@@ -150,6 +157,7 @@ RSpec.describe Storages::Peripherals::OneDriveConnectionValidator doit "returns a validation success" doexpect(subject.type).to eq(:healthy)+ expect(subject.error_code).to eq(:none)expect(subject.description).to be_nilendenddiff --git a/modules/storages/spec/requests/storages/admin/connection_validation_spec.rb b/modules/storages/spec/requests/storages/admin/connection_validation_spec.rbindex 10fc607eb80..b3b0cfe7b9d 100644--- a/modules/storages/spec/requests/storages/admin/connection_validation_spec.rb+++ b/modules/storages/spec/requests/storages/admin/connection_validation_spec.rb@@ -77,7 +77,10 @@ RSpec.describe "connection validation", :skip_csrf docontext "if the a validation result of type :none (no validation executed) is returned" dolet(:validation_result) do- Storages::ConnectionValidation.new(type: :none, timestamp: Time.current, description: "not configured")+ Storages::ConnectionValidation.new(type: :none,+ error_code: :none,+ timestamp: Time.current,+ description: "not configured")endit_behaves_like "a validation result template", show_timestamp: false, label: nil, description: "not configured"@@ -85,27 +88,31 @@ RSpec.describe "connection validation", :skip_csrf docontext "if validator returns an error" dolet(:validation_result) do- Storages::ConnectionValidation.new(type: :error, timestamp: Time.current, description: "An error occurred")+ Storages::ConnectionValidation.new(type: :error,+ error_code: :my_err,+ timestamp: Time.current,+ description: "An error occurred")endit_behaves_like "a validation result template",- show_timestamp: true, label: "Error", description: "An error occurred"+ show_timestamp: true, label: "Error", description: "MY_ERR: An error occurred"endcontext "if validator returns a warning" dolet(:validation_result) doStorages::ConnectionValidation.new(type: :warning,+ error_code: :my_wrn,timestamp: Time.current,description: "There is something weird...")endit_behaves_like "a validation result template",- show_timestamp: true, label: "Warning", description: "There is something weird..."+ show_timestamp: true, label: "Warning", description: "MY_WRN: There is something weird..."endcontext "if validator returns a success" dolet(:validation_result) do- Storages::ConnectionValidation.new(type: :healthy, timestamp: Time.current, description: nil)+ Storages::ConnectionValidation.new(type: :healthy, error_code: :none, timestamp: Time.current, description: nil)endit_behaves_like "a validation result template",@@ -115,22 +122,21 @@ RSpec.describe "connection validation", :skip_csrf doprivate- # rubocop:disable Layout/LineLengthdef xpath_for_subtitle- "//turbo-stream[@target='connection_validation_result']/template/div/div/span[@data-test-selector='validation-result--subtitle']"+ "#{xpath_for_turbo_target}/div/div/span[@data-test-selector='validation-result--subtitle']"enddef xpath_for_timestamp- "//turbo-stream[@target='connection_validation_result']/template/div/div/span[@data-test-selector='validation-result--timestamp']"+ "#{xpath_for_turbo_target}/div/div/span[@data-test-selector='validation-result--timestamp']"enddef xpath_for_label- "//turbo-stream[@target='connection_validation_result']/template/div/div/span[contains(@class, 'Label')]"+ "#{xpath_for_turbo_target}/div/div/span[contains(@class, 'Label')]"enddef xpath_for_description- "//turbo-stream[@target='connection_validation_result']/template/div/div/span[@data-test-selector='validation-result--description']"+ "#{xpath_for_turbo_target}/div/div/span[@data-test-selector='validation-result--description']"end- # rubocop:enable Layout/LineLength+ def xpath_for_turbo_target = "//turbo-stream[@target='storages-admin-sidebar-validation-result-component']/template"end