Skip to content

Commit

Permalink
chore[Op#56922]: split out project vs storage oauth components
Browse files Browse the repository at this point in the history
  • Loading branch information
akabiru committed Aug 14, 2024
1 parent ce5e271 commit c1b0217
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 237 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 }
) do
render(Primer::Beta::Text.new) { body_text }
Expand All @@ -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 }
end
Expand Down
Original file line number Diff line number Diff line change
@@ -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
end
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def oauth_access_grant # rubocop:disable Metrics/AbcSize
storageId: @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)
end
end
Expand Down Expand Up @@ -171,17 +171,21 @@ def storage_oauth_access_granted?
def redirect_to_project_storages_path_with_nudge_modal
redirect_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: }
}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def ensure_storage_configured!

def oauth_access_granted_modal_params
{
type: "Storages::Admin::Storages::OAuthAccessGrantedModalComponent",
type: Storages::Admin::Storages::OAuthAccessGrantedModalComponent.name,
parameters: { storage: @storage.id }
}
end
Expand Down
Original file line number Diff line number Diff line change
@@ -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
end
Loading

0 comments on commit c1b0217

Please sign in to comment.