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

chore[#50212]: WIP - OAuth Credentials clipboard copy

Kabiru Mwenja15ee221579b6
diff --git a/modules/storages/app/components/storages/admin/forms/oauth_application_form_component.html.erb b/modules/storages/app/components/storages/admin/forms/oauth_application_form_component.html.erb
new file mode 100644
index 00000000000..85e8ebaa676
--- /dev/null
+++ b/modules/storages/app/components/storages/admin/forms/oauth_application_form_component.html.erb
@@ -0,0 +1,22 @@
+<%=
+ primer_form_with(
+ model: storage,
+ url: edit_admin_settings_storage_path(storage),
+ method: :get
+ ) do |form|
+ flex_layout do |general_info_row|
+ general_info_row.with_row(mb: 3) do
+ render(Storages::Admin::ClipboardCopyInputForm.new(form))
+ end
+
+ general_info_row.with_row(mb: 3) do
+ render(Storages::Admin::ClipboardCopyInputForm.new(form))
+ end
+
+ general_info_row.with_row do
+ concat(render(Primer::Beta::Button.new(scheme: :primary, type: :submit)) { I18n.t('storages.buttons.done_continue') })
+ concat(render(Primer::Beta::Button.new(scheme: :default, tag: :a, href: edit_admin_settings_storage_path(storage))) { I18n.t('button_cancel') })
+ end
+ end
+ end
+%>
diff --git a/modules/storages/app/components/storages/admin/forms/oauth_application_form_component.rb b/modules/storages/app/components/storages/admin/forms/oauth_application_form_component.rb
new file mode 100644
index 00000000000..b32fcf9ffd2
--- /dev/null
+++ b/modules/storages/app/components/storages/admin/forms/oauth_application_form_component.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+#-- 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.
+#++
+#
+module Storages::Admin::Forms
+ class OAuthApplicationFormComponent < ApplicationComponent
+ include OpPrimer::ComponentHelpers
+
+ attr_reader :storage
+ alias_method :oauth_application, :model
+
+ def initialize(oauth_application:, storage:, **options)
+ super(oauth_application, **options)
+ @storage = storage
+ end
+ end
+end
diff --git a/modules/storages/app/components/storages/admin/storage_view_component.html.erb b/modules/storages/app/components/storages/admin/storage_view_component.html.erb
index acb3aaaacd4..75a8abd2f61 100644
--- a/modules/storages/app/components/storages/admin/storage_view_component.html.erb
+++ b/modules/storages/app/components/storages/admin/storage_view_component.html.erb
@@ -45,18 +45,34 @@
end
component.with_row(scheme: :default) do
- grid_layout('op-storage-view--row', tag: :div, align_items: :center) do |grid|
- grid.with_area(:item, tag: :div, mr: 3) do
- concat(render(Primer::Beta::Text.new(font_weight: :semibold, mr: 1)) { I18n.t('storages.file_storage_view.openproject_oauth') })
- concat(configuration_check_label_for(:openproject_oauth_application_configured))
- end
+ render(OpTurbo::FrameWrapperComponent.new(storage, frame: :openproject_oauth)) do
+ grid_layout('op-storage-view--row', tag: :div, align_items: :center) do |grid|
+ grid.with_area(:item, tag: :div, mr: 3) do
+ concat(render(Primer::Beta::Text.new(font_weight: :semibold, mr: 1)) { I18n.t('storages.file_storage_view.openproject_oauth') })
+ concat(configuration_check_label_for(:openproject_oauth_application_configured))
+ end
- grid.with_area(:description, tag: :div, color: :subtle, data: { 'test-selector': 'storage-openproject-oauth-client-description' }) do
- render(Primer::Beta::Truncate.new(font_weight: :light)) { openproject_oauth_client_description }
- end
+ grid.with_area(:description, tag: :div, color: :subtle, data: { 'test-selector': 'storage-openproject-oauth-client-description' }) do
+ render(Primer::Beta::Truncate.new(font_weight: :light)) { openproject_oauth_client_description }
+ end
- grid.with_area(:"icon-button", tag: :div, color: :subtle, mr: 3, justify_self: :end) do
- render(Primer::Beta::IconButton.new(icon: :sync, scheme: :invisible, aria: { label: I18n.t('storages.label_edit_storage') } , data: { 'test-selector': 'storage-edit-button' }))
+ grid.with_area(:"icon-button", tag: :div, color: :subtle, mr: 3, justify_self: :end, test_selector: 'storage-replace-openproject-oauth-application') do
+ primer_form_with(
+ model: storage,
+ url: replace_oauth_application_admin_settings_storage_path(storage),
+ method: :delete
+ ) do |_form|
+ render(
+ Primer::Beta::IconButton.new(
+ icon: :sync,
+ scheme: :invisible,
+ type: :submit,
+ aria: { label: I18n.t("storages.buttons.replace_provider_type_oauth", provider_type: I18n.t("storages.provider_types.#{storage.short_provider_type}.name")) },
+ data: { turbo_confirm: I18n.t("storages.confirm_replace_oauth_client") }
+ )
+ )
+ end
+ end
end
end
end
diff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rb
index f472f42649b..0ab19ec9e24 100644
--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb
@@ -139,7 +139,7 @@ class Storages::Admin::StoragesController < ApplicationController
redirect_to admin_settings_storages_path
end
- def replace_oauth_application
+ def replace_oauth_application # rubocop:disable Metrics/AbcSize
@storage.oauth_application.destroy
service_result = ::Storages::OAuthApplications::CreateService.new(storage: @storage, user: current_user).call
@@ -147,6 +147,9 @@ class Storages::Admin::StoragesController < ApplicationController
flash[:notice] = I18n.t('storages.notice_oauth_application_replaced')
@oauth_application = service_result.result
render :show_oauth_application
+ elsif OpenProject::FeatureDecisions.storage_primer_design_active?
+ @oauth_application = ServiceResultErrorsPresenter.new(service_result)
+ render :show_oauth_application
else
@errors = service_result.errors
render :edit
diff --git a/modules/storages/app/forms/storages/admin/clipboard_copy_input_form.rb b/modules/storages/app/forms/storages/admin/clipboard_copy_input_form.rb
new file mode 100644
index 00000000000..54ecda7cd7d
--- /dev/null
+++ b/modules/storages/app/forms/storages/admin/clipboard_copy_input_form.rb
@@ -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.
+#++
+
+module Storages::Admin
+ class ClipboardCopyInputForm < ApplicationForm
+ # attr_reader :attribute_name
+
+ # def initialize(builder, name:, **options)
+ # super(builder, **options)
+ # @attribute_name = name
+ # end
+
+ form do |input_form|
+ input_form.text_field(
+ name: :host,
+ label: I18n.t('activerecord.attributes.storages/storage.host'),
+ readonly: true,
+ required: true
+ )
+ end
+ 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.erb
index 144fe75626e..9c36e4e64a7 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,91 +1,90 @@
-<!-- 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.short_provider_type}.name")} #{t("storages.label_oauth_application_details")}" %>
-<% local_assigns[:additional_breadcrumb] = [
- link_to(@storage.name, edit_admin_settings_storage_path(@storage)),
- t("storages.label_oauth_breadcrumb.openproject")
-] %>
-<%= toolbar title: "OpenProject #{t("storages.label_oauth_application_details")}" %>
-
-<div class="op-toast -warning">
- <div class="op-toast--content">
- <p class="-with-inline-links">
- <%= t('repositories.storage.oauth_application_details') %>
- <a
- href="<%= File.join(@oauth_application.integration.host, 'settings/admin/openproject') %>"
- target="_blank"
- class="spot-link"
- >
- <span class="spot-icon spot-icon_arrow-right3"></span>
- <span><%= t('repositories.storage.oauth_application_details_link_text') %></span>
- </a>
- </p>
+<% if OpenProject::FeatureDecisions.storage_primer_design_active? %>
+ <%= render(OpTurbo::FrameWrapperComponent.new(@storage, frame: :openproject_oauth)) do %>
+ <%= render(Storages::Admin::Forms::OAuthApplicationFormComponent.new(oauth_application: @oauth_application, storage: @storage)) %>
+ <% end %>
+<% else %>
+ <% html_title t(:label_administration), t("project_module_storages"), @storage.name, "#{t("storages.provider_types.#{@storage.short_provider_type}.name")} #{t("storages.label_oauth_application_details")}" %>
+ <% local_assigns[:additional_breadcrumb] = [
+ link_to(@storage.name, edit_admin_settings_storage_path(@storage)),
+ t("storages.label_oauth_breadcrumb.openproject")
+ ] %>
+ <%= toolbar title: "OpenProject #{t("storages.label_oauth_application_details")}" %>
+ <div class="op-toast -warning">
+ <div class="op-toast--content">
+ <p class="-with-inline-links">
+ <%= t('repositories.storage.oauth_application_details') %>
+ <a
+ href="<%= File.join(@oauth_application.integration.host, 'settings/admin/openproject') %>"
+ target="_blank"
+ class="spot-link"
+ >
+ <span class="spot-icon spot-icon_arrow-right3"></span>
+ <span><%= t('repositories.storage.oauth_application_details_link_text') %></span>
+ </a>
+ </p>
+ </div>
</div>
-</div>
-
-<%= labelled_tabular_form_for @oauth_application, url: '/' do |f| -%>
- <fieldset class="form--fieldset">
- <div class="form--field">
- <label class="form--label"><%= Storages::Admin::LABEL_OAUTH_CLIENT_ID %></label>
-
- <div class="form--field-container">
- <div class="form--text-field-container -wide">
- <%= text_field_tag(
- :uid,
- @oauth_application.uid,
- {
- size: 40,
- readonly: true,
- id: 'client_id'
- }
- ) %>
- </div>
- <div class="form--field-affix">
- <% csp_onclick('this.focus(); this.select();', '#client_id') %>
- <copy-to-clipboard click-target=".client-id-copy-button"
- clipboard-target="#client_id">
- </copy-to-clipboard>
- <button class="client-id-copy-button button -without-button-styling"
- title="<%= t(:button_copy_to_clipboard) %>">
- <%= op_icon('icon-copy') %>
- <span class="hidden-for-sighted"><%= t(:button_copy_to_clipboard) %></span>
- </button>
+ <%= labelled_tabular_form_for @oauth_application, url: '/' do |f| -%>
+ <fieldset class="form--fieldset">
+ <div class="form--field">
+ <label class="form--label"><%= Storages::Admin::LABEL_OAUTH_CLIENT_ID %></label>
+ <div class="form--field-container">
+ <div class="form--text-field-container -wide">
+ <%= text_field_tag(
+ :uid,
+ @oauth_application.uid,
+ {
+ size: 40,
+ readonly: true,
+ id: 'client_id'
+ }
+ ) %>
+ </div>
+ <div class="form--field-affix">
+ <% csp_onclick('this.focus(); this.select();', '#client_id') %>
+ <copy-to-clipboard click-target=".client-id-copy-button"
+ clipboard-target="#client_id">
+ </copy-to-clipboard>
+ <button class="client-id-copy-button button -without-button-styling"
+ title="<%= t(:button_copy_to_clipboard) %>">
+ <%= op_icon('icon-copy') %>
+ <span class="hidden-for-sighted"><%= t(:button_copy_to_clipboard) %></span>
+ </button>
+ </div>
</div>
</div>
- </div>
-
- <div class="form--field">
- <label class="form--label"><%= Storages::Admin::LABEL_OAUTH_CLIENT_SECRET %></label>
-
- <div class="form--field-container">
- <div class="form--text-field-container -wide">
- <%= text_field_tag(
- :plaintext_secret,
- @oauth_application.plaintext_secret,
- {
- size: 40,
- readonly: true,
- id: 'secret'
- }
- ) %>
- </div>
- <div class="form--field-affix">
- <% csp_onclick('this.focus(); this.select();', '#secret') %>
- <copy-to-clipboard click-target=".secret-copy-button"
- clipboard-target="#secret">
- </copy-to-clipboard>
- <button class="secret-copy-button button -without-button-styling"
- title="<%= t(:button_copy_to_clipboard) %>">
- <%= op_icon('icon-copy') %>
- <span class="hidden-for-sighted"><%= t(:button_copy_to_clipboard) %></span>
- </button>
+ <div class="form--field">
+ <label class="form--label"><%= Storages::Admin::LABEL_OAUTH_CLIENT_SECRET %></label>
+ <div class="form--field-container">
+ <div class="form--text-field-container -wide">
+ <%= text_field_tag(
+ :plaintext_secret,
+ @oauth_application.plaintext_secret,
+ {
+ size: 40,
+ readonly: true,
+ id: 'secret'
+ }
+ ) %>
+ </div>
+ <div class="form--field-affix">
+ <% csp_onclick('this.focus(); this.select();', '#secret') %>
+ <copy-to-clipboard click-target=".secret-copy-button"
+ clipboard-target="#secret">
+ </copy-to-clipboard>
+ <button class="secret-copy-button button -without-button-styling"
+ title="<%= t(:button_copy_to_clipboard) %>">
+ <%= op_icon('icon-copy') %>
+ <span class="hidden-for-sighted"><%= t(:button_copy_to_clipboard) %></span>
+ </button>
+ </div>
</div>
</div>
- </div>
- </fieldset>
-
- <% 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(@storage), class: "-highlight -with-icon icon-checkmark button" %>
+ </fieldset>
+ <% 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(@storage), class: "-highlight -with-icon icon-checkmark button" %>
+ <% end %>
<% end %>
<% end %>
diff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.yml
index dd6a8cd818d..c1564765749 100644
--- a/modules/storages/config/locales/en.yml
+++ b/modules/storages/config/locales/en.yml
@@ -66,6 +66,7 @@ en:
default_name: "My storage"
unknown_storage: "Unknown storage"
buttons:
+ done_continue: "Done, continue"
done_continue_setup: "Done. Continue setup"
done_complete_setup: "Done, complete setup"
edit_automatically_managed_project_folders: "Edit automatically managed project folders"