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

[#51266] Skip alert confirmation when OAuth clients are "Incomplete" and use pencil icon (#14299)

Kabiru Mwenja0d2432c6af83
diff --git a/modules/storages/app/components/storages/admin/oauth_client_info_component.html.erb b/modules/storages/app/components/storages/admin/oauth_client_info_component.html.erb
index 204e5bb0b17..1444be2c928 100644
--- a/modules/storages/app/components/storages/admin/oauth_client_info_component.html.erb
+++ b/modules/storages/app/components/storages/admin/oauth_client_info_component.html.erb
@@ -17,17 +17,7 @@
grid.with_area(:"icon-button", tag: :div, color: :muted) do
flex_layout(justify_content: :flex_end) do |icons_container|
icons_container.with_column do
- render(
- Primer::Beta::IconButton.new(
- icon: :sync,
- tag: :a,
- href: new_admin_settings_storage_oauth_client_path(storage),
- scheme: :invisible,
- aria: { label: I18n.t("storages.label_edit_storage_oauth_client") },
- data: { confirm: I18n.t("storages.confirm_replace_oauth_client") },
- test_selector: 'storage-edit-oauth-client-button'
- )
- )
+ render(Primer::Beta::IconButton.new(**edit_icon_button_options))
end
end
end
diff --git a/modules/storages/app/components/storages/admin/oauth_client_info_component.rb b/modules/storages/app/components/storages/admin/oauth_client_info_component.rb
index 27f358d5e56..735f15a54d9 100644
--- a/modules/storages/app/components/storages/admin/oauth_client_info_component.rb
+++ b/modules/storages/app/components/storages/admin/oauth_client_info_component.rb
@@ -40,5 +40,29 @@ module Storages::Admin
super(oauth_client, **options)
@storage = storage
end
+
+ def edit_icon_button_options
+ {
+ icon: oauth_client_configured? ? :sync : :pencil,
+ tag: :a,
+ href: Rails.application.routes.url_helpers.new_admin_settings_storage_oauth_client_path(storage),
+ scheme: :invisible,
+ aria: { label: I18n.t("storages.label_edit_storage_oauth_client") },
+ data: edit_icon_button_data_options,
+ test_selector: 'storage-edit-oauth-client-button'
+ }
+ end
+
+ private
+
+ def edit_icon_button_data_options
+ {}.tap do |data_h|
+ data_h[:confirm] = I18n.t("storages.confirm_replace_oauth_client") if oauth_client_configured?
+ end
+ end
+
+ def oauth_client_configured?
+ storage.configuration_checks[:storage_oauth_client_configured]
+ end
end
end
diff --git a/modules/storages/spec/components/storages/admin/oauth_client_info_component_spec.rb b/modules/storages/spec/components/storages/admin/oauth_client_info_component_spec.rb
new file mode 100644
index 00000000000..82806801892
--- /dev/null
+++ b/modules/storages/spec/components/storages/admin/oauth_client_info_component_spec.rb
@@ -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.
+#++
+#
+require 'spec_helper'
+require_module_spec_helper
+
+RSpec.describe Storages::Admin::OAuthClientInfoComponent, type: :component do # rubocop:disable RSpec/SpecFilePathFormat
+ describe '#edit_icon_button_options' do
+ context 'with oauth client configured' do
+ it 'returns false, does not render view component' do
+ storage = build_stubbed(:nextcloud_storage,
+ oauth_client: build_stubbed(:oauth_client))
+ component = described_class.new(storage:, oauth_client: storage.oauth_client)
+
+ expect(component.edit_icon_button_options).to include(
+ icon: :sync,
+ data: { confirm: "Are you sure? All users will have to authorize again against the storage." }
+ )
+ end
+ end
+
+ context 'without oauth client' do
+ it 'returns true, renders view component' do
+ storage = build_stubbed(:nextcloud_storage)
+ component = described_class.new(storage:, oauth_client: nil)
+
+ edit_icon_button_data_options = component.edit_icon_button_options
+ expect(edit_icon_button_data_options).to include(icon: :pencil)
+ expect(edit_icon_button_data_options[:data]).not_to include(:confirm)
+ end
+ end
+ end
+end