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[Op#56922]: Split authorized state from nudge modal

Kabiru Mwenjab400bd124160
diff --git a/frontend/src/stimulus/controllers/dynamic/auto-show-dialog.ts b/frontend/src/stimulus/controllers/dynamic/auto-show-dialog.ts
new file mode 100644
index 00000000000..db2a0aabe55
--- /dev/null
+++ b/frontend/src/stimulus/controllers/dynamic/auto-show-dialog.ts
@@ -0,0 +1,37 @@
+/*
+ * -- copyright
+ * OpenProject is an open source project management software.
+ * Copyright (C) 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.
+ * ++
+ */
+
+import { Controller } from '@hotwired/stimulus';
+
+export default class AutoShowDialogController extends Controller<HTMLDialogElement> {
+ connect() {
+ this.element.showModal();
+ }
+}
diff --git a/modules/storages/app/components/storages/admin/storages/oauth_access_grant_nudge_modal_component.html.erb b/modules/storages/app/components/storages/admin/storages/oauth_access_grant_nudge_modal_component.html.erb
index 266dbbcb06c..3c71ea2eb3f 100644
--- a/modules/storages/app/components/storages/admin/storages/oauth_access_grant_nudge_modal_component.html.erb
+++ b/modules/storages/app/components/storages/admin/storages/oauth_access_grant_nudge_modal_component.html.erb
@@ -19,14 +19,12 @@
aria: { live: :assertive },
data: {
'storages--oauth-access-grant-nudge-modal-target': 'header'
- },
- visually_hide_title: authorized
+ }
)
dialog.with_body(
id: dialog_body_id,
- test_selector: 'oauth-access-grant-nudge-modal-body',
- aria: { hidden: authorized }
+ test_selector: 'oauth-access-grant-nudge-modal-body'
) do
concat(
render(
@@ -63,31 +61,29 @@
) { cancel_button_text }
)
- unless authorized
- concat(
- primer_form_with(
- model: @project_storage,
- url: confirm_button_url,
- method: :get,
- data: {
- 'storages--oauth-access-grant-nudge-modal-target': 'requestAccessForm'
- }
- ) do |_form|
- render(
- Primer::Beta::Button.new(
- scheme: :primary,
- size: :medium,
- type: :submit,
- aria: { label: confirm_button_aria_label },
- data: {
- 'storages--oauth-access-grant-nudge-modal-target': 'requestAccessButton',
- action: 'click->storages--oauth-access-grant-nudge-modal#requestAccess'
- }
- )
- ) { confirm_button_text }
- end
- )
- end
+ concat(
+ primer_form_with(
+ model:,
+ url: confirm_button_url,
+ method: :get,
+ data: {
+ 'storages--oauth-access-grant-nudge-modal-target': 'requestAccessForm'
+ }
+ ) do |_form|
+ render(
+ Primer::Beta::Button.new(
+ scheme: :primary,
+ size: :medium,
+ type: :submit,
+ aria: { label: confirm_button_aria_label },
+ data: {
+ 'storages--oauth-access-grant-nudge-modal-target': 'requestAccessButton',
+ action: 'storages--oauth-access-grant-nudge-modal#requestAccess'
+ }
+ )
+ ) { confirm_button_text }
+ end
+ )
end
end
end
diff --git a/modules/storages/app/components/storages/admin/storages/oauth_access_grant_nudge_modal_component.rb b/modules/storages/app/components/storages/admin/storages/oauth_access_grant_nudge_modal_component.rb
index fb15a096e3d..8dd42e5eb21 100644
--- a/modules/storages/app/components/storages/admin/storages/oauth_access_grant_nudge_modal_component.rb
+++ b/modules/storages/app/components/storages/admin/storages/oauth_access_grant_nudge_modal_component.rb
@@ -28,74 +28,64 @@
# See COPYRIGHT and LICENSE files for more details.
#++
#
-module Storages::Admin::Storages
- class OAuthAccessGrantNudgeModalComponent < ApplicationComponent
- include OpTurbo::Streamable
- options dialog_id: "storages--oauth-grant-nudge-modal-component",
- dialog_body_id: "storages--oauth-grant-nudge-modal-body-component",
- authorized: false
+module Storages
+ module Admin
+ module Storages
+ class OAuthAccessGrantNudgeModalComponent < ApplicationComponent
+ include OpTurbo::Streamable
- attr_reader :storage
+ options dialog_id: "storages--oauth-grant-nudge-modal-component",
+ dialog_body_id: "storages--oauth-grant-nudge-modal-body-component"
- def initialize(storage:, **)
- @storage = find_storage(storage)
- super(@storage, **)
- end
+ def initialize(storage:, **)
+ @storage = find_storage(storage)
+ super(@storage, **)
+ end
- def render?
- @storage.present?
- end
+ def render?
+ @storage.present?
+ end
- private
+ private
- def confirm_button_text
- I18n.t("storages.oauth_grant_nudge_modal.confirm_button_label")
- end
+ attr_reader :storage
- def title
- if authorized
- I18n.t("storages.oauth_grant_nudge_modal.access_granted_screen_reader", storage: storage.name)
- else
- I18n.t("storages.oauth_grant_nudge_modal.title")
- end
- end
+ def confirm_button_text
+ I18n.t("storages.oauth_grant_nudge_modal.confirm_button_label")
+ end
- def waiting_title
- I18n.t("storages.oauth_grant_nudge_modal.requesting_access_to", storage: storage.name)
- end
+ def title
+ I18n.t("storages.oauth_grant_nudge_modal.title")
+ end
- def cancel_button_text
- if authorized
- I18n.t("button_close")
- else
- I18n.t("storages.oauth_grant_nudge_modal.cancel_button_label")
- end
- end
+ def waiting_title
+ I18n.t("storages.oauth_grant_nudge_modal.requesting_access_to", storage: storage.name)
+ end
- def body_text
- if authorized
- success_title = I18n.t("storages.oauth_grant_nudge_modal.access_granted")
- success_subtitle = I18n.t("storages.oauth_grant_nudge_modal.storage_ready", storage: storage.name)
- concat(render(::Storages::OpenProjectStorageModalComponent::Body.new(:success, success_subtitle:, success_title:)))
- else
- I18n.t("storages.oauth_grant_nudge_modal.body", storage: storage.name)
- end
- end
+ def cancel_button_text
+ I18n.t("storages.oauth_grant_nudge_modal.cancel_button_label")
+ end
- def confirm_button_aria_label
- I18n.t("storages.oauth_grant_nudge_modal.confirm_button_aria_label", storage: storage.name)
- end
+ def body_text
+ I18n.t("storages.oauth_grant_nudge_modal.body", storage: storage.name)
+ end
- def confirm_button_url
- url_helpers.oauth_access_grant_admin_settings_storage_project_storages_path(storage)
- end
+ def confirm_button_aria_label
+ I18n.t("storages.oauth_grant_nudge_modal.confirm_button_aria_label", storage: storage.name)
+ end
+
+ def confirm_button_url
+ url_helpers.oauth_access_grant_admin_settings_storage_project_storages_path(storage)
+ end
- def find_storage(storage_record_or_id)
- return if storage_record_or_id.blank?
- return storage_record_or_id if storage_record_or_id.is_a?(::Storages::Storage)
+ def find_storage(storage_record_or_id)
+ return if storage_record_or_id.blank?
+ return storage_record_or_id if storage_record_or_id.is_a?(::Storages::Storage)
- ::Storages::Storage.find_by(id: storage_record_or_id)
+ ::Storages::Storage.find_by(id: storage_record_or_id)
+ end
+ end
end
end
end
diff --git a/modules/storages/app/components/storages/admin/storages/oauth_access_granted_modal_component.html.erb b/modules/storages/app/components/storages/admin/storages/oauth_access_granted_modal_component.html.erb
new file mode 100644
index 00000000000..cbeaa3e073c
--- /dev/null
+++ b/modules/storages/app/components/storages/admin/storages/oauth_access_granted_modal_component.html.erb
@@ -0,0 +1,36 @@
+<%=
+ component_wrapper do
+ render(
+ Primer::Alpha::Dialog.new(
+ id: dialog_id,
+ title:,
+ test_selector: 'oauth-access-granted-modal'
+ )
+ ) do |dialog|
+ dialog.with_header(
+ show_divider: false,
+ role: :alert,
+ aria: { live: :assertive },
+ visually_hide_title: true
+ )
+
+ dialog.with_body(
+ id: dialog_body_id,
+ test_selector: 'oauth-access-granted-modal-body',
+ aria: { hidden: true }
+ ) do
+ render(Primer::Beta::Text.new) { body_text }
+ end
+
+ dialog.with_footer(show_divider: false) do
+ render(
+ Primer::Beta::Button.new(
+ scheme: :default,
+ size: :medium,
+ data: { 'close-dialog-id': dialog_id }
+ )
+ ) { cancel_button_text }
+ end
+ end
+ end
+%>
diff --git a/modules/storages/app/components/storages/admin/storages/oauth_access_granted_modal_component.rb b/modules/storages/app/components/storages/admin/storages/oauth_access_granted_modal_component.rb
new file mode 100644
index 00000000000..c5ff9dc78cf
--- /dev/null
+++ b/modules/storages/app/components/storages/admin/storages/oauth_access_granted_modal_component.rb
@@ -0,0 +1,80 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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
+ module Admin
+ module Storages
+ class OAuthAccessGrantedModalComponent < ApplicationComponent
+ include OpTurbo::Streamable
+
+ def initialize(storage:, **)
+ @storage = find_storage(storage)
+ super(@storage, **)
+ end
+
+ def render?
+ storage.present? && OAuthClientToken.exists?(user: User.current, oauth_client: storage.oauth_client)
+ end
+
+ private
+
+ attr_reader :storage
+
+ def dialog_id = "#{wrapper_key}-dialog-id"
+ def dialog_body_id = "#{wrapper_key}-dialog-body-id"
+
+ def title
+ I18n.t("storages.oauth_grant_nudge_modal.access_granted_screen_reader", storage: storage.name)
+ end
+
+ def waiting_title
+ I18n.t("storages.oauth_grant_nudge_modal.requesting_access_to", storage: storage.name)
+ end
+
+ def cancel_button_text
+ I18n.t("button_close")
+ end
+
+ def body_text
+ success_title = I18n.t("storages.oauth_grant_nudge_modal.access_granted")
+ success_subtitle = I18n.t("storages.oauth_grant_nudge_modal.storage_ready", storage: storage.name)
+ concat(render(::Storages::OpenProjectStorageModalComponent::Body.new(:success, success_subtitle:, success_title:)))
+ end
+
+ def find_storage(storage_record_or_id)
+ return if storage_record_or_id.blank?
+ return storage_record_or_id if storage_record_or_id.is_a?(::Storages::Storage)
+
+ ::Storages::Storage.find_by(id: storage_record_or_id)
+ end
+ end
+ end
+ end
+end
diff --git a/modules/storages/app/controllers/storages/admin/storages/project_storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages/project_storages_controller.rb
index fac0e2de8ca..4129b2164ae 100644
--- a/modules/storages/app/controllers/storages/admin/storages/project_storages_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/storages/project_storages_controller.rb
@@ -70,8 +70,8 @@ class Storages::Admin::Storages::ProjectStoragesController < ApplicationControll
storageId: @storage.id }.to_json,
expires: 1.hour
}
- session[:oauth_callback_flash_modal] = oauth_access_grant_nudge_modal(authorized: true)
- redirect_to(storage.oauth_configuration.authorization_uri(state: nonce), allow_other_host: true)
+ session[:oauth_callback_flash_modal] = oauth_access_granted_modal_params
+ redirect_to(@storage.oauth_configuration.authorization_uri(state: nonce), allow_other_host: true)
end
def create # rubocop:disable Metrics/AbcSize
@@ -226,13 +226,10 @@ class Storages::Admin::Storages::ProjectStoragesController < ApplicationControll
false
end
- def oauth_access_grant_nudge_modal(authorized: false)
+ def oauth_access_granted_modal_params
{
- type: "Storages::Admin::Storages::OAuthAccessGrantNudgeModalComponent",
- parameters: {
- storage: @storage.id,
- authorized:
- }
+ type: "Storages::Admin::Storages::OAuthAccessGrantedModalComponent",
+ parameters: { storage: @storage.id }
}
end
end