Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#53429] Project storage menu links does not include prefix. #15028

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def default_cancel_button_options
name: :cancel,
scheme: :default,
tag: :a,
href: Rails.application.routes.url_helpers.admin_settings_storages_path,
href: OpenProject::StaticRouting::StaticRouter.new.url_helpers.admin_settings_storages_path,
label: I18n.t('button_cancel')
}
end
Expand Down
2 changes: 1 addition & 1 deletion modules/storages/app/models/storages/project_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def open(user)
def open_with_connection_ensured
return unless storage.configured?

url_helpers = Rails.application.routes.url_helpers
url_helpers = OpenProject::StaticRouting::StaticRouter.new.url_helpers
open_project_storage_url = url_helpers.open_project_storage_url(
host: Setting.host_name,
protocol: 'https',
Expand Down
40 changes: 29 additions & 11 deletions modules/storages/spec/features/storages_menu_links_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,25 @@
require 'spec_helper'
require_module_spec_helper

RSpec.describe 'Storage links in project menu', :js, :with_cuprite do
RSpec.describe 'Storage links in project menu' do
include EnsureConnectionPathHelper

let!(:storage_configured_linked1) { create(:nextcloud_storage_configured, :as_automatically_managed, name: "Storage 1") }
let!(:project_storage1) { create(:project_storage, :as_automatically_managed, project:, storage: storage_configured_linked1) }
let!(:storage_configured_linked2) { create(:nextcloud_storage_configured, name: "Storage 2") }
let!(:project_storage2) do
shared_let(:project) { create(:project, enabled_module_names: %i[storages]) }
shared_let(:storage_configured_linked1) { create(:nextcloud_storage_configured, :as_automatically_managed, name: "Storage 1") }
shared_let(:project_storage1) do
create(:project_storage, :as_automatically_managed, project:, storage: storage_configured_linked1)
end
shared_let(:storage_configured_linked2) { create(:nextcloud_storage_configured, name: "Storage 2") }
shared_let(:project_storage2) do
create(:project_storage, project_folder_mode: 'inactive', project:, storage: storage_configured_linked2)
end
let!(:storage_configured_linked3) { create(:nextcloud_storage_configured, name: "Storage 3") }
let!(:project_storage3) do
shared_let(:storage_configured_linked3) { create(:nextcloud_storage_configured, name: "Storage 3") }
shared_let(:project_storage3) do
create(:project_storage, project_folder_mode: 'manual', project:, storage: storage_configured_linked3)
end
let!(:storage_configured_unlinked) { create(:nextcloud_storage_configured, name: "Storage 4") }
let!(:storage_unconfigured_linked) { create(:nextcloud_storage, name: "Storage 5") }
let!(:project_storage4) { create(:project_storage, project:, storage: storage_unconfigured_linked) }
let!(:project) { create(:project, enabled_module_names: %i[storages]) }
shared_let(:storage_configured_unlinked) { create(:nextcloud_storage_configured, name: "Storage 4") }
shared_let(:storage_unconfigured_linked) { create(:nextcloud_storage, name: "Storage 5") }
shared_let(:project_storage4) { create(:project_storage, project:, storage: storage_unconfigured_linked) }
let(:user) { create(:user, member_with_permissions: { project => permissions }) }

before do
Expand Down Expand Up @@ -82,6 +84,22 @@
expect(page).to have_no_link(storage_configured_unlinked.name)
expect(page).to have_no_link(storage_unconfigured_linked.name)
end

context 'when OP has been installed behind prefix' do
let(:prefix) { '/qwerty' }

before { allow(OpenProject::Configuration).to receive(:rails_relative_url_root).and_return(prefix) }

it 'has all links prefixed' do
visit(project_path(id: project.id))

expect(page).to have_link(storage_configured_linked1.name, href: ensure_connection_path(project_storage1))
expect(page).to have_link(storage_configured_linked2.name, href: ensure_connection_path(project_storage2))
expect(page).to have_link(storage_configured_linked3.name, href: ensure_connection_path(project_storage3))
expect(page).to have_no_link(storage_configured_unlinked.name)
expect(page).to have_no_link(storage_unconfigured_linked.name)
end
end
end

context 'read_files' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@

module EnsureConnectionPathHelper
def ensure_connection_path(project_storage)
oauth_clients_ensure_connection_path(
url_helpers = OpenProject::StaticRouting::StaticRouter.new.url_helpers
url_helpers.oauth_clients_ensure_connection_path(
oauth_client_id: project_storage.storage.oauth_client.client_id,
storage_id: project_storage.storage.id,
destination_url: open_project_storage_url(
destination_url: url_helpers.open_project_storage_url(
protocol: 'https',
project_id: project_storage.project.identifier,
id: project_storage.id
Expand Down
Loading