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
chore[Op#56922]: split out project vs storage oauth components
Kabiru Mwenja9d2c7caf5320
diff --git a/frontend/src/stimulus/controllers/dynamic/auto-show-dialog.ts b/frontend/src/stimulus/controllers/dynamic/auto-show-dialog.controller.tssimilarity index 100%rename from frontend/src/stimulus/controllers/dynamic/auto-show-dialog.tsrename to frontend/src/stimulus/controllers/dynamic/auto-show-dialog.controller.tsdiff --git a/modules/storages/app/components/storages/admin/oauth_access_grant_nudge_modal_component.html.erb b/modules/storages/app/components/storages/admin/oauth_access_grant_nudge_modal_component.html.erbdeleted file mode 100644index af60d43a12d..00000000000--- a/modules/storages/app/components/storages/admin/oauth_access_grant_nudge_modal_component.html.erb+++ /dev/null@@ -1,92 +0,0 @@-<%=- render(- Primer::Alpha::Dialog.new(- id: dialog_id,- title:,- data: {- 'application-target': 'dynamic',- controller: 'storages--oauth-access-grant-nudge-modal',- 'storages--oauth-access-grant-nudge-modal-close-button-label-value': I18n.t('button_close'),- 'storages--oauth-access-grant-nudge-modal-loading-screen-reader-message-value': waiting_title,- },- test_selector: 'oauth-access-grant-nudge-modal'- )- ) do |dialog|- dialog.with_header(- show_divider: false,- role: :alert,- 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 }- ) do- concat(- render(- Primer::Beta::Text.new(- display: :none,- data: {- 'storages--oauth-access-grant-nudge-modal-target': 'loadingIndicator'- }- )- ) { render(Storages::OpenProjectStorageModalComponent::Body.new(:waiting, waiting_title:)) }- )- concat(- render(- Primer::Beta::Text.new(- data: {- 'storages--oauth-access-grant-nudge-modal-target': 'requestAccessBody'- }- )- ) { body_text }- )- end-- dialog.with_footer(show_divider: false) do- concat(- render(- Primer::Beta::Button.new(- scheme: :default,- size: :medium,- data: {- 'close-dialog-id': dialog_id,- 'storages--oauth-access-grant-nudge-modal-target': 'closeButton'- }- )- ) { 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- end- end-%>diff --git a/modules/storages/app/components/storages/admin/oauth_access_grant_nudge_modal_component.rb b/modules/storages/app/components/storages/admin/oauth_access_grant_nudge_modal_component.rbdeleted file mode 100644index 3a867075577..00000000000--- a/modules/storages/app/components/storages/admin/oauth_access_grant_nudge_modal_component.rb+++ /dev/null@@ -1,102 +0,0 @@-# 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::Admin- class OAuthAccessGrantNudgeModalComponent < ApplicationComponent- options dialog_id: "storages--oauth-grant-nudge-modal-component",- dialog_body_id: "storages--oauth-grant-nudge-modal-body-component",- authorized: false-- attr_reader :project_storage-- def initialize(project_storage:, **)- @project_storage = find_project_storage(project_storage)- super(@project_storage, **)- end-- def render?- @project_storage.present?- end-- private-- def confirm_button_text- I18n.t("storages.oauth_grant_nudge_modal.confirm_button_label")- end-- def title- if authorized- I18n.t("storages.oauth_grant_nudge_modal.access_granted_screen_reader", storage: project_storage.storage.name)- else- I18n.t("storages.oauth_grant_nudge_modal.title")- end- end-- def waiting_title- I18n.t("storages.oauth_grant_nudge_modal.requesting_access_to", storage: project_storage.storage.name)- 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 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: project_storage.storage.name)- concat(render(::Storages::OpenProjectStorageModalComponent::Body.new(:success, success_subtitle:, success_title:)))- else- I18n.t("storages.oauth_grant_nudge_modal.body", storage: project_storage.storage.name)- end- end-- def confirm_button_aria_label- I18n.t("storages.oauth_grant_nudge_modal.confirm_button_aria_label", storage: project_storage.storage.name)- end-- def confirm_button_url- options[:confirm_button_url] || url_helpers.oauth_access_grant_project_settings_project_storage_path(- project_id: project_storage.project.id,- id: project_storage- )- end-- def find_project_storage(project_storage_record_or_id)- return if project_storage_record_or_id.blank?- return project_storage_record_or_id if project_storage_record_or_id.is_a?(::Storages::ProjectStorage)-- ::Storages::ProjectStorage.find_by(id: project_storage_record_or_id)- end- end-enddiff --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.erbindex cbeaa3e073c..8530faeb50b 100644--- 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@@ -4,7 +4,11 @@Primer::Alpha::Dialog.new(id: dialog_id,title:,- test_selector: 'oauth-access-granted-modal'+ data: {+ "application-target": "dynamic",+ controller: "auto-show-dialog",+ },+ test_selector: "oauth-access-granted-modal")) do |dialog|dialog.with_header(@@ -16,7 +20,7 @@dialog.with_body(id: dialog_body_id,- test_selector: 'oauth-access-granted-modal-body',+ test_selector: "oauth-access-granted-modal-body",aria: { hidden: true }) dorender(Primer::Beta::Text.new) { body_text }@@ -27,7 +31,7 @@Primer::Beta::Button.new(scheme: :default,size: :medium,- data: { 'close-dialog-id': dialog_id }+ data: { "close-dialog-id": dialog_id })) { cancel_button_text }enddiff --git a/modules/storages/app/components/storages/project_storages/oauth_access_grant_nudge_modal_component.rb b/modules/storages/app/components/storages/project_storages/oauth_access_grant_nudge_modal_component.rbnew file mode 100644index 00000000000..f6c3d9c4b5d--- /dev/null+++ b/modules/storages/app/components/storages/project_storages/oauth_access_grant_nudge_modal_component.rb@@ -0,0 +1,59 @@+# 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 ProjectStorages+ class OAuthAccessGrantNudgeModalComponent < ::Storages::Admin::Storages::OAuthAccessGrantNudgeModalComponent+ def initialize(project_storage:, **)+ @project_storage = find_project_storage(project_storage)+ super(storage: @project_storage&.storage, **)+ @model = @project_storage+ end++ private++ attr_reader :project_storage++ def confirm_button_url+ url_helpers.oauth_access_grant_project_settings_project_storage_path(+ project_id: project_storage.project.id,+ id: project_storage+ )+ end++ def find_project_storage(project_storage_record_or_id)+ return if project_storage_record_or_id.blank?+ return project_storage_record_or_id if project_storage_record_or_id.is_a?(::Storages::ProjectStorage)++ ::Storages::ProjectStorage.find_by(id: project_storage_record_or_id)+ end+ end+ end+enddiff --git a/modules/storages/app/controllers/storages/admin/project_storages_controller.rb b/modules/storages/app/controllers/storages/admin/project_storages_controller.rbindex a5275d9f0d2..931d3fdbd11 100644--- a/modules/storages/app/controllers/storages/admin/project_storages_controller.rb+++ b/modules/storages/app/controllers/storages/admin/project_storages_controller.rb@@ -85,7 +85,7 @@ class Storages::Admin::ProjectStoragesController < Projects::SettingsControllerstorageId: @project_storage.storage_id }.to_json,expires: 1.hour}- session[:oauth_callback_flash_modal] = oauth_access_grant_nudge_modal(authorized: true)+ session[:oauth_callback_flash_modal] = storage_oauth_access_granted_modal(storage:)redirect_to(storage.oauth_configuration.authorization_uri(state: nonce), allow_other_host: true)endend@@ -171,17 +171,21 @@ class Storages::Admin::ProjectStoragesController < Projects::SettingsControllerdef redirect_to_project_storages_path_with_nudge_modalredirect_to(external_file_storages_project_settings_project_storages_path,- flash: { modal: oauth_access_grant_nudge_modal }+ flash: { modal: oauth_access_grant_nudge_modal(project_storage: @project_storage) })end- def oauth_access_grant_nudge_modal(authorized: false)+ def oauth_access_grant_nudge_modal(project_storage:){- type: "Storages::Admin::OAuthAccessGrantNudgeModalComponent",- parameters: {- project_storage: @project_storage.id,- authorized:- }+ type: Storages::ProjectStorages::OAuthAccessGrantNudgeModalComponent.name,+ parameters: { project_storage: project_storage.id }+ }+ end++ def storage_oauth_access_granted_modal(storage:)+ {+ type: Storages::Admin::Storages::OAuthAccessGrantedModalComponent.name,+ parameters: { storage: storage.id }}endenddiff --git a/modules/storages/app/controllers/storages/admin/storages/project_storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages/project_storages_controller.rbindex 4129b2164ae..afc0e37ebf1 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@@ -228,7 +228,7 @@ class Storages::Admin::Storages::ProjectStoragesController < ApplicationControlldef oauth_access_granted_modal_params{- type: "Storages::Admin::Storages::OAuthAccessGrantedModalComponent",+ type: Storages::Admin::Storages::OAuthAccessGrantedModalComponent.name,parameters: { storage: @storage.id }}enddiff --git a/modules/storages/spec/components/storages/admin/storages/oauth_access_grant_nudge_modal_component_spec.rb b/modules/storages/spec/components/storages/admin/storages/oauth_access_grant_nudge_modal_component_spec.rbnew file mode 100644index 00000000000..73bd0dd34fa--- /dev/null+++ b/modules/storages/spec/components/storages/admin/storages/oauth_access_grant_nudge_modal_component_spec.rb@@ -0,0 +1,55 @@+#-- 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.+#+++#+require "spec_helper"+require_module_spec_helper++RSpec.describe Storages::Admin::Storages::OAuthAccessGrantNudgeModalComponent, type: :component do # rubocop:disable RSpec/SpecFilePathFormat+ let(:storage) { build_stubbed(:nextcloud_storage) }++ it "renders the nudge modal" do+ render_inline(described_class.new(storage:))++ expect(page).to have_css('[role="alert"]', text: "One more step...", aria: { live: :assertive })+ expect(page).to have_test_selector(+ "oauth-access-grant-nudge-modal-body",+ text: "To get access to the project folder you need to login to #{storage.name}."+ )++ expect(page).to have_button("I will do it later")+ expect(page).to have_button("Login", aria: { label: "Login to #{storage.name}" })+ end++ context "with no storage" do+ it "does not render" do+ render_inline(described_class.new(storage: nil))++ expect(page.text).to be_empty+ end+ end+enddiff --git a/modules/storages/spec/components/storages/admin/oauth_access_grant_nudge_modal_component_spec.rb b/modules/storages/spec/components/storages/admin/storages/oauth_access_granted_modal_component_spec.rbsimilarity index 53%rename from modules/storages/spec/components/storages/admin/oauth_access_grant_nudge_modal_component_spec.rbrename to modules/storages/spec/components/storages/admin/storages/oauth_access_granted_modal_component_spec.rbindex 606ae91b72d..27653183edf 100644--- a/modules/storages/spec/components/storages/admin/oauth_access_grant_nudge_modal_component_spec.rb+++ b/modules/storages/spec/components/storages/admin/storages/oauth_access_granted_modal_component_spec.rb@@ -29,60 +29,66 @@require "spec_helper"require_module_spec_helper-RSpec.describe Storages::Admin::OAuthAccessGrantNudgeModalComponent, type: :component do # rubocop:disable RSpec/SpecFilePathFormat- let(:project_storage) { build_stubbed(:project_storage) }+RSpec.describe Storages::Admin::Storages::OAuthAccessGrantedModalComponent, type: :component do # rubocop:disable RSpec/SpecFilePathFormat+ context "with storage and oauth client token" do+ let(:oauth_client) { build_stubbed(:oauth_client) }+ let(:storage) { build_stubbed(:nextcloud_storage, oauth_client:) }- before do- render_inline(oauth_access_grant_nudge_modal_component)- end-- context "with access pending authorization" do- let(:oauth_access_grant_nudge_modal_component) { described_class.new(project_storage:) }-- it "renders the nudge modal" do- expect(page).to have_css('[role="alert"]', text: "One more step...", aria: { live: :assertive })- expect(page).to have_test_selector(- "oauth-access-grant-nudge-modal-body",- text: "To get access to the project folder you need to login to #{project_storage.storage.name}.",- aria: { hidden: false }- )-- expect(page).to have_button("I will do it later")- expect(page).to have_button("Login", aria: { label: "Login to #{project_storage.storage.name}" })- end- end-- context "with access authorized" do- let(:oauth_access_grant_nudge_modal_component) do- described_class.new(project_storage:, authorized: true)+ before do+ allow(OAuthClientToken).to receive(:exists?).and_return(true)endit "renders a success modal" do+ render_inline(described_class.new(storage:))+expect(page).to have_css("h1.sr-only",- text: "Access granted. You are now ready to use #{project_storage.storage.name}"+ text: "Access granted. You are now ready to use #{storage.name}")expect(page).to have_test_selector(- "oauth-access-grant-nudge-modal-body",+ "oauth-access-granted-modal-body",text: "Access granted",aria: { hidden: true })expect(page).to have_test_selector(- "oauth-access-grant-nudge-modal-body",- text: "You are now ready to use #{project_storage.storage.name}",+ "oauth-access-granted-modal-body",+ text: "You are now ready to use #{storage.name}",aria: { hidden: true })expect(page).to have_button("Close")++ aggregate_failures "checks that the current user has an oauth token" do+ expect(OAuthClientToken).to have_received(:exists?)+ .with(user: User.current, oauth_client: storage.oauth_client)+ end+ end+ end++ context "with no storage" do+ it "does not render" do+ render_inline(described_class.new(storage: nil))++ expect(page.text).to be_emptyendend- context "with no project storage" do- let(:oauth_access_grant_nudge_modal_component) { described_class.new(project_storage: nil) }+ context "with storage but no oauth client token" do+ before do+ allow(OAuthClientToken).to receive(:exists?).and_call_original+ endit "does not render" do+ storage = build_stubbed(:nextcloud_storage)+ render_inline(described_class.new(storage:))+expect(page.text).to be_empty++ aggregate_failures "checks that the current user has an oauth token" do+ expect(OAuthClientToken).to have_received(:exists?)+ .with(user: User.current, oauth_client: storage.oauth_client)+ endendendenddiff --git a/modules/storages/spec/components/storages/project_storages/oauth_access_grant_nudge_modal_component_spec.rb b/modules/storages/spec/components/storages/project_storages/oauth_access_grant_nudge_modal_component_spec.rbnew file mode 100644index 00000000000..7ca41d20dea--- /dev/null+++ b/modules/storages/spec/components/storages/project_storages/oauth_access_grant_nudge_modal_component_spec.rb@@ -0,0 +1,56 @@+#-- 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.+#+++#+require "spec_helper"+require_module_spec_helper++RSpec.describe Storages::ProjectStorages::OAuthAccessGrantNudgeModalComponent, type: :component do # rubocop:disable RSpec/SpecFilePathFormat+ let(:storage) { build_stubbed(:nextcloud_storage) }+ let(:project_storage) { build_stubbed(:project_storage, storage:) }++ it "renders the nudge modal" do+ render_inline(described_class.new(project_storage:))++ expect(page).to have_css('[role="alert"]', text: "One more step...", aria: { live: :assertive })+ expect(page).to have_test_selector(+ "oauth-access-grant-nudge-modal-body",+ text: "To get access to the project folder you need to login to #{storage.name}."+ )++ expect(page).to have_button("I will do it later")+ expect(page).to have_button("Login", aria: { label: "Login to #{storage.name}" })+ end++ context "with no project storage" do+ it "does not render" do+ render_inline(described_class.new(project_storage: nil))++ expect(page.text).to be_empty+ end+ end+end